more SystemCall fixes
[io/quag.git] / addons / ODE / source / geom.c
blobfb782c0bec481be1c4772afb71af88df291c63e7
1 // Copyright (c) 2006, Jonathan Wright
3 #include "geom.h"
4 #include "IoODEBox.h"
5 #include "IoODEPlane.h"
6 #include "IoODEContact.h"
7 #include "IoList.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");
25 return g;
28 dGeomID IoMessage_locals_odeGeomIdArgAt_(IoMessage *self, void *locals, int n)
30 IoObject *geom = IoMessage_locals_odeGeomArgAt_(self, locals, n);
32 if (ISNIL(geom))
34 return 0;
36 else
38 return DATA(geom)->geomId;
42 IoObject *IoODEGeom_geomFromId(void *state, dGeomID id)
44 if (id == 0)
46 return ((IoState*)state)->ioNil;
48 else
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);
65 int i;
67 for(i=0; i < count; i++)
69 IoODEContact *contact = IoODEContact_newContactGeom(IOSTATE, &(contacts[i]));
70 IoList_rawAppend_(result, contact);
73 free(contacts);
74 return result;