1 //metadoc ODEJoint Jonathan Wright", 2006)
2 //metadoc ODEJoint license BSD revised
3 /*metadoc ODEJoint description
7 #include "IoODEJoint_internal.h"
11 #include "IoVector_ode.h"
12 #include "GLIncludes.h"
14 /* ----------------------------------------------------------- */
16 IoTag
*IoODEJoint_newTag(void *state
)
18 // TODO: Get rid of IoODEJoint as an IoObject. Can't be manipulated directly through Io.
19 IoTag
*tag
= IoTag_newWithName_("ODEJoint");
20 IoTag_state_(tag
, state
);
21 IoTag_freeFunc_(tag
, (IoTagFreeFunc
*)IoODEJoint_free
);
22 IoTag_markFunc_(tag
, (IoTagMarkFunc
*)IoODEJoint_mark
);
23 IoTag_cloneFunc_(tag
, (IoTagCloneFunc
*)IoODEJoint_rawClone
);
27 IoODEJoint
*IoODEJoint_proto(void *state
)
29 IoObject
*self
= IoObject_new(state
);
30 IoObject_tag_(self
, IoODEJoint_newTag(state
));
32 IoODEJoint_protoCommon(self
);
34 IoState_registerProtoWithFunc_(state
, self
, IoODEJoint_proto
);
37 IoMethodTable methodTable
[] = {
38 ODE_COMMON_JOINT_METHODS
41 IoObject_addMethodTable_(self
, methodTable
);
46 void IoODEJoint_protoCommon(IoODEJoint
*self
)
48 IoObject_setDataPointer_(self
, calloc(1, sizeof(IoODEJointData
)));
55 IoODEJoint
*IoODEJoint_rawClone(IoODEJoint
*proto
)
57 IoObject
*self
= IoObject_rawClonePrimitive(proto
);
58 IoObject_setDataPointer_(self
, calloc(1, sizeof(IoODEJointData
)));
62 void IoODEJoint_free(IoODEJoint
*self
)
64 if(JOINTID
&& JOINTGROUP
)
66 IoODEJointGroup_removeJoint(JOINTGROUP
, self
);
67 dJointDestroy(JOINTID
);
69 free(IoObject_dataPointer(self
));
72 void IoODEJoint_mark(IoODEJoint
*self
)
76 IoObject_shouldMark((IoObject
*)JOINTGROUP
);
80 IoODEJoint
*IoODEJoint_newProtoCommon(void *state
, IoStateProtoFunc
*func
, IoODEJointGroup
*jointGroup
)
82 IoODEJoint
*proto
= IoState_protoWithInitFunction_(state
, func
);
83 IoODEJoint
*self
= IOCLONE(proto
);
84 JOINTGROUP
= jointGroup
;
88 /* ----------------------------------------------------------- */
90 void IoODEJoint_worldDestoryed(IoODEJoint
*self
)
96 /* ----------------------------------------------------------- */
99 IoObject
*IoODEJoint_jointId(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
)
101 return IONUMBER((long)JOINTID
);
104 IoObject
*IoODEJoint_jointGroup(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
)
106 return JOINTGROUP
? JOINTGROUP
: IONIL(self
);
109 void IoODEJoint_assertValidJoint(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
)
111 IOASSERT(JOINTGROUP
, "This ODE joint belongs to an ODE joint group which has been freed or emptied.");
112 IOASSERT(JOINTID
, "ODE Joint cannot be used directly. Clone the joint and use the Joint on the cloned joint.");
115 IoObject
*IoODEJoint_attach(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
)
117 dBodyID body1
= IoMessage_locals_odeBodyIdArgAt_(m
, locals
, 0);
118 dBodyID body2
= IoMessage_locals_odeBodyIdArgAt_(m
, locals
, 1);
120 IoODEJoint_assertValidJoint(self
, locals
, m
);
121 dJointAttach(JOINTID
, body1
, body2
);
125 IoObject
*IoODEJoint_attachedBody1(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
)
127 IoODEJoint_assertValidJoint(self
, locals
, m
);
128 return IoODEBody_bodyFromId(IOSTATE
, dJointGetBody(JOINTID
, 0));
131 IoObject
*IoODEJoint_attachedBody2(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
)
133 IoODEJoint_assertValidJoint(self
, locals
, m
);
134 return IoODEBody_bodyFromId(IOSTATE
, dJointGetBody(JOINTID
, 1));
137 IoObject
*IoODEJoint_getParam(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
, int parameter
, IoODEJointGetParamFunc func
)
139 IoODEJoint_assertValidJoint(self
, locals
, m
);
140 return IONUMBER(func(JOINTID
, parameter
));
143 IoObject
*IoODEJoint_setParam(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
, int parameter
, IoODEJointSetParamFunc func
)
145 dReal value
= IoMessage_locals_doubleArgAt_(m
, locals
, 0);
146 IoODEJoint_assertValidJoint(self
, locals
, m
);
147 func(JOINTID
, parameter
, value
);
151 IoObject
*IoODEJoint_getVector3(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
, IoODEJointGetVector3Func func
)
155 IoODEJoint_assertValidJoint(self
, locals
, m
);
156 func(JOINTID
, anchor
);
157 return IoVector_newWithODEPoint(IOSTATE
, anchor
);
160 IoObject
*IoODEJoint_setVector3(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
, IoODEJointSetVector3Func func
)
162 dReal x
= IoMessage_locals_doubleArgAt_(m
, locals
, 0);
163 dReal y
= IoMessage_locals_doubleArgAt_(m
, locals
, 1);
164 dReal z
= IoMessage_locals_doubleArgAt_(m
, locals
, 2);
166 IoODEJoint_assertValidJoint(self
, locals
, m
);
167 func(JOINTID
, x
, y
, z
);
171 IoObject
*IoODEJoint_getReal(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
, IoODEJointGetReal func
)
173 IoODEJoint_assertValidJoint(self
, locals
, m
);
174 return IONUMBER(func(JOINTID
));
177 IoObject
*IoODEJoint_setReal(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
, IoODEJointSetReal func
)
179 dReal value
= IoMessage_locals_doubleArgAt_(m
, locals
, 0);
181 IoODEJoint_assertValidJoint(self
, locals
, m
);
182 func(JOINTID
, value
);
186 IoObject
*IoODEJoint_setReal2(IoODEJoint
*self
, IoObject
*locals
, IoMessage
*m
, IoODEJointSetReal2 func
)
188 dReal value1
= IoMessage_locals_doubleArgAt_(m
, locals
, 0);
189 dReal value2
= IoMessage_locals_doubleArgAt_(m
, locals
, 1);
191 IoODEJoint_assertValidJoint(self
, locals
, m
);
192 func(JOINTID
, value1
, value2
);