1use crate::ode::*;
5use crate::ode::cls::*;
6use crate::ode::krp::*;
7
8#[derive(Debug)]
10pub enum MetaId {
11 Sphere = 0,
13 Box,
15 Capsule,
17 Cylinder,
19 Plane,
21 Ray,
23 Convex,
25 GeomTransform,
27 TriMesh,
29 Heightfield,
31 Composite
33}
34
35macro_rules! meta_panic {
37 ($s: ident, $e: expr) => { panic!("Expected {} but {:?}", $e, $s.id()); };
38}
39pub trait MetaInf {
43 fn id(&self) -> MetaId;
45 fn get_krp_mut(&mut self) -> &mut Krp;
47 fn get_krp(&self) -> &Krp;
49 fn get_tcm_mut(&mut self) -> &mut TCMaterial;
51 fn get_tcm(&self) -> &TCMaterial;
53 fn as_sphere(&self) -> &MetaSphere { meta_panic!(self, "Sphere"); }
55 fn as_box(&self) -> &MetaBox { meta_panic!(self, "Box"); }
57 fn as_capsule(&self) -> &MetaCapsule { meta_panic!(self, "Capsule"); }
59 fn as_cylinder(&self) -> &MetaCylinder { meta_panic!(self, "Cylinder"); }
61 fn as_plane(&self) -> &MetaPlane { meta_panic!(self, "Plane"); }
63 fn as_convex(&self) -> &MetaConvex { meta_panic!(self, "Convex"); }
65 fn as_trimesh(&self) -> &MetaTriMesh { meta_panic!(self, "TriMesh"); }
67 fn as_composite(&self) -> &MetaComposite { meta_panic!(self, "Composite"); }
69 fn dup(&self) -> Box<dyn MetaInf> { meta_panic!(self, "Clone"); }
71}
72
73#[derive(Clone)]
75pub struct MetaSphere {
76 pub dm: dReal,
78 pub r: dReal,
80 pub krp: Krp,
82 pub tcm: TCMaterial
84}
85
86impl MetaSphere {
87 pub fn new(dm: dReal, r: dReal,
89 krp: Krp, tex: i32, col: dVector4) -> Box<MetaSphere> {
90 Box::new(MetaSphere{dm: dm, r: r,
91 krp: krp, tcm: TCMaterial::new(tex, col)})
92 }
93}
94
95impl MetaInf for MetaSphere {
96 fn id(&self) -> MetaId { MetaId::Sphere }
98 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
100 fn get_krp(&self) -> &Krp { &self.krp }
102 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
104 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
106 fn as_sphere(&self) -> &MetaSphere { self }
108 fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
110}
111
112#[derive(Clone)]
114pub struct MetaBox {
115 pub dm: dReal,
117 pub lxyz: dVector3,
119 pub krp: Krp,
121 pub tcm: TCMaterial
123}
124
125impl MetaBox {
126 pub fn new(dm: dReal, lxyz: dVector3,
128 krp: Krp, tex: i32, col: dVector4) -> Box<MetaBox> {
129 Box::new(MetaBox{dm: dm, lxyz: lxyz,
130 krp: krp, tcm: TCMaterial::new(tex, col)})
131 }
132}
133
134impl MetaInf for MetaBox {
135 fn id(&self) -> MetaId { MetaId::Box }
137 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
139 fn get_krp(&self) -> &Krp { &self.krp }
141 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
143 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
145 fn as_box(&self) -> &MetaBox { self }
147 fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
149}
150
151#[derive(Clone)]
153pub struct MetaCapsule {
154 pub dm: dReal,
156 pub r: dReal,
158 pub l: dReal,
160 pub krp: Krp,
162 pub tcm: TCMaterial
164}
165
166impl MetaCapsule {
167 pub fn new(dm: dReal, r: dReal, l: dReal,
169 krp: Krp, tex: i32, col: dVector4) -> Box<MetaCapsule> {
170 Box::new(MetaCapsule{dm: dm, r: r, l: l,
171 krp: krp, tcm: TCMaterial::new(tex, col)})
172 }
173}
174
175impl MetaInf for MetaCapsule {
176 fn id(&self) -> MetaId { MetaId::Capsule }
178 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
180 fn get_krp(&self) -> &Krp { &self.krp }
182 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
184 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
186 fn as_capsule(&self) -> &MetaCapsule { self }
188 fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
190}
191
192#[derive(Clone)]
194pub struct MetaCylinder {
195 pub dm: dReal,
197 pub r: dReal,
199 pub l: dReal,
201 pub krp: Krp,
203 pub tcm: TCMaterial
205}
206
207impl MetaCylinder {
208 pub fn new(dm: dReal, r: dReal, l: dReal,
210 krp: Krp, tex: i32, col: dVector4) -> Box<MetaCylinder> {
211 Box::new(MetaCylinder{dm: dm, r: r, l: l,
212 krp: krp, tcm: TCMaterial::new(tex, col)})
213 }
214}
215
216impl MetaInf for MetaCylinder {
217 fn id(&self) -> MetaId { MetaId::Cylinder }
219 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
221 fn get_krp(&self) -> &Krp { &self.krp }
223 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
225 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
227 fn as_cylinder(&self) -> &MetaCylinder { self }
229 fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
231}
232
233#[derive(Clone)]
235pub struct MetaPlane {
236 pub dm: dReal,
238 pub lxyz: dVector3,
240 pub norm: dVector4,
242 pub krp: Krp,
244 pub tcm: TCMaterial
246}
247
248impl MetaPlane {
249 pub fn new(dm: dReal, lxyz: dVector3, norm: dVector4,
251 krp: Krp, tex: i32, col: dVector4) -> Box<MetaPlane> {
252 Box::new(MetaPlane{dm: dm, lxyz: lxyz, norm: norm,
253 krp: krp, tcm: TCMaterial::new(tex, col)})
254 }
255}
256
257impl MetaInf for MetaPlane {
258 fn id(&self) -> MetaId { MetaId::Plane }
260 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
262 fn get_krp(&self) -> &Krp { &self.krp }
264 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
266 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
268 fn as_plane(&self) -> &MetaPlane { self }
270 fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
272}
273
274#[derive(Clone)]
276pub struct MetaConvex {
277 pub ff: bool,
279 pub dm: dReal,
281 pub fvp: *mut convexfvp,
283 pub krp: Krp,
285 pub tcm: TCMaterial
287}
288
289impl MetaConvex {
290 pub fn new(ff: bool, dm: dReal, fvp: *mut convexfvp,
292 krp: Krp, tex: i32, col: dVector4) -> Box<MetaConvex> {
293 Box::new(MetaConvex{ff: ff, dm: dm, fvp: fvp,
294 krp: krp, tcm: TCMaterial::new(tex, col)})
295 }
296}
297
298impl MetaInf for MetaConvex {
299 fn id(&self) -> MetaId { MetaId::Convex }
301 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
303 fn get_krp(&self) -> &Krp { &self.krp }
305 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
307 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
309 fn as_convex(&self) -> &MetaConvex { self }
311 fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
313}
314
315impl Drop for MetaConvex {
316 fn drop(&mut self) {
317 if self.ff && self.fvp != 0 as *mut convexfvp {
318unsafe {
319 FreeConvexFVP(self.fvp, self.ff);
320}
321 }
322 }
323}
324
325#[derive(Clone)]
327pub struct MetaTriMesh {
328 pub ff: bool,
330 pub dm: dReal,
332 pub tmv: *mut trimeshvi,
334 pub krp: Krp,
336 pub tcm: TCMaterial
338}
339
340impl MetaTriMesh {
341 pub fn new(ff: bool, dm: dReal, tmv: *mut trimeshvi,
343 krp: Krp, tex: i32, col: dVector4) -> Box<MetaTriMesh> {
344 Box::new(MetaTriMesh{ff: ff, dm: dm, tmv: tmv,
345 krp: krp, tcm: TCMaterial::new(tex, col)})
346 }
347}
348
349impl MetaInf for MetaTriMesh {
350 fn id(&self) -> MetaId { MetaId::TriMesh }
352 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
354 fn get_krp(&self) -> &Krp { &self.krp }
356 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
358 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
360 fn as_trimesh(&self) -> &MetaTriMesh { self }
362 fn dup(&self) -> Box<dyn MetaInf> { Box::new(self.clone()) }
364}
365
366impl Drop for MetaTriMesh {
367 fn drop(&mut self) {
368 if self.ff && self.tmv != 0 as *mut trimeshvi {
369unsafe {
370 FreeTriMeshVI(self.tmv, self.ff);
371}
372 }
373 }
374}
375
376pub struct MetaComposite {
378 pub elems: Vec<Box<dyn MetaInf>>,
380 pub qs: Vec<dQuaternion>,
382 pub ofs: Vec<dVector3>,
384 pub krp: Krp,
386 pub tcm: TCMaterial
388}
389
390impl MetaComposite {
391 pub fn new(elems: Vec<Box<dyn MetaInf>>,
393 qs: Vec<dQuaternion>, ofs: Vec<dVector3>,
394 krp: Krp, tex: i32, col: dVector4) -> Box<MetaComposite> {
395 Box::new(MetaComposite{elems: elems, ofs: ofs, qs: qs,
396 krp: krp, tcm: TCMaterial::new(tex, col)})
397 }
398}
399
400impl MetaInf for MetaComposite {
401 fn id(&self) -> MetaId { MetaId::Composite }
403 fn get_krp_mut(&mut self) -> &mut Krp { &mut self.krp }
405 fn get_krp(&self) -> &Krp { &self.krp }
407 fn get_tcm_mut(&mut self) -> &mut TCMaterial { &mut self.tcm }
409 fn get_tcm(&self) -> &TCMaterial { &self.tcm }
411 fn as_composite(&self) -> &MetaComposite { self }
413}