Addons updated to new doc format
[io.git] / addons / ODE / source / IoODEPlane.c
blobccb0230e2f95bbd1ab8a7e69797dd217541a9756
1 //metadoc ODEPlane copyrigth Jonathan Wright, 2006
2 //metadoc ODEPlane license BSD revised
3 /*metadoc ODEPlane description
4 ODEPlane binding
5 */
7 #include "IoODEPlane.h"
8 #include "IoState.h"
9 #include "IoSeq.h"
10 #include "IoVector_ode.h"
11 #include "IoList.h"
12 #include "geom.h"
14 #define DATA(self) ((IoODEPlaneData *)IoObject_dataPointer(self))
15 #define GEOMID (DATA(self)->geomId)
17 IoTag *IoODEPlane_newTag(void *state)
19 IoTag *tag = IoTag_newWithName_("ODEPlane");
20 IoTag_state_(tag, state);
21 IoTag_freeFunc_(tag, (IoTagFreeFunc *)IoODEPlane_free);
22 IoTag_cloneFunc_(tag, (IoTagCloneFunc *)IoODEPlane_rawClone);
23 return tag;
26 IoODEPlane *IoODEPlane_proto(void *state)
28 IoObject *self = IoObject_new(state);
29 IoObject_tag_(self, IoODEPlane_newTag(state));
31 IoObject_setDataPointer_(self, calloc(1, sizeof(IoODEPlaneData)));
33 GEOMID = 0;
35 IoState_registerProtoWithFunc_(state, self, IoODEPlane_proto);
38 IoMethodTable methodTable[] = {
39 {"geomId", IoODEPlane_geomId},
40 {"params", IoODEPlane_params},
41 {"setParams", IoODEPlane_setParams},
42 {"collide", IoODEGeom_collide},
44 {NULL, NULL},
46 IoObject_addMethodTable_(self, methodTable);
48 return self;
51 IoODEPlane *IoODEPlane_rawClone(IoODEPlane *proto)
53 IoObject *self = IoObject_rawClonePrimitive(proto);
54 IoObject_setDataPointer_(self, calloc(1, sizeof(IoODEPlaneData)));
55 return self;
58 IoODEPlane *IoODEPlane_new(void *state, dGeomID geomId)
60 IoODEPlane *proto = IoState_protoWithInitFunction_(state, IoODEPlane_proto);
61 IoODEPlane *self = IOCLONE(proto);
62 GEOMID = geomId;
63 dGeomSetData(GEOMID, self);
64 return self;
67 void IoODEPlane_free(IoODEPlane *self)
69 if(GEOMID)
71 dGeomDestroy(GEOMID);
72 GEOMID = 0;
75 free(IoObject_dataPointer(self));
78 void IoODEPlane_mark(IoODEPlane *self)
82 /* ----------------------------------------------------------- */
84 dGeomID IoODEPlane_rawGeomId(IoODEPlane *self)
86 return GEOMID;
89 /* ----------------------------------------------------------- */
91 void IoODEPlane_assertHasPlaneId(IoODEPlane *self, IoObject *locals, IoMessage *m)
93 IOASSERT(GEOMID, "ODE Plane cannot be used directly. Clone the space and use the clone.");
97 IoObject *IoODEPlane_geomId(IoODEPlane *self, IoObject *locals, IoMessage *m)
99 return IONUMBER((long)GEOMID);
102 IoObject *IoODEPlane_params(IoODEPlane *self, IoObject *locals, IoMessage *m)
104 dVector4 params;
105 IoODEPlane_assertHasPlaneId(self, locals, m);
106 dGeomPlaneGetParams(GEOMID, params);
107 return IoVector_newWithODEVector4(IOSTATE, params);
110 IoObject *IoODEPlane_setParams(IoODEPlane *self, IoObject *locals, IoMessage *m)
112 dReal a = IoMessage_locals_doubleArgAt_(m, locals, 0);
113 dReal b = IoMessage_locals_doubleArgAt_(m, locals, 1);
114 dReal c = IoMessage_locals_doubleArgAt_(m, locals, 2);
115 dReal d = IoMessage_locals_doubleArgAt_(m, locals, 3);
117 IoODEPlane_assertHasPlaneId(self, locals, m);
118 dGeomPlaneSetParams(GEOMID, a, b, c, d);
119 return self;