setPositionOrientation and collision detection

hustzion

16-06-2010 13:39:47

Hi all lovely coders,
In OgreNewt,
Once using the member function setPositionOrientation() of class Body,the collision detection doesn't work.
Any one know the reason?And how to solve it?
(I think I don't need to post the simple code?)
Hope someone will share.
Thanks sincerely!

SFCBias

16-06-2010 17:10:50

You just about always need code :) . But it kind of sounds like your using that function to move the bodies? If so, this function is only to be used to set the initial state of the collision object i.e. If you want an object to spawn in the air side ways or oriented in another way other than right-side-up.

so if your calling this function more then once for each body , this may be your problem

kallaspriit

16-06-2010 18:12:01

Indeed, you cant just set position or NGD wont know how to handle the collisions, you've got to use forces to move your object or IK joint.

hustzion

17-06-2010 02:48:11


so if your calling this function more then once for each body , this may be your problem



exactly what I am facing to!

hustzion

17-06-2010 02:50:27

Indeed, you cant just set position or NGD wont know how to handle the collisions, you've got to use forces to move your object or IK joint.
So now we know it doesn't work,what's the reason?
no way to solve the problem?

SFCBias

17-06-2010 05:26:09

You need to do one of these two things for all bodies.

1. call setStandardForceCallback();

2. Create a class with a member function to handle the addition of force to each of your bodies ( this is convenient so if you want to change gravity force or direction even)

Example: Here we have a class called "MyClass" with a member function called "forceCallback". Note the parameters for this function.
The fourth line is really the only one that should be changed at all, it is the gravity. Here we have it set to -98.0665 in the Y direction. This means that every body will move 98.0665 units downward (negative Y) every update. You can change this to whatever you like but be sure to stay consistent with your units of measurement.
void MyClass::forceCallback(Body* me, Real timestep,
int threadIndex)
{
//apply a simple gravity force.
Ogre::Real mass;
Ogre::Vector3 inertia;

me->getMassMatrix(mass, inertia);
Ogre::Vector3 force(0, -98.0665, 0);
force *= mass;

me->addForce(force);
}


Then at the creation of your bodies Call setCustomForceAndTorqueCallback with the class containing the callback inside of the "< >". Then a reference to the location of the actual function. Then an initilized pointer a class of type MyClass.

Here MyClass is the class name, and myclass is the initialized pointer to and object of MyClass. (Its alot of MyClasses but its less confusing than it seems)



void createBody()
{
OgreNewt::CollisionPtr m_col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::Box(mWorld));
OgreNewt::Body* bod = new OgreNewt::Body(mWorld,m_col);
/* The important stuff */
bod->setCustomForceAndTorqueCallback<MyClass>(&MyClass::forceCallback,myclass);
/* Other parameters ... */
}

hustzion

17-06-2010 13:13:27

SFCBias,
Thanks to your reply.
However I think I didn't describe my question clearly. :wink:
I mean,I want the collision body can be anywhere anytime immediately.
It seems that no function can replace setPositionOrientation()??

SFCBias

17-06-2010 16:03:17

Ok if thats the case then try translating the actual sceneNode using setPosition,translate, or one of those functions.

hustzion

20-06-2010 09:48:32

Ok if thats the case then try translating the actual sceneNode using setPosition,translate, or one of those functions.
I tried this method before I come here.
Let's forget it!That's a big big bug in OgreNewt(and Newton)!
I even create a new thread,finally failed to solved it.

kallaspriit

21-06-2010 17:04:43

It's not a bug, it's the way a physics engine works and I doubt any physics library does it differently. NGD needs moving bodies for accurate collision detection and joint (including contact-joints) solving. If you just position a body anywhere, it does not have velocity or momentum and you cant expect the physics library to make any intelligent decisions..

Check out OgreNewt::KinematicController, it has methods like:
//! set the position part of the attachment matrix
/*!
\param position new destination position in global space
*/
void setTargetPosit (const Ogre::Vector3& position);

//! set the orientation part of the attachment matrix
/*!
\param rotation new destination position in global space
*/
void setTargetRotation (const Ogre::Quaternion& rotation);

//! set the position and orientation part of the attachment matrix
/*!
\param position new destination position in global space
\param rotation new destination position in global space
*/
void setTargetMatrix (const Ogre::Vector3& position, const Ogre::Quaternion& rotation);

SFCBias

22-06-2010 13:05:59

Agree, you shouldn't be so quick to give up when so many other people have already done what you wish to achieve, you just must be patient ;)