Translation for the ogreode collision handling tutorial

cxxD

01-05-2010 14:46:52

hi guys i cant figure out what is done in this tutorial:
http://www.ogre3d.org/wiki/index.php/Og ... n_Handling

i think i could figure out this part:
bool MyClass::collision(OgreOde::Contact *Contact)
{
// Check for collisions between things that are connected and ignore them
OgreOde::Geometry * const g1 = Contact->getFirstGeometry();
OgreOde::Geometry * const g2 = Contact->getSecondGeometry();

if (g1 && g2)
{
const OgreOde::Body * const b1 = g2->getBody();
const OgreOde::Body * const b2 = g1->getBody();
if (b1 && b2 && OgreOde::Joint::areConnected(b1, b2))
return false;
}

//set contact parameters:
Contact->setBouncyness(1.0);
Contact->setCoulombFriction(OgreOde::Utility::Infinity);
Contact->setForceDependentSlip(1.0);
Contact->setAdditionalFDS(1.0);

/*we have 2 collidable objects from our object system, if one of the Collide function returns false, we return false in this method, too,
else we return true, so ode computes a normal collision.
true means ode will treat this like a normal collison => rigid body behavior
false means ode will not treat this collision at all => objects ignore each other*/

bool Return = true;

if (g1->getUserAny().isEmpty() == false))
if (!any_cast<CollisionTestedObject*>(g1->getUserAny())->Collide(true, Contact))
Return = false;

if (g2->getUserAny().isEmpty() == false)
if (!any_cast<CollisionTestedObject*>(g2->getUserAny())->Collide(false, Contact))
Return = false;

return Return;
}



which i turned to:
def Collision(contact):
g1 = contact.getFirstGeometry()
g2 = contact.getSecondGeometry()
if g1 and g2:
b1 = g2.getBody()
b2 = g1.getBody()
if b1 and b2 and ode.Joint.areConnected(b1, b2):
return False

contact.setBouncyness(1)
contact.setCoulombFriction(ode.Utility.Infinity)
contact.setForceDependantSlip(1)
contact.setAdditionalFDS(1)

if g1.getUserAny().isEmpty() == false:
if g1.getUser.Any().Collide(true, contact):
return false

if g2.getUserAny().isEmpty() == false:
if g2.getUser.Any().Collide(true, contact):
return false

and i figured out that the next thing coming is something like contact data for the colliding objects (but i dont think this is so heavily used, i just want to test collision detection first, the right behaviour is coming afterwards) but what the heck is this??:

class CollisionTestedObject
{
public:
CollisionTestedObject(void);
virtual ~CollisionTestedObject(void);

/*!
\brief
This function will be called, if a geometry collides that has a user object that points to this object.
*/
bool virtual Collide(bool MineIsFirst, OgreOde::Contact *Contact) = 0;

};


what does it do? it makes no sense to me... :?
i didnt get further than that because of my bad c knowledge (its not c knowledge its vb knowledge so......)

could someone translate it entirely?

dermont

02-05-2010 03:02:33

It's an abstract class since it contains pure virtual methods:
- http://en.wikipedia.org/wiki/Virtual_function

For python you should check links such as:
- http://docs.python.org/library/abc.html ... ractmethod
- http://www.velocityreviews.com/forums/t ... ython.html
- http://www.devx.com/opensource/Article/ ... 763/page/2

One implementation would be something like this:


from abc import ABCMeta, abstractmethod, abstractproperty
from types import *

class CollisionTestedObject:
__metaclass__ = ABCMeta

@abstractmethod
def Collide(bMineIsFirst, Contact):
raise NotImplementedError('Can\'t instantiate class `' + \
cls.__name__ + '\';\n' + \
'Abstract methods: ' + \
", ".join(cls.__abstractmethods__))


I don't really understand why the ogreode tutorial appears to be so complicated for what you are trying to do. You could create a simple contact collision class:


class MyCollidingObject:
def __init__(self):
self.Bouncyness = 0.5
self.BounceVelocity = -1.0
self.ForceDependentSlip = 1.0
self.Friction = 99999999
def Collide(self, bMineIsFirst, Contact):
Contact.setForceDependentSlip(self.ForceDependentSlip)
Contact.setAdditionalFDS(self.ForceDependentSlip)
Contact.setCoulombFriction(self.Friction)
Contact.setBouncyness( self.Bouncyness, self.BounceVelocity)
return True


and link to geometry:

self.collisionObject = MyCollidingObject()
geom.setUserAny(ogre.Any(self.collisionObject))


and in your collision callback:

if not g1.getUserAny().isEmpty():
anyData = g1.getUserAny().getData()[1]
if not isinstance(anyData, MyCollidingObject):
ret = False
else:
ret = anyData.Collide(True, contact)

if not g2.getUserAny().isEmpty():
anyData = g2.getUserAny().getData()[1]
if not isinstance(anyData, MyCollidingObject):
ret = False
else:
ret = anyData.Collide(True, contact)
return ret


Attached is an example of the above.

cxxD

02-05-2010 09:45:13

ill think about that.. and thank you very much:)
but you can be sure to receive a lot more dumb questions by me

EDIT:
i didnt quite manage to get this working... but once ive managed to ill post some information here... maybe

EDIT 2:
I achieved collision detection some time ago... i found out how to do by accident. It's totally different from what was done in the tutorial...