create VmcExtCam
This commit is contained in:
		
							parent
							
								
									61cc7bcb81
								
							
						
					
					
						commit
						db21964ea1
					
				
							
								
								
									
										76
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								src/lib.rs
									
									
									
									
									
								
							| 
						 | 
					@ -336,3 +336,79 @@ impl MessageBehavior for VmcExtBlendVal {
 | 
				
			||||||
        return Ok(VmcExtBlendVal { name, value });
 | 
					        return Ok(VmcExtBlendVal { name, value });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct VmcExtCam {
 | 
				
			||||||
 | 
					    name: String,
 | 
				
			||||||
 | 
					    transform: Transform3D,
 | 
				
			||||||
 | 
					    fov: f32,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl MessageBehavior for VmcExtCam {
 | 
				
			||||||
 | 
					    fn to_sendable_osc_message(&self) -> OscMessage {
 | 
				
			||||||
 | 
					        let quat = self.transform.basis.to_quat();
 | 
				
			||||||
 | 
					        return OscMessage {
 | 
				
			||||||
 | 
					            addr: String::from("/VMC/Ext/Cam"),
 | 
				
			||||||
 | 
					            args: vec![
 | 
				
			||||||
 | 
					                OscType::from(self.name.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),
 | 
				
			||||||
 | 
					                OscType::from(self.fov),
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    fn parse_from_osc_message(msg: OscMessage) -> Result<Self, String> {
 | 
				
			||||||
 | 
					        if msg.args.len() != 9 {
 | 
				
			||||||
 | 
					            return Err(String::from("arg count invalid"));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let name: 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);
 | 
				
			||||||
 | 
					        let fov: f32;
 | 
				
			||||||
 | 
					        match &msg.args[0] {
 | 
				
			||||||
 | 
					            OscType::String(s) => name = 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")),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        match msg.args[8] {
 | 
				
			||||||
 | 
					            OscType::Float(f) => fov = f,
 | 
				
			||||||
 | 
					            _ => return Err(String::from("arg type invalid")),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return Ok(VmcExtCam {
 | 
				
			||||||
 | 
					            name,
 | 
				
			||||||
 | 
					            transform: Transform3D::new(Basis::from_quat(quat), origin),
 | 
				
			||||||
 | 
					            fov,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user