run newton

ghiboz

02-05-2007 22:53:59

hi!
i'm trying to drop a ball, but nothing....
here is my code:
in createScene:
Entity* floor = mSceneMgr->createEntity("Floor", "Plane01.mesh" );
SceneNode* floornode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "FloorNode" );
floornode->attachObject( floor );
floor->setMaterialName( "Simple/dirt01" );



OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floornode, false );
OgreNewt::Body* bod = new OgreNewt::Body( m_World, col );
delete col;

bod->attachToNode( floornode );
bod->setPositionOrientation( Ogre::Vector3(0.0,0.0,0.0), Ogre::Quaternion::IDENTITY );


and after:
Entity* entTest = mSceneMgr->createEntity( "Test", "sphere.mesh" );
SceneNode* nodeTest = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Test" );
entTest->setMaterialName( "Simple/BumpyMetal" );
nodeTest->attachObject( entTest );
nodeTest->setScale( Vector3(0.05, 0.05, 0.05) );
nodeTest->setPosition( Vector3(0.0, 25.0, 0.0));


after, in the framelistener:
bool TestFrameListener::frameStarted(const FrameEvent &evt)
{
OgreNewt::Collision* colTest = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) );
OgreNewt::Body* bodyTest = new OgreNewt::Body( m_World, colTest );

Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcSphereSolid( 10.0, 1.0 );
bodyTest->setMassMatrix( 10.0, inertia );
bodyTest->attachToNode( msnCam );
bodyTest->setStandardForceCallback();
bodyTest->setVelocity( Ogre::Vector3(0,0,0) );
return true;
}


i inserted the breakpoint in the framelistener and the program go on, but the spere stay on fly and doesn't go down for gravity...
what's the error??

thanks

Drakon

02-05-2007 23:33:07

Well.. the tutorials that are provided with OgreNewt will help a lot you with your problem if you just look at them ;)

Why are you doing:

after, in the framelistener:
bool TestFrameListener::frameStarted(const FrameEvent &evt)
{
OgreNewt::Collision* colTest = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,1,1) );
OgreNewt::Body* bodyTest = new OgreNewt::Body( m_World, colTest );

Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcSphereSolid( 10.0, 1.0 );
bodyTest->setMassMatrix( 10.0, inertia );
bodyTest->attachToNode( msnCam );
bodyTest->setStandardForceCallback();
bodyTest->setVelocity( Ogre::Vector3(0,0,0) );
return true;
}



If you want only one ball you can add it right after your terrain in CreateScene function;)

walaber

02-05-2007 23:34:13

the code in the FrameListener::frameStarted() function gets called EVERY frame. you are creating a new ball every frame. move that code into the createScene() function, and in frameStarted() add

mWorld->update( evt.timeSinceLastFrame );


that should be right, but I typed it off the top of my head so I might have miss-typed something.