1 // Copyright (c) 2006, Jonathan Wright
5 #include "IoODEPlane.h"
6 #include "IoODEContact.h"
9 #define DATA(self) ((IoODEGeomData *)IoObject_dataPointer(self))
11 int ISODEGEOM(IoObject
*self
)
13 return ISODEBOX(self
) || ISODEPLANE(self
);
16 IoObject
*IoMessage_locals_odeGeomArgAt_(IoMessage
*self
, void *locals
, int n
)
18 IoObject
*g
= IoMessage_locals_valueArgAt_(self
, locals
, n
);
20 if (!ISODEGEOM(g
) && !ISNIL(g
))
22 IoMessage_locals_numberArgAt_errorForType_(self
, locals
, n
, "ODEGeom");
28 dGeomID
IoMessage_locals_odeGeomIdArgAt_(IoMessage
*self
, void *locals
, int n
)
30 IoObject
*geom
= IoMessage_locals_odeGeomArgAt_(self
, locals
, n
);
38 return DATA(geom
)->geomId
;
42 IoObject
*IoODEGeom_geomFromId(void *state
, dGeomID id
)
46 return ((IoState
*)state
)->ioNil
;
50 return (IoObject
*)dGeomGetData(id
);
54 IoObject
*IoODEGeom_collide(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
56 dGeomID g1
= DATA(self
)->geomId
;
57 dGeomID g2
= IoMessage_locals_odeGeomIdArgAt_(m
, locals
, 0);
59 int max
= IoMessage_argCount(m
) > 1 ? IoMessage_locals_doubleArgAt_(m
, locals
, 1) : 1;
60 dContactGeom
* contacts
= calloc(max
, sizeof(*contacts
));
62 int count
= dCollide(g1
, g2
, max
, contacts
, sizeof(*contacts
));
64 IoList
*result
= IoList_new(IOSTATE
);
67 for(i
=0; i
< count
; i
++)
69 IoODEContact
*contact
= IoODEContact_newContactGeom(IOSTATE
, &(contacts
[i
]));
70 IoList_rawAppend_(result
, contact
);