From: Matthias B. <mb...@us...> - 2004-08-03 07:19:22
|
Update of /cvsroot/pyode/pyode/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28697 Modified Files: declarations.pyx ode.pyx space.pyx Log Message: 1) The Space class is now derived from GeomObject (as a Space is meanwhile considered to be a geom object in ODE). 2) Added some missing Space methods. Index: ode.pyx =================================================================== RCS file: /cvsroot/pyode/pyode/src/ode.pyx,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ode.pyx 31 Jul 2004 12:28:02 -0000 1.8 --- ode.pyx 3 Aug 2004 07:19:13 -0000 1.9 *************** *** 140,143 **** --- 140,146 ---- include "joints.pyx" + # Geom base + include "geomobject.pyx" + # Space include "space.pyx" Index: space.pyx =================================================================== RCS file: /cvsroot/pyode/pyode/src/space.pyx,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** space.pyx 12 Jul 2004 17:30:08 -0000 1.2 --- space.pyx 3 Aug 2004 07:19:13 -0000 1.3 *************** *** 1,4 **** # Space ! cdef class Space: """Space class (container for geometry objects). --- 1,4 ---- # Space ! cdef class Space(GeomObject): """Space class (container for geometry objects). *************** *** 16,20 **** --- 16,24 ---- """ + # The id of the space. Actually this is a copy of the value in self.gid + # (as the Space is derived from GeomObject) which can be used without + # casting whenever a *space* id is required. cdef dSpaceID sid + # Dictionary with Geomobjects. Key is the ID (geom._id()) and the value # is the geom object (Python wrapper). This is used in collide_callback() *************** *** 27,30 **** --- 31,37 ---- self.sid = dHashSpaceCreate(0) + # Copy the ID + self.gid = <dGeomID>self.sid + dSpaceSetCleanup(self.sid, 0) _geom_c2py_lut[<long>self.sid]=self *************** *** 35,40 **** def __dealloc__(self): ! if self.sid!=NULL: dSpaceDestroy(self.sid) # def _addgeom(self, geom): --- 42,49 ---- def __dealloc__(self): ! if self.gid!=NULL: dSpaceDestroy(self.sid) + self.sid = NULL + self.gid = NULL # def _addgeom(self, geom): *************** *** 62,65 **** --- 71,106 ---- return id + def add(self, GeomObject geom): + """add(geom) + + Add a geom to a space. This does nothing if the geom is + already in the space. + + @param geom: Geom object to add + @type geom: GeomObject + """ + + dSpaceAdd(self.sid, geom.gid) + + def remove(self, GeomObject geom): + """remove(geom) + + Remove a geom from a space. + + @param geom: Geom object to remove + @type geom: GeomObject + """ + dSpaceRemove(self.sid, geom.gid) + + def query(self, GeomObject geom): + """query(geom) -> bool + + Return True if the given geom is in the space. + + @param geom: Geom object to check + @type geom: GeomObject + """ + return dSpaceQuery(self.sid, geom.gid) + def getNumGeoms(self): """getNumGeoms() -> int *************** *** 69,72 **** --- 110,133 ---- return dSpaceGetNumGeoms(self.sid) + def getGeom(self, int idx): + """getGeom(idx) -> GeomObject + + Return the geom with the given index contained within the space. + + @param idx: Geom index (0,1,...,getNumGeoms()-1) + @type idx: int + """ + cdef dGeomID gid + + # Check the index + if idx<0 or idx>=dSpaceGetNumGeoms(self.sid): + raise IndexError, "geom index out of range" + + gid = dSpaceGetGeom(self.sid, idx) + if <long>gid not in _geom_c2py_lut: + raise RuntimeError, "geom id cannot be translated to a Python object" + + return _geom_c2py_lut[<long>gid] + def collide(self, arg, callback): """Do collision detection. Index: declarations.pyx =================================================================== RCS file: /cvsroot/pyode/pyode/src/declarations.pyx,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** declarations.pyx 31 Jul 2004 12:27:27 -0000 1.8 --- declarations.pyx 3 Aug 2004 07:19:13 -0000 1.9 *************** *** 300,303 **** --- 300,304 ---- void dSpaceAdd (dSpaceID, dGeomID) void dSpaceRemove (dSpaceID, dGeomID) + int dSpaceQuery (dSpaceID, dGeomID) void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback) *************** *** 308,311 **** --- 309,313 ---- int dSpaceGetNumGeoms (dSpaceID) + dGeomID dSpaceGetGeom (dSpaceID, int i) # Geom |