use crate::ode::*;
impl dSurfaceParameters {
pub fn new() -> dSurfaceParameters {
dSurfaceParameters{
mode: 0, mu: 0.0, mu2: 0.0, rho: 0.0, rho2: 0.0, rhoN: 0.0, bounce: 0.0, bounce_vel: 0.0, soft_erp: 0.0, soft_cfm: 0.0, motion1: 0.0, motion2: 0.0, motionN: 0.0, slip1: 0.0, slip2: 0.0} }
}
impl dContactGeom {
pub fn new() -> dContactGeom {
dContactGeom{
pos: [0.0; 4], normal: [0.0; 4], depth: 0.0, g1: 0 as dGeomID,
g2: 0 as dGeomID,
side1: 0, side2: 0} }
}
impl dContact {
pub fn new() -> dContact {
dContact{
surface: dSurfaceParameters::new(),
geom: dContactGeom::new(),
fdir1: [0.0; 4]} }
}
pub trait Quaternion {
fn as_ptr_mut(&mut self) -> *mut dReal;
fn as_ptr(&self) -> *const dReal;
fn new() -> dQuaternion {
let mut q: dQuaternion = [0.0; 4];
unsafe {
dQSetIdentity(q.as_ptr_mut());
}
q
}
fn from_R(m: dMatrix3) -> dQuaternion {
let mut q: dQuaternion = [0.0; 4];
unsafe {
dQfromR(q.as_ptr_mut(), m.as_ptr() as *mut dReal);
}
q
}
fn to_R(&self) -> dMatrix3 {
let mut m: dMatrix3 = [0.0; 12];
unsafe {
dRfromQ(m.as_ptr_mut(), self.as_ptr() as *mut dReal);
}
m
}
fn from_axis_and_angle(axis: [dReal; 3], angle: dReal) -> dQuaternion {
let mut q: dQuaternion = [0.0; 4];
unsafe {
dQFromAxisAndAngle(q.as_ptr_mut(), axis[0], axis[1], axis[2], angle);
}
q
}
}
impl Quaternion for dQuaternion {
fn as_ptr_mut(&mut self) -> *mut dReal { &mut (*self)[0] as *mut dReal }
fn as_ptr(&self) -> *const dReal { &(*self)[0] as *const dReal }
}
pub trait Matrix3 {
fn as_ptr_mut(&mut self) -> *mut dReal;
fn as_ptr(&self) -> *const dReal;
fn new() -> dMatrix3 {
let mut m: dMatrix3 = [0.0; 12];
unsafe {
dRSetIdentity(m.as_ptr_mut());
}
m
}
fn from_Q(q: dQuaternion) -> dMatrix3 {
let mut m: dMatrix3 = [0.0; 12];
unsafe {
dRfromQ(m.as_ptr_mut(), q.as_ptr() as *mut dReal);
}
m
}
fn to_Q(&self) -> dQuaternion {
let mut q: dQuaternion = [0.0; 4];
unsafe {
dQfromR(q.as_ptr_mut(), self.as_ptr() as *mut dReal);
}
q
}
fn from_axis_and_angle(axis: [dReal; 3], angle: dReal) -> dMatrix3 {
let mut m: dMatrix3 = [0.0; 12];
unsafe {
dRFromAxisAndAngle(m.as_ptr_mut(), axis[0], axis[1], axis[2], angle);
}
m
}
fn from_euler_angles(phi: dReal, theta: dReal, psi: dReal) -> dMatrix3 {
let mut m: dMatrix3 = [0.0; 12];
unsafe {
dRFromEulerAngles(m.as_ptr_mut(), phi, theta, psi);
}
m
}
fn from_2_axes(e0: [dReal; 3], e1: [dReal; 3]) -> dMatrix3 {
let mut m: dMatrix3 = [0.0; 12];
unsafe {
dRFrom2Axes(m.as_ptr_mut(), e0[0], e0[1], e0[2], e1[0], e1[1], e1[2]);
}
m
}
fn from_z_axis(e: [dReal; 3]) -> dMatrix3 {
let mut m: dMatrix3 = [0.0; 12];
unsafe {
dRFromZAxis(m.as_ptr_mut(), e[0], e[1], e[2]);
}
m
}
}
impl Matrix3 for dMatrix3 {
fn as_ptr_mut(&mut self) -> *mut dReal { &mut (*self)[0] as *mut dReal }
fn as_ptr(&self) -> *const dReal { &(*self)[0] as *const dReal }
}
pub trait Matrix4 {
fn new() -> dMatrix4 {
let mut m: dMatrix4 = [0.0; 16];
for i in 0..4 { m[i * 5] = 1.0; }
m
}
}
impl Matrix4 for dMatrix4 {
}
impl dMass {
pub fn new() -> dMass {
let mut mass: dMass = dMass{
mass: 0.0,
c: [0.0; 4], I: [0.0; 12]}; unsafe { dMassSetZero(&mut mass); } mass
}
}