Python-OgreOde: Notifying other objects about collisions
Hi, I'm relatively new at Python and I've just started playing with Python-Ogre (especially the wrapped OgreOde) after some months getting nowhere with PyOgre+PyODE.
Right now I have a program with a ball on a plane that I can roll around. I control the ball with an instance of my class "Walker" that just checks for the right keys and adds torque to its attribute self.ball when the appropriate keys are pressed. So now I'd like to only add torque if the ball is colliding with another object (that is, it's on the ground). I'd like to send a message to the "Walker" instance whenever its body/geom combination has a collision. What's the best way to do this?
My thought was that I would just add an attribute to the ball's geom that would just be a list of object that are notified when the geom is in a collision. But when the contact happens and I get the geometries from the contact object, the attribute I had added is never there.
Thanks in advance for any suggestions.
Welcome to some of the wrinkles of the using wrapped C++ engines. When the callback is called a *new* python object is created around the given OgreODE geometry object. This is despite the fact that you just created that geometry from python at the beginning of your program. This happens because the callback is originating from C++ code that has no knowledge of your Python object. You are to have to find some way to lookup the Python object based on the passed C++ one.
Thanks, that makes sense. Seems to be working now. I'm using the geom's getID() to make a list of who needs to know when collisions happen. I'm storing this list in an extra CollisionMessager class I made.
I tried to bypass using IDs and just store the data in an object that I attached to the geom with setUserObject(), but I got an error that my function call didn't match the C++ signature.
Seems like using setUserObject would be a better way to do it, if it worked. (Or perhaps I just don't understand how setUserObject is supposed to work.)
Thanks again for the help.
Check the python Ogre forums for more info on that. I believe Andy is working on a fix for the issue. We will probably just be able to modify the wrapper code a little.
setUserObject() is the right way to solve your problem - however as GameEnder mentioned it's currently broken in Python-Ogre 0.9a (I missed it!) but will be fixed in the next binary release..
You can use setUserData()/getUserData() also as a work around - it's an unsigned int so you can give it a numeric value etc
Cool, I'll keep using my workaround until the next release.
So now I've got this other issue that I think is related. I have a camera man object that positions the camera in relation to the ball I'm rolling. When I create the camera man, I tell it which object (the ball's scene node) it should follow (it maintains its distance and angle to the ball). But when I run the program, the reference point (the ball's position) never moves. I'm guessing that's because the object that the camera man is following is just a Python shell of the C++ object, and it isn't getting updated. Is there some way I'm not aware of for a Python object to keep track of a wrapped C++ object? This seems like a really basic thing to do.
BTW, I appreciate your responsiveness. I'm really enjoying Python-Ogre.
Could you submit a test program, the shorter the better...
It's unlikely to be a python to c++ update issue as the python wrapper doesn't "copy" anything - however anything is possible:)
Oh my God. I'm a moron. The problem had nothing to do with Python-Ogre and everything to do with a "time-saving" function I made. But hey - I found it while culling down the program to something manageable that you could look at. So thanks once again!