Danaugrs
27-01-2009 23:31:13
How can OgreNewt warn me when two CollisionPrimitives (CollisionBoxes in the case) collide with eachother?
I guess it has something to do with setAutoactiveCallback or some other Callback function.
Is there any example of how to implement this?
Regards in advance,
Daniel
Zero23
28-01-2009 14:22:17
Do you mean with warn, Collision1 will collide with Collision2 in 2 seconds or do you only want to know when a Collision is?
For the first you can use OgreNewt::CollisionTools::CollisionCollideContinue.
For the second you can use OgreNewt::Collision::setCustomForceAndTorqueCallback.
I hope I can help you with this!
Zero
Danaugrs
28-01-2009 15:44:50
Thanks!
I meant the second option - to warn me when a collision is happening:
By the API I have this:
void setCustomForceAndTorqueCallback (boost::function< void(c *, Body *)> callback, c *instancedClassPointer)
I tried what follows based on the SimpleBuoyancy Demo - the only one I found that uses setCustomForceAndTorqueCallback
My code is as follows (I am using Python-Ogre but I think the code is really straightforward so C/C++ users may understand)
body.setStandardForceCallback() # This line was more of a guess
body.setCustomForceAndTorqueCallback(self.standardForceCallback, "")
...
def standardForceCallback(me):
mass, inertia = me.getMassMatrix()
print "callback"
Anyway I tried some translation:
body::setStandardForceCallback() // This line was more of a guess
body::setCustomForceAndTorqueCallback(standardForceCallback, "")
The function never gets called
What am I doing wrong?
Is there any example of how to use this callback function?
Regards,
Daniel
PS: My father is actually a partner of a company here in Brazil called Compex Tecnologia
Zero23
28-01-2009 15:53:52
Hmm
body.setCustomForceAndTorqueCallback(self.standardForceCallback, "")
What is this "" in your function call?
Can you show the function definition in phyton?
Regards,
Zero
PS: Nice
Danaugrs
28-01-2009 16:00:11
The definition is actually quite simple
def standardForceCallback(me):
mass, inertia = me.getMassMatrix() #This line does nothing right now.
print "callback"
When the function is called it only prints out "callback", so I can know when it is being called.
But it isn't being called.
The "" is a string with no chars. Apparently it is a required parameter that I don't know of.
If i take it out it gives me an error message.
Zero23
28-01-2009 16:04:59
Hmm the "" may should be the pointer to your class? In C++ I have to pass the pointer to the Class too.
Zero
Danaugrs
28-01-2009 16:19:23
You are right
If I didn't pass a pointer to my class as a parameter there is no way OgreNewt could find my function.
What has got me no errors is:
body.setCustomForceAndTorqueCallback(self, "forceCallback") #My function is now called "forceCallback"
But I'm still not getting callbacks
Is there a problem if the bodies are controlled by me? I mean, I have a body that is always at the mouse position -
at the intersection when my "camray" collides with a ground object. Then this body interlaces with other bodies already on the ground by my mouse movement,
not by the physics engine. Can this be a problem?
Danaugrs
Zero23
28-01-2009 16:21:39
Do you use to move the body, setbodyPositionOrientation?
Zero
Zero23
28-01-2009 16:37:34
Can you use the C++ version of OgreNewt with Phyton?
Then download the newest version, I posted them here in the forum!
and then after you call setbodyPositionOrienation call OgreNewt::World::CollisionUpdate().
Zero
Danaugrs
28-01-2009 17:28:27
The new version looks really cool!
But unfortunately I can't use it with python..
I'm gonna post this same problem on the Python-Ogre forum,
maybe they know something that is python particular..
If you find out what's wrong post it here
Thanks a lot Zero! (or is it Sven?
)
Danaugrs
Zero23
28-01-2009 17:35:34
Yes i know what is wrong
You place a body at a place, but you dont update the collision. So the callback cant be called. I hope you understand what I want to tell you
You have to use setForce and the other functions^^ Or you get the new OgreNewt to run and use the CollisionUpdate() function.
I hope you understand what I mean.
Regards,
Zero (No not Sven^^, Bastian!!)
Danaugrs
28-01-2009 17:42:51
I got it now =D
Python-ogre already comes with a binded version of OgreNewt for python
I can't build it from source (I don't know how
) so I can't use the new version.
I will see if the Python-ogre admin will include the new version of OgreNewt on the next update =D
Thanks Bastian
Cheers,
Danaugrs