create DeviceTransform

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 10:49:48 -05:00
parent 47e34b1b71
commit fb62a02b04

View File

@ -689,3 +689,73 @@ impl MessageBehavior for VmcExtMidiCcBit {
return Ok(VmcExtMidiCcBit { knob, active }); return Ok(VmcExtMidiCcBit { knob, active });
} }
} }
struct DeviceTranform {
addr: String,
serial: String,
transform: Transform3D,
}
impl MessageBehavior for DeviceTranform {
fn to_sendable_osc_message(&self) -> OscMessage {
let quat = self.transform.basis.to_quat();
return OscMessage {
addr: self.addr.to_owned(),
args: vec![
OscType::from(self.serial.to_owned()),
OscType::from(self.transform.origin.x),
OscType::from(self.transform.origin.y),
OscType::from(self.transform.origin.z),
OscType::from(quat.x),
OscType::from(quat.y),
OscType::from(quat.z),
OscType::from(quat.w),
],
};
}
fn parse_from_osc_message(msg: OscMessage) -> Result<Self, String> {
if msg.args.len() != 8 {
return Err(String::from("arg count invalid"));
}
let serial: String;
let mut origin = Vector3::new(0.0, 0.0, 0.0);
let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0);
match &msg.args[0] {
OscType::String(s) => serial = s.to_owned(),
_ => return Err(String::from("arg type invalid")),
}
match msg.args[1] {
OscType::Float(f) => origin.x = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[2] {
OscType::Float(f) => origin.y = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[3] {
OscType::Float(f) => origin.z = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[4] {
OscType::Float(f) => quat.x = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[5] {
OscType::Float(f) => quat.y = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[6] {
OscType::Float(f) => quat.z = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[7] {
OscType::Float(f) => quat.w = f,
_ => return Err(String::from("arg type invalid")),
}
return Ok(DeviceTranform {
addr: msg.addr.to_owned(),
serial,
transform: Transform3D::new(Basis::from_quat(quat), origin),
});
}
}