use crate::ode::*;
use crate::ode::cls::*;
use crate::ode::krp::*;
#[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_krp_mut(&mut self) -> &mut Krp;
fn get_krp(&self) -> &Krp;
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_convex(&self) -> &MetaConvex { meta_panic!(self, "Convex"); }
fn as_trimesh(&self) -> &MetaTriMesh { meta_panic!(self, "TriMesh"); }
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 dm: dReal,
pub r: dReal,
pub krp: Krp,
pub tcm: TCMaterial
}
impl MetaSphere {
pub fn new(dm: dReal, r: dReal,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaSphere> {
Box::new(MetaSphere{dm: dm, r: r,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaSphere {
fn id(&self) -> MetaId { MetaId::Sphere }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
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 krp: Krp,
pub tcm: TCMaterial
}
impl MetaBox {
pub fn new(dm: dReal, lxyz: dVector3,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaBox> {
Box::new(MetaBox{dm: dm, lxyz: lxyz,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaBox {
fn id(&self) -> MetaId { MetaId::Box }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
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 krp: Krp,
pub tcm: TCMaterial
}
impl MetaCapsule {
pub fn new(dm: dReal, r: dReal, l: dReal,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaCapsule> {
Box::new(MetaCapsule{dm: dm, r: r, l: l,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaCapsule {
fn id(&self) -> MetaId { MetaId::Capsule }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
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 krp: Krp,
pub tcm: TCMaterial
}
impl MetaCylinder {
pub fn new(dm: dReal, r: dReal, l: dReal,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaCylinder> {
Box::new(MetaCylinder{dm: dm, r: r, l: l,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaCylinder {
fn id(&self) -> MetaId { MetaId::Cylinder }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
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 krp: Krp,
pub tcm: TCMaterial
}
impl MetaPlane {
pub fn new(dm: dReal, lxyz: dVector3, norm: dVector4,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaPlane> {
Box::new(MetaPlane{dm: dm, lxyz: lxyz, norm: norm,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaPlane {
fn id(&self) -> MetaId { MetaId::Plane }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
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()) }
}
#[derive(Clone)]
pub struct MetaConvex {
pub ff: bool,
pub dm: dReal,
pub fvp: *mut convexfvp,
pub krp: Krp,
pub tcm: TCMaterial
}
impl MetaConvex {
pub fn new(ff: bool, dm: dReal, fvp: *mut convexfvp,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaConvex> {
Box::new(MetaConvex{ff: ff, dm: dm, fvp: fvp,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaConvex {
fn id(&self) -> MetaId { MetaId::Convex }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_convex(&self) -> &MetaConvex { self }
fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
}
impl Drop for MetaConvex {
fn drop(&mut self) {
if self.ff && self.fvp != 0 as *mut convexfvp {
unsafe {
FreeConvexFVP(self.fvp, self.ff);
}
}
}
}
#[derive(Clone)]
pub struct MetaTriMesh {
pub ff: bool,
pub dm: dReal,
pub tmv: *mut trimeshvi,
pub krp: Krp,
pub tcm: TCMaterial
}
impl MetaTriMesh {
pub fn new(ff: bool, dm: dReal, tmv: *mut trimeshvi,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaTriMesh> {
Box::new(MetaTriMesh{ff: ff, dm: dm, tmv: tmv,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaTriMesh {
fn id(&self) -> MetaId { MetaId::TriMesh }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_trimesh(&self) -> &MetaTriMesh { self }
fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
}
impl Drop for MetaTriMesh {
fn drop(&mut self) {
if self.ff && self.tmv != 0 as *mut trimeshvi {
unsafe {
FreeTriMeshVI(self.tmv, self.ff);
}
}
}
}
pub struct MetaComposite {
pub elems: Vec<Box<dyn MetaInf>>,
pub qs: Vec<dQuaternion>,
pub ofs: Vec<dVector3>,
pub krp: Krp,
pub tcm: TCMaterial
}
impl MetaComposite {
pub fn new(elems: Vec<Box<dyn MetaInf>>,
qs: Vec<dQuaternion>, ofs: Vec<dVector3>,
krp: Krp, tex: i32, col: dVector4) -> Box<MetaComposite> {
Box::new(MetaComposite{elems: elems, ofs: ofs, qs: qs,
krp: krp, tcm: TCMaterial::new(tex, col)})
}
}
impl MetaInf for MetaComposite {
fn id(&self) -> MetaId { MetaId::Composite }
fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
fn get_krp(&self) -> &Krp { &self.krp }
fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
fn get_tcm(&self) -> &TCMaterial { &self.tcm }
fn as_composite(&self) -> &MetaComposite { self }
}