From f431703f0a49f4c375611f6487415ce82a032d11 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 14 Apr 2009 15:40:18 +0000 Subject: [PATCH] Phase out OdeContactCollection --- panda/src/ode/Sources.pp | 3 - panda/src/ode/odeCollisionEntry.I | 48 ++++++++-- panda/src/ode/odeCollisionEntry.h | 21 +++-- panda/src/ode/odeContactCollection.I | 88 ------------------- panda/src/ode/odeContactCollection.cxx | 116 ------------------------- panda/src/ode/odeContactCollection.h | 57 ------------ panda/src/ode/odeContactGeom.h | 2 + panda/src/ode/odeUtil.cxx | 19 ++-- panda/src/ode/odeUtil.h | 4 +- panda/src/ode/pode_composite1.cxx | 1 - 10 files changed, 71 insertions(+), 288 deletions(-) delete mode 100644 panda/src/ode/odeContactCollection.I delete mode 100644 panda/src/ode/odeContactCollection.cxx delete mode 100644 panda/src/ode/odeContactCollection.h diff --git a/panda/src/ode/Sources.pp b/panda/src/ode/Sources.pp index 78791c00bc..afd13f6fae 100755 --- a/panda/src/ode/Sources.pp +++ b/panda/src/ode/Sources.pp @@ -29,7 +29,6 @@ odeContact.I odeContact.h \ odeAMotorJoint.I odeAMotorJoint.h \ odeBallJoint.I odeBallJoint.h \ - odeContactCollection.I odeContactCollection.h \ odeContactJoint.I odeContactJoint.h \ odeFixedJoint.I odeFixedJoint.h \ odeHingeJoint.I odeHingeJoint.h \ @@ -62,7 +61,6 @@ odeSpace.cxx \ odeGeom.cxx \ odeSurfaceParameters.cxx \ - odeContactCollection.cxx \ odeContactGeom.cxx odeContact.cxx \ odeAMotorJoint.cxx odeBallJoint.cxx \ odeContactJoint.cxx odeFixedJoint.cxx \ @@ -91,7 +89,6 @@ odeGeom.I odeGeom.h \ odeSurfaceParameters.I odeSurfaceParameters.h \ odeContactGeom.I odeContactGeom.h \ - odeContactCollection.I odeContactCollection.h \ odeContact.I odeContact.h \ odeAMotorJoint.I odeAMotorJoint.h \ odeBallJoint.I odeBallJoint.h \ diff --git a/panda/src/ode/odeCollisionEntry.I b/panda/src/ode/odeCollisionEntry.I index 13512d3a8c..d5c011da73 100644 --- a/panda/src/ode/odeCollisionEntry.I +++ b/panda/src/ode/odeCollisionEntry.I @@ -27,7 +27,7 @@ OdeCollisionEntry() { // Description: Returns the first geom in the collision. //////////////////////////////////////////////////////////////////// INLINE const OdeGeom OdeCollisionEntry:: -get_geom1() { +get_geom1() const { return OdeGeom(_geom1); } @@ -37,7 +37,7 @@ get_geom1() { // Description: Returns the second geom in the collision. //////////////////////////////////////////////////////////////////// INLINE const OdeGeom OdeCollisionEntry:: -get_geom2() { +get_geom2() const { return OdeGeom(_geom2); } @@ -47,7 +47,7 @@ get_geom2() { // Description: Returns the first body in the collision. //////////////////////////////////////////////////////////////////// INLINE const OdeBody OdeCollisionEntry:: -get_body1() { +get_body1() const { return OdeBody(_body1); } @@ -57,7 +57,7 @@ get_body1() { // Description: Returns the second body in the collision. //////////////////////////////////////////////////////////////////// INLINE const OdeBody OdeCollisionEntry:: -get_body2() { +get_body2() const { return OdeBody(_body2); } @@ -67,7 +67,7 @@ get_body2() { // Description: Returns the number of contacts in the collision. //////////////////////////////////////////////////////////////////// INLINE const size_t OdeCollisionEntry:: -get_num_contacts() { +get_num_contacts() const { return _num_contacts; } @@ -77,7 +77,18 @@ get_num_contacts() { // Description: Returns the nth contact geom in the collision. //////////////////////////////////////////////////////////////////// INLINE const OdeContactGeom OdeCollisionEntry:: -get_contact_geom(size_t n) { +get_contact_geom(size_t n) const { + nassertr(n >= 0 && n < _num_contacts, OdeContactGeom()); + return _contact_geoms[n]; +} + +//////////////////////////////////////////////////////////////////// +// Function: OdeCollisionEntry::operator [] +// Access: Published +// Description: Returns the nth contact geom in the collision. +//////////////////////////////////////////////////////////////////// +INLINE const OdeContactGeom OdeCollisionEntry:: +operator [] (size_t n) const { nassertr(n >= 0 && n < _num_contacts, OdeContactGeom()); return _contact_geoms[n]; } @@ -86,10 +97,33 @@ get_contact_geom(size_t n) { // Function: OdeCollisionEntry::get_contact_point // Access: Published // Description: Returns the nth contact point in the collision. +// This does exactly the same as +// get_contact_geom(n).get_pos(). //////////////////////////////////////////////////////////////////// INLINE const LPoint3f OdeCollisionEntry:: -get_contact_point(size_t n) { +get_contact_point(size_t n) const { nassertr(n >= 0 && n < _num_contacts, LPoint3f::zero()); return _contact_geoms[n].get_pos(); } +//////////////////////////////////////////////////////////////////// +// Function: OdeCollisionEntry::operator bool +// Access: Published +// Description: An OdeCollisionEntry evaluates to False if it +// holds no contacts. +//////////////////////////////////////////////////////////////////// +INLINE OdeCollisionEntry:: +operator bool () const { + return (_num_contacts != 0); +} + +//////////////////////////////////////////////////////////////////// +// Function: OdeCollisionEntry::is_empty +// Access: Published +// Description: Returns true if the entry holds no contacts. +//////////////////////////////////////////////////////////////////// +INLINE bool OdeCollisionEntry:: +is_empty() const { + return (_num_contacts == 0); +} + diff --git a/panda/src/ode/odeCollisionEntry.h b/panda/src/ode/odeCollisionEntry.h index 3ccc3c5b7f..350c882fd0 100644 --- a/panda/src/ode/odeCollisionEntry.h +++ b/panda/src/ode/odeCollisionEntry.h @@ -20,6 +20,8 @@ #include "odeContactGeom.h" +class OdeUtil; + //////////////////////////////////////////////////////////////////// // Class : OdeCollisionEntry // Description : A class used to hold information about a collision @@ -29,16 +31,20 @@ class EXPCL_PANDAODE OdeCollisionEntry : public TypedReferenceCount { PUBLISHED: virtual ~OdeCollisionEntry(); - INLINE const OdeGeom get_geom1(); - INLINE const OdeGeom get_geom2(); - INLINE const OdeBody get_body1(); - INLINE const OdeBody get_body2(); + INLINE const OdeGeom get_geom1() const; + INLINE const OdeGeom get_geom2() const; + INLINE const OdeBody get_body1() const; + INLINE const OdeBody get_body2() const; - INLINE const size_t get_num_contacts(); - INLINE const LPoint3f get_contact_point(size_t n); - INLINE const OdeContactGeom get_contact_geom(size_t n); + INLINE const size_t get_num_contacts() const; + INLINE const LPoint3f get_contact_point(size_t n) const; + INLINE const OdeContactGeom get_contact_geom(size_t n) const; + INLINE const OdeContactGeom operator [] (size_t n) const; MAKE_SEQ(get_contact_points, get_num_contacts, get_contact_point); MAKE_SEQ(get_contact_geoms, get_num_contacts, get_contact_geom); + + INLINE operator bool () const; + INLINE bool is_empty() const; private: INLINE OdeCollisionEntry(); @@ -66,6 +72,7 @@ private: static TypeHandle _type_handle; friend class OdeSpace; + friend class OdeUtil; }; #include "odeCollisionEntry.I" diff --git a/panda/src/ode/odeContactCollection.I b/panda/src/ode/odeContactCollection.I deleted file mode 100644 index 8fdcfc78db..0000000000 --- a/panda/src/ode/odeContactCollection.I +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: odeContactCollection.I -// Created by: pro-rsoft (17Dec08) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: OdeContactCollection::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE OdeContactCollection:: -~OdeContactCollection() { -} - -//////////////////////////////////////////////////////////////////// -// Function: OdeContactCollection::operator += -// Access: Published -// Description: Appends the other list onto the end of this one. -//////////////////////////////////////////////////////////////////// -INLINE void OdeContactCollection:: -operator += (const OdeContactCollection &other) { - add_contacts_from(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: OdeContactCollection::operator + -// Access: Published -// Description: Returns a OdeContactCollection representing the -// concatenation of the two lists. -//////////////////////////////////////////////////////////////////// -INLINE OdeContactCollection OdeContactCollection:: -operator + (const OdeContactCollection &other) const { - OdeContactCollection a(*this); - a += other; - return a; -} - -//////////////////////////////////////////////////////////////////// -// Function: OdeContactCollection::clear -// Access: Published -// Description: Clears the contact collection. -//////////////////////////////////////////////////////////////////// -INLINE void OdeContactCollection:: -clear() { - _contacts.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: OdeContactCollection::is_empty -// Access: Published -// Description: Returns true if the collection is empty. -//////////////////////////////////////////////////////////////////// -INLINE bool OdeContactCollection:: -is_empty() const { - return _contacts.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: OdeContactCollection::get_num_contacts -// Access: Published -// Description: Returns the number of Contacts in the collection. -// This is the same thing as size(). -//////////////////////////////////////////////////////////////////// -INLINE int OdeContactCollection:: -get_num_contacts() const { - return _contacts.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: OdeContactCollection::size -// Access: Published -// Description: Returns the number of Contacts in the collection. -// This is the same thing as get_num_contacts(). -//////////////////////////////////////////////////////////////////// -INLINE int OdeContactCollection:: -size() const { - return _contacts.size(); -} - diff --git a/panda/src/ode/odeContactCollection.cxx b/panda/src/ode/odeContactCollection.cxx deleted file mode 100644 index eb15d836f3..0000000000 --- a/panda/src/ode/odeContactCollection.cxx +++ /dev/null @@ -1,116 +0,0 @@ -// Filename: odeContactCollection.cxx -// Created by: pro-rsoft (17Dec08) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#include "odeContactCollection.h" - -OdeContactCollection:: -OdeContactCollection() { -} - -OdeContactCollection:: -OdeContactCollection(const OdeContactCollection ©) : - _contacts(copy._contacts) { -} - -void OdeContactCollection:: -operator = (const OdeContactCollection ©) { - _contacts = copy._contacts; -} - -void OdeContactCollection:: -add_contact(PT(OdeContact) contact) { - _contacts.push_back(contact); -} - -bool OdeContactCollection:: -remove_contact(PT(OdeContact) contact) { - int contact_index = -1; - for (int i = 0; contact_index == -1 && i < (int)_contacts.size(); i++) { - if (_contacts[i] == contact) { - contact_index = i; - } - } - - if (contact_index == -1) { - // The indicated contact was not a member of the collection. - return false; - } - - _contacts.erase(_contacts.begin() + contact_index); - return true; -} - -void OdeContactCollection:: -add_contacts_from(const OdeContactCollection &other) { - int other_num_contacts = other.get_num_contacts(); - for (int i = 0; i < other_num_contacts; i++) { - add_contact(other.get_contact(i)); - } -} - -void OdeContactCollection:: -remove_contacts_from(const OdeContactCollection &other) { - Contacts new_contacts; - int num_contacts = get_num_contacts(); - for (int i = 0; i < num_contacts; i++) { - PT(OdeContact) contact = get_contact(i); - if (!other.has_contact(contact)) { - new_contacts.push_back(contact); - } - } - _contacts = new_contacts; -} - -void OdeContactCollection:: -remove_duplicate_contacts() { - Contacts new_contacts; - - int num_contacts = get_num_contacts(); - for (int i = 0; i < num_contacts; i++) { - PT(OdeContact) contact = get_contact(i); - bool duplicated = false; - - for (int j = 0; j < i && !duplicated; j++) { - duplicated = (contact == get_contact(j)); - } - - if (!duplicated) { - new_contacts.push_back(contact); - } - } - - _contacts = new_contacts; -} - -bool OdeContactCollection:: -has_contact(PT(OdeContact) contact) const { - for (int i = 0; i < get_num_contacts(); i++) { - if (contact == get_contact(i)) { - return true; - } - } - return false; -} - -PT(OdeContact) OdeContactCollection:: -get_contact(int index) const { - nassertr(index >= 0 && index < (int)_contacts.size(), NULL); - return _contacts[index]; -} - -PT(OdeContact) OdeContactCollection:: -operator [] (int index) const { - return get_contact(index); -} - diff --git a/panda/src/ode/odeContactCollection.h b/panda/src/ode/odeContactCollection.h deleted file mode 100644 index c47a6f4c77..0000000000 --- a/panda/src/ode/odeContactCollection.h +++ /dev/null @@ -1,57 +0,0 @@ -// Filename: odeContactCollection.h -// Created by: pro-rsoft (17Dec08) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef ODECONTACTCOLLECTION_H -#define ODECONTACTCOLLECTION_H - -#include "odeContact.h" - -//////////////////////////////////////////////////////////////////// -// Class : OdeContactCollection -// Description : This is a set of zero or more OdeContacts. It's -// handy for returning from functions that need to -// return multiple OdeContacts. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAODE OdeContactCollection { -PUBLISHED: - OdeContactCollection(); - OdeContactCollection(const OdeContactCollection ©); - void operator = (const OdeContactCollection ©); - INLINE ~OdeContactCollection(); - - void add_contact(PT(OdeContact) contact); - bool remove_contact(PT(OdeContact) contact); - void add_contacts_from(const OdeContactCollection &other); - void remove_contacts_from(const OdeContactCollection &other); - void remove_duplicate_contacts(); - bool has_contact(PT(OdeContact) contact) const; - INLINE void clear(); - - INLINE bool is_empty() const; - INLINE int get_num_contacts() const; - PT(OdeContact) get_contact(int index) const; - MAKE_SEQ(get_contacts, get_num_contacts, get_contact); - PT(OdeContact) operator [] (int index) const; - INLINE int size() const; - INLINE void operator += (const OdeContactCollection &other); - INLINE OdeContactCollection operator + (const OdeContactCollection &other) const; - -private: - typedef pvector Contacts; - Contacts _contacts; -}; - -#include "odeContactCollection.I" -#endif - diff --git a/panda/src/ode/odeContactGeom.h b/panda/src/ode/odeContactGeom.h index 52d90601f4..6de7a39660 100755 --- a/panda/src/ode/odeContactGeom.h +++ b/panda/src/ode/odeContactGeom.h @@ -23,6 +23,7 @@ #include "odeGeom.h" class OdeSpace; +class OdeUtil; //////////////////////////////////////////////////////////////////// // Class : OdeContactGeom @@ -31,6 +32,7 @@ class OdeSpace; class EXPCL_PANDAODE OdeContactGeom : public TypedReferenceCount { friend class OdeContact; friend class OdeSpace; + friend class OdeUtil; PUBLISHED: OdeContactGeom(); diff --git a/panda/src/ode/odeUtil.cxx b/panda/src/ode/odeUtil.cxx index 641ea8cba7..baf14ad0fb 100755 --- a/panda/src/ode/odeUtil.cxx +++ b/panda/src/ode/odeUtil.cxx @@ -94,21 +94,25 @@ are_connected_excluding(const OdeBody &body1, // Access: Public, Static // Description: Given two geometry objects that potentially touch // (geom1 and geom2), generate contact information -// for them. Returns a collection of OdeContacts. +// for them. Returns an OdeCollisionEntry. //////////////////////////////////////////////////////////////////// -OdeContactCollection OdeUtil:: +PT(OdeCollisionEntry) OdeUtil:: collide(const OdeGeom &geom1, const OdeGeom &geom2, const short int max_contacts) { dContactGeom *contact_list = (dContactGeom *)PANDA_MALLOC_ARRAY(max_contacts * sizeof(dContactGeom)); int num_contacts = dCollide(geom1.get_id(), geom2.get_id(), max_contacts, contact_list, sizeof(contact_list)); - OdeContactCollection contacts; + PT(OdeCollisionEntry) entry = new OdeCollisionEntry(); + entry->_geom1 = geom1.get_id(); + entry->_geom2 = geom2.get_id(); + entry->_body1 = dGeomGetBody(geom1.get_id()); + entry->_body2 = dGeomGetBody(geom2.get_id()); + entry->_num_contacts = num_contacts; + entry->_contact_geoms = new OdeContactGeom[num_contacts]; for (int i = 0; i < num_contacts; i++) { - PT(OdeContact) contact = new OdeContact(); - contact->set_geom(OdeContactGeom(contact_list[i])); - contacts.add_contact(contact); + entry->_contact_geoms[i] = contact_list[i]; } PANDA_FREE_ARRAY(contact_list); - return contacts; + return entry; } #ifdef HAVE_PYTHON @@ -153,3 +157,4 @@ OdeGeom OdeUtil:: space_to_geom(const OdeSpace &space) { return OdeGeom((dGeomID)space.get_id()); } + diff --git a/panda/src/ode/odeUtil.h b/panda/src/ode/odeUtil.h index 3e575d3724..1e9bfd04f6 100755 --- a/panda/src/ode/odeUtil.h +++ b/panda/src/ode/odeUtil.h @@ -21,7 +21,7 @@ #include "ode_includes.h" #include "odeJointCollection.h" -#include "odeContactCollection.h" +#include "odeCollisionEntry.h" #ifdef HAVE_PYTHON #include "py_panda.h" @@ -46,7 +46,7 @@ PUBLISHED: static int are_connected_excluding(const OdeBody &body1, const OdeBody &body2, const int joint_type); - static OdeContactCollection collide(const OdeGeom &geom1, const OdeGeom &geom2, + static PT(OdeCollisionEntry) collide(const OdeGeom &geom1, const OdeGeom &geom2, const short int max_contacts = 150); static int collide2(const OdeGeom &geom1, const OdeGeom &geom2, PyObject* arg, PyObject* callback); diff --git a/panda/src/ode/pode_composite1.cxx b/panda/src/ode/pode_composite1.cxx index 787241bd71..e5fae93056 100755 --- a/panda/src/ode/pode_composite1.cxx +++ b/panda/src/ode/pode_composite1.cxx @@ -11,5 +11,4 @@ #include "odeSurfaceParameters.cxx" #include "odeContactGeom.cxx" #include "odeContact.cxx" -#include "odeContactCollection.cxx"