use crate::ode::*;
use crate::ode::cls::*;
#[derive(Debug)]
pub enum MetaId {
Sphere = 0,
Box,
Capsule,
Cylinder,
Plane,
Ray,
Convex,
GeomTransform,
TriMesh,
Heightfield,
Composite
}
macro_rules! meta_panic {
($s: ident, $e: expr) => { panic!("Expected {} but {:?}", $e, $s.id()); };
}
pub trait MetaInf {
fn id(&self) -> MetaId;
fn get_bounce(&self) -> dReal;
fn get_tcm_mut(&mut self) -> &mut TCMaterial;
fn get_tcm(&self) -> &TCMaterial;
fn as_sphere(&self) -> &MetaSphere { meta_panic!(self, "Sphere"); }
fn as_box(&self) -> &MetaBox { meta_panic!(self, "Box"); }
fn as_capsule(&self) -> &MetaCapsule { meta_panic!(self, "Capsule"); }
fn as_cylinder(&self) -> &MetaCylinder { meta_panic!(self, "Cylinder"); }
fn as_plane(&self) -> &MetaPlane { meta_panic!(self, "Plane"); }
fn as_composite(&self) -> &MetaComposite { meta_panic!(self, "Composite"); }
fn dup(&self) -> Box<dyn MetaInf> { meta_panic!(self, "Clone"); }
}
#[derive(Clone)]
pub struct MetaSphere {
pub m: dReal,
pub r: dReal,
pub bounce: dReal,
pub tcm: TCMaterial
}
impl MetaSphere {
pub fn new(m: dReal, r: dReal,
bounce: dReal, tex: i32, col: dVector4) -> Box<MetaSphere> {
Box::new(MetaSphere{m: m, r: r,
bounce: bounce, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaSphere {
fn id(&self) -> MetaId { MetaId::Sphere }
fn get_bounce(&self) -> dReal { self.bounce }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_sphere(&self) -> &MetaSphere { self }
fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
}
#[derive(Clone)]
pub struct MetaBox {
pub dm: dReal,
pub lxyz: dVector3,
pub bounce: dReal,
pub tcm: TCMaterial
}
impl MetaBox {
pub fn new(dm: dReal, lxyz: dVector3,
bounce: dReal, tex: i32, col: dVector4) -> Box<MetaBox> {
Box::new(MetaBox{dm: dm, lxyz: lxyz,
bounce: bounce, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaBox {
fn id(&self) -> MetaId { MetaId::Box }
fn get_bounce(&self) -> dReal { self.bounce }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_box(&self) -> &MetaBox { self }
fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
}
#[derive(Clone)]
pub struct MetaCapsule {
pub dm: dReal,
pub r: dReal,
pub l: dReal,
pub bounce: dReal,
pub tcm: TCMaterial
}
impl MetaCapsule {
pub fn new(dm: dReal, r: dReal, l: dReal,
bounce: dReal, tex: i32, col: dVector4) -> Box<MetaCapsule> {
Box::new(MetaCapsule{dm: dm, r: r, l: l,
bounce: bounce, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaCapsule {
fn id(&self) -> MetaId { MetaId::Capsule }
fn get_bounce(&self) -> dReal { self.bounce }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_capsule(&self) -> &MetaCapsule { self }
fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
}
#[derive(Clone)]
pub struct MetaCylinder {
pub dm: dReal,
pub r: dReal,
pub l: dReal,
pub bounce: dReal,
pub tcm: TCMaterial
}
impl MetaCylinder {
pub fn new(dm: dReal, r: dReal, l: dReal,
bounce: dReal, tex: i32, col: dVector4) -> Box<MetaCylinder> {
Box::new(MetaCylinder{dm: dm, r: r, l: l,
bounce: bounce, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaCylinder {
fn id(&self) -> MetaId { MetaId::Cylinder }
fn get_bounce(&self) -> dReal { self.bounce }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_cylinder(&self) -> &MetaCylinder { self }
fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
}
#[derive(Clone)]
pub struct MetaPlane {
pub dm: dReal,
pub lxyz: dVector3,
pub norm: dVector4,
pub bounce: dReal,
pub tcm: TCMaterial
}
impl MetaPlane {
pub fn new(dm: dReal, lxyz: dVector3, norm: dVector4,
bounce: dReal, tex: i32, col: dVector4) -> Box<MetaPlane> {
Box::new(MetaPlane{dm: dm, lxyz: lxyz, norm: norm,
bounce: bounce, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaPlane {
fn id(&self) -> MetaId { MetaId::Plane }
fn get_bounce(&self) -> dReal { self.bounce }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_plane(&self) -> &MetaPlane { self }
fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
}
pub struct MetaComposite {
pub elems: Vec<Box<dyn MetaInf>>,
pub ofs: Vec<dVector3>,
pub qs: Vec<dQuaternion>,
pub bounce: dReal,
pub tcm: TCMaterial
}
impl MetaComposite {
pub fn new(elems: Vec<Box<dyn MetaInf>>,
ofs: Vec<dVector3>, qs: Vec<dQuaternion>,
bounce: dReal, tex: i32, col: dVector4) -> Box<MetaComposite> {
Box::new(MetaComposite{elems: elems, ofs: ofs, qs: qs,
bounce: bounce, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaComposite {
fn id(&self) -> MetaId { MetaId::Composite }
fn get_bounce(&self) -> dReal { self.bounce }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_composite(&self) -> &MetaComposite { self }
}