Hi I am trying to implement OgreNewt in to my project but the physics doesn´t seem to be updating, the object never calls any callback functions.
My Init function for the physics object looks like this
Vector3 size = Ogre::Vector3( 10, 10, 10 );
m_pSceneNode = m_pSceneManager->getRootSceneNode()->createChildSceneNode();
m_pEntity = m_pSceneManager->createEntity("box_body", "box.mesh" );
m_pSceneNode->attachObject( m_pEntity );
m_pSceneNode->setScale( size );
m_pEntity->setNormaliseNormals(true);
OgreNewt::Collision *col = new OgreNewt::CollisionPrimitives::Box( g_pGame->GetPhysicsWorld(), size );
m_pBod = new OgreNewt::Body( g_pGame->GetPhysicsWorld(), col );
m_pBod->setAutoFreeze(0);
delete col;
m_pBod->attachToNode( m_pSceneNode );
m_pBod->setPositionOrientation( Ogre::Vector3(0,30,0),Ogre::Quaternion::IDENTITY );
m_Mass = 10.0;
Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( m_Mass, size );
m_pBod->setMassMatrix( m_Mass, inertia );
//m_pBod->setStandardForceCallback();
m_pBod->setCustomForceAndTorqueCallback(forceCallback);
I update the physics from my Game class with
m_pWorld->update(timeDelta);
I don´t know why it´s not working should I have something special in my Update function? I have both tried the StandardForceCallback that comes with ogrenewt and one self made both after they are set nothing happens.
alberts
19-10-2006 23:27:06
Maybe the problem is caused by the size of your world...
ProfesorX
20-10-2006 02:45:26
i had a similar problem, and the reason: i wasn't updating the physics correctly, i put the following code in FrameListener, and now it works

maybe this could help to give you an idea (taken from OgreNewt_BasicFrameListener.cpp):
First, in your FrameListener constructor:
desired_framerate = update_framerate;
m_update = (Ogre::Real)(1.0f / (Ogre::Real)desired_framerate);
m_elapsed = 0.0f;
Later, in your frameStarted method:
m_elapsed += evt.timeSinceLastFrame;
Ogre::LogManager::getSingleton().logMessage(" Newton Frame Listener... m_elapsed: "+Ogre::StringConverter::toString(m_elapsed)+
" m_update:"+Ogre::StringConverter::toString(m_update));
int count = 0;
if ((m_elapsed > m_update) && (m_elapsed < (1.0f)) )
{
while (m_elapsed > m_update)
{
m_World->update( m_update );
m_elapsed -= m_update;
count++;
}
}
else
{
if (m_elapsed < (m_update))
{
// not enough time has passed this loop, so ignore for now.
}
else
{
m_World->update( m_elapsed );
count++;
}
}
Ogre::LogManager::getSingleton().logMessage(" Newton updates this loop: "+Ogre::StringConverter::toString(count));
Hope this help you
Thanks for the help but that didn´t work either

It compiles and run but the box is just hanging there in the air without a care in the world...
ProfesorX
20-10-2006 17:21:26
It sounds to me that you are not aplying forces (gravity or other) correctly in the forceCallback function.
Can you post your forcecallBack function to see if it is some problem there?
Here is my custom callback
void forceCallback(OgreNewt::Body *me)
{
//apply a simple gravity force.
Ogre::Real mass;
Ogre::Vector3 inertia;
me->getMassMatrix(mass, inertia);
Ogre::Vector3 force(0,-9.8,0);
force *= mass;
me->addForce( force );
}
setting it like this
m_pBod->setCustomForceAndTorqueCallback(forceCallback);
but I also tried it with
m_pBod->setStandardForceCallback();
I have put a break point in both of them and it never gets there.
alberts
20-10-2006 23:03:53
Have you created the framelistener?
mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, mSceneMgr, mWorld, 60 );
mRoot->addFrameListener(mNewtonListener);
Yes I have both tried the BasicFrameListener and putting code in frameStarted. I get no response. I am going crazy here! Been trying around with this for so long now

. Does it matter that I have the world in my Game class that inherits from OgreApplication, I then create my objects in my MainScene. The objects gets renderd but nothing else happens. I dont use Example Application.
I have not yet got it to work. Are you supposed to get debug lines if you press F3, because I don´t ? If anyone would be willing to look at the code you can get it from here
http://rapidshare.com/files/605997/OgreBase_v0.2.rar
. Would really appreciate help, been looking at all the examples but I can´t see what I am doing wrong.
denreaper
26-10-2006 21:24:27
If you can't see anything upon F3 being pushed, and you are using the basicframelistener, odds are your basicframelistener isn't doing it's job. Could you show where you are initialising your basicframelistener at?
EDIT: I'll take a look at your code.
denreaper
26-10-2006 22:18:41
Okay, I couldn't compile against some of the things you have, but let me know if this does anything:
Add OgreNewt::BasicFrameListener *m_pNewtonListener; to OgreApplication.h in protected.
To OgreApplication.cpp in OgreApplication::CreateFrameListener():
m_pNewtonListener = new OgreNewt::BasicFrameListener( m_pRenderWindow, m_pSceneManager, m_pWorld );
whateveryourrootis->addFrameListener( m_pNewtonListener );
Comment this out unless you're using part of the code for something else:
m_Elapsed += evt.timeSinceLastFrame;
if ((m_Elapsed > m_Update) && (m_Elapsed < (1.0f)) )
{
while (m_Elapsed > m_Update)
{
m_pWorld->update( m_Update );
m_Elapsed -= m_Update;
}
}
else
{
if (m_Elapsed < (m_Update))
{
// not enough time has passed this loop, so ignore for now.
}
else
{
m_pWorld->update( m_Elapsed );
m_Elapsed = 0.0f;
}
}
See if you can see something when F3 is pushed now. If you can, then you are having the same problem I am. I'll make a new thread for my problem and if you are, I'll link you to it.
Thanks denreaper for looking at the code. I can´t initialize the BasicFrameListener in OgreApplication because I don´t create my SceneManager until my MainScene. But I took a look at your code in your topic and tried changing the code where I set inertia.
I was doing this and then setting inertia in the setMassMatrix
//Vector3 inertia = OgreNewt::MomentOfInertia::CalcSphereSolid( m_Mass, 10 );
But tried this instead
m_pBod->setMassMatrix( 10.0,OgreNewt::MomentOfInertia::CalcSphereSolid(10.0, 10.0 );
Now I get in to the Callbacks! But... I get some other error. But I´ll try to sort it out.
denreaper
27-10-2006 15:52:24
Sorry, I guess I didn't take enough time with your code. Anyway, glad to hear you got it working. About it acting the way it is now, is inertia initialised after you set the mass matrix of the body?
No that seems to be the problem at the moment it says "Stack around the variable inertia was corrupted" doesn´t know why or what to do about it, never seen a error like that before.
denreaper
28-10-2006 07:36:53
Neither have I... Did a debug tell you anything?
no don´t know what it could be. The inertia gets a value so it´s not Null.
if I comment out
//me->getMassMatrix(mass, inertia);
in my callback function the physcis seems to work but it gets updated way to fast. I just see the object flashing by. The inertia value isn´t used in the callback function do I still need to use the getMassMatrix function to get it to work correctly?