Store contact geoms on collision, not just points. Also, fix memory leak.

This commit is contained in:
rdb 2009-04-12 12:34:14 +00:00
parent 94dd3b9624
commit 5292623b94
5 changed files with 41 additions and 17 deletions

View File

@ -62,13 +62,24 @@ get_body2() {
}
////////////////////////////////////////////////////////////////////
// Function: OdeCollisionEntry::get_num_contact_points
// Function: OdeCollisionEntry::get_num_contacts
// Access: Published
// Description: Returns the number of contact points.
// Description: Returns the number of contacts in the collision.
////////////////////////////////////////////////////////////////////
INLINE const size_t OdeCollisionEntry::
get_num_contact_points() {
return _num_points;
get_num_contacts() {
return _num_contacts;
}
////////////////////////////////////////////////////////////////////
// Function: OdeCollisionEntry::get_contact_geom
// Access: Published
// Description: Returns the nth contact geom in the collision.
////////////////////////////////////////////////////////////////////
INLINE const OdeContactGeom OdeCollisionEntry::
get_contact_geom(size_t n) {
nassertr(n >= 0 && n < _num_contacts, OdeContactGeom());
return _contact_geoms[n];
}
////////////////////////////////////////////////////////////////////
@ -78,7 +89,7 @@ get_num_contact_points() {
////////////////////////////////////////////////////////////////////
INLINE const LPoint3f OdeCollisionEntry::
get_contact_point(size_t n) {
nassertr(n >= 0 && n < _num_points, LPoint3f::zero());
return _points[n];
nassertr(n >= 0 && n < _num_contacts, LPoint3f::zero());
return _contact_geoms[n].get_pos();
}

View File

@ -16,3 +16,13 @@
TypeHandle OdeCollisionEntry::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: OdeCollisionEntry::Destructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
OdeCollisionEntry::
~OdeCollisionEntry() {
delete[] _contact_geoms;
}

View File

@ -18,7 +18,7 @@
#include "pandabase.h"
#include "typedReferenceCount.h"
class OdeGeom;
#include "odeContactGeom.h"
////////////////////////////////////////////////////////////////////
// Class : OdeCollisionEntry
@ -27,23 +27,25 @@ class OdeGeom;
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAODE OdeCollisionEntry : public TypedReferenceCount {
PUBLISHED:
virtual ~OdeCollisionEntry() {};
virtual ~OdeCollisionEntry();
INLINE const OdeGeom get_geom1();
INLINE const OdeGeom get_geom2();
INLINE const OdeBody get_body1();
INLINE const OdeBody get_body2();
INLINE const size_t get_num_contacts();
INLINE const LPoint3f get_contact_point(size_t n);
INLINE const size_t get_num_contact_points();
MAKE_SEQ(get_contact_points, get_num_contact_points, get_contact_point);
INLINE const OdeContactGeom get_contact_geom(size_t n);
MAKE_SEQ(get_contact_points, get_num_contacts, get_contact_point);
MAKE_SEQ(get_contact_geoms, get_num_contacts, get_contact_geom);
private:
INLINE OdeCollisionEntry();
dGeomID _geom1, _geom2;
dBodyID _body1, _body2;
size_t _num_points;
LPoint3f *_points;
size_t _num_contacts;
OdeContactGeom *_contact_geoms;
public:
static TypeHandle get_class_type() {

View File

@ -22,12 +22,15 @@
#include "ode_includes.h"
#include "odeGeom.h"
class OdeSpace;
////////////////////////////////////////////////////////////////////
// Class : OdeContactGeom
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAODE OdeContactGeom : public TypedReferenceCount {
friend class OdeContact;
friend class OdeSpace;
PUBLISHED:
OdeContactGeom();

View File

@ -206,8 +206,8 @@ auto_callback(void *data, dGeomID o1, dGeomID o2) {
entry->_geom2 = o2;
entry->_body1 = b1;
entry->_body2 = b2;
entry->_num_points = numc;
entry->_points = new LPoint3f[numc];
entry->_num_contacts = numc;
entry->_contact_geoms = new OdeContactGeom[numc];
}
for(i=0; i < numc; i++) {
@ -216,9 +216,7 @@ auto_callback(void *data, dGeomID o1, dGeomID o2) {
dJointAttach(c, b1, b2);
}
if (!_collide_space->_collision_event.empty()) {
entry->_points[i][0] = contact[i].geom.pos[0];
entry->_points[i][1] = contact[i].geom.pos[1];
entry->_points[i][2] = contact[i].geom.pos[2];
entry->_contact_geoms[i] = contact[i].geom;
}
// this creates contact position data for python. It is useful for debugging only 64 points are stored
if(contactCount < 64) {