Hello,
Iam trying to use Newton with Ogre to make a small game. I just want to use Newton for his collision system. I have implemented the listener and add a world objet into my code, my 3D objects are declared in it. It should work, no compilation error etc .. But i don't know how (surely in the framelistener) to add event in case of collision or where i should had my methods. Didn't see in the doc where to proceed.
Regards,
Jérémy
Tks for the link it has helped.
I still have a problem, my collision don't seems to work :
My two 3D objects are declared like this:
mEnt = mSceneMgr->createEntity( mName, mMesh );
mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(mNameNode);
mNode->attachObject( mEnt );
mNode->setPosition(startPosition);
mNode->setOrientation(startOrient);
mNewtShip->setPositionOrientation( startPosition, startOrient );
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box( mWorld, scale );
mNewtShip = new OgreNewt::Body( mWorld, col );
mNewtMatID = new OgreNewt::MaterialID( mWorld );
mNewtShip->setMaterialGroupID( mNewtMatID );
mNewtShip->attachToNode(mNode);
//Declaration of collision:
mMatPairDefault = new OgreNewt::MaterialPair( getWorld(),mMainShip->getMaterialID() , mEnemyShip->getMaterialID() );
mCollisionCallback = new CollisionCallback();
mMatPairDefault->setContactCallback( mCollisionCallback );
//My collision callback function:
class CollisionCallback : public OgreNewt::ContactCallback
{
public:
CollisionCallback(void) {};
~CollisionCallback(void){};
int userBegin()
{
Ogre::LogManager::getSingleton().logMessage("userBegin() -> Collision!");
return 1;
}
int userProcess()
{
//OgreNewt::ContactCallback::
Ogre::LogManager::getSingleton().logMessage("userProcess() -> Collision!");
return 1;
};
};
I don't know exactly what method is called when a collision begin but it must be one of thoses .. if someone have a idea to help me or see a missing declaration line for newt objects .
For information, i have debugged my prog to be sure that it is not a error of empty pointer or something else and the property of my bodies seems good as far as i know.
The result of this programs: ships are moving and when they colide nothing in my logs.
Regards,
Jérémy
how r the to bodies making contact?
r u pushing they with forces? or with setPositionAndOrientation ?
cause the collision will work only if the impact was provoqued by a force application.
to do that, u'll need to setup a customForceAndTorqueCallback.
have u done that?
My bodies are entering in contact when i translate my nodes, i thought Newton could track the move .. (i checked the value in debug, seems to track the objects).
I did one setPositionAndOrientation at the init of my object.
So i have to create a force on my object instead of making a object translation ? I was just planning on using only the collision detection from Newt because i don't really need to use force .. but why not if it is the only way.
So i have to setup a customForceAndTorqueCallback and to apply a dynamic force to my object what method can i use ?
Thanks a lot for your quick answer btw.
Jérémy
Acid_Gambit
24-04-2007 12:54:38
The idea behind physics is that you apply forces just like in the real world when you want to "move" an object. You can simply use setForce on an OgreNewt body to "push" it in the right direction.
Game_Ender
24-04-2007 13:51:16
If you just want collision detection, using something like OgreOpCode which is truly just collision detection.
now that i have installed Newt, lets try to understand the logics of physics.
If i understand i have to create a forceCallback object but i don't see how it will work with my pressed key.
Example, i presse Z to advance : before i was doing a simple translate() now, obviously i can't only do a simple setForce().
I don't quite understand why i have to put my control into a callback method.. if someone has time for some noob questions ^^
Jérémy
Hello,
I have worked for the last pasted days on the use of forces on my ship.
I have set my objects like this
Ogre::Real mass = 10.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( mass, scale );
mNewtShip->setMassMatrix( mass, inertia);
i have add this line to test Newt :
mNewtShip->setStandardForceCallback();
It is working, my ship is going down. So i add a custom force function like this:
if( mKeyboard->isKeyDown( KC_E ) )
{
mGameManager->mMainShip->mNewtShip->setCustomForceAndTorqueCallback( boost::bind( &Lost_PilotFrameListener::forceBodyCallback, this, _1 ) );
KeyDwn=1;
}
void forceBodyCallback (OgreNewt::Body* me)
{
Ogre::LogManager::getSingleton().logMessage("ForceCallback()");
Vector3 spd(10,0,0);
};
It is working, the force method is called. My problem is that when i remove the standard callback force method my custom method is no longer called.
How thoses 2 methods are linked ?
Regards,
Jérémy
JackyE
29-04-2007 23:04:37
I don't think you can apply 2 forceCallbacks. Just simulate the standardCallback + you own functions. Add to your customForceFunction (forceBodyCallback in your case):
Vector3 gravity(0, -9.8, 0);
m_pBody->addForce(gravity);
Ogre::LogManager::getSingleton().logMessage("ForceCallback()");
Vector3 spd(10,0,0);
PS: Set the custom force callback permanently. You will only make it difficult if you start switching between the standard, and your custom force function.