StillmatikX
05-04-2008 21:14:19
Hey guys,
I have recently applied physics to the prototype of this game that I am working on but I am experiencing a problem where the objects will not interact in the world correctly. More specifically, I created a couple of objects which should just fall from a random height to the ground. I'm pretty sure I've setup all aspects of the world correctly such as adding collisions, bodies, and forcecallbacks to all of the enitities. However, the objects are created initially but they never fall to the ground. This is the case when the dimensions of the planes defining my cube world are pretty big such as 1000. When I set the dimensions to 100, though, the objects fall (However, other problems are encountered due to the small size). Here is a snippet of my code demonstrating my setup for the falling objects:
.....and a snippet of the setup for one of the planes of my world:
Does the world need to be setup/configured a certain way in order to ensure that objects of any size but sensible sizes interact correctly in the world? As of right now, all I'm doing for the world is:
....and then of course creating planes to represent its boundaries and so on....
I have recently applied physics to the prototype of this game that I am working on but I am experiencing a problem where the objects will not interact in the world correctly. More specifically, I created a couple of objects which should just fall from a random height to the ground. I'm pretty sure I've setup all aspects of the world correctly such as adding collisions, bodies, and forcecallbacks to all of the enitities. However, the objects are created initially but they never fall to the ground. This is the case when the dimensions of the planes defining my cube world are pretty big such as 1000. When I set the dimensions to 100, though, the objects fall (However, other problems are encountered due to the small size). Here is a snippet of my code demonstrating my setup for the falling objects:
Entity* dodgeball;
Entity* obstacle;
SceneNode* node;
OgreNewt::Body* bod;
Ogre::Real mass;
Ogre::Vector3 inertia;
size = Ogre::Vector3( 6.0, 3.0, 6.0 );
for(int count = 0; count < 20; count++)
{
node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
obstacle = mSceneMgr->createEntity("obstacle"+Ogre::StringConverter::toString( count ), "box.mesh" );
node->attachObject( obstacle );
obstacle->setMaterialName("Examples/Chrome");
node->setScale( size );
// rigid body.
col = new OgreNewt::CollisionPrimitives::Box( mWorld, size );
bod = new OgreNewt::Body( mWorld, col );
bod->attachToNode( node );
// initial position
bod->setPositionOrientation( Ogre::Vector3(Math::RangeRandom(-dim/2,dim/2),Math::RangeRandom(5,45),Math::RangeRandom(-45,45)),
Ogre::Quaternion::IDENTITY );
delete col;
mass = 10;
inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( mass, size );
bod->setMassMatrix( mass, inertia );
bod->setStandardForceCallback();
}
.....and a snippet of the setup for one of the planes of my world:
Ogre::Real dim = 100.0;
Entity* floor;
SceneNode* floorNode;
floor = mSceneMgr->createEntity("Floor", "box.mesh");
floor->setNormaliseNormals(true);
floorNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Floor_Node" );
floorNode->attachObject( floor );
floorNode->setPosition(Vector3(0.0,0.0,0.0));
floor->setMaterialName( "Examples/WoodFloor" );
floor->setCastShadows( false );
Ogre::Vector3 size(dim,.1,dim);
floorNode->setScale( size );
OgreNewt::Collision* col;
col = new OgreNewt::CollisionPrimitives::Box( mWorld, size );
OgreNewt::Body* floorBody = new OgreNewt::Body( mWorld, col );
floorBody->attachToNode( floorNode );
floorBody->setPositionOrientation( Ogre::Vector3(0.0,0.0,0.0), Ogre::Quaternion::IDENTITY );
delete col;
Does the world need to be setup/configured a certain way in order to ensure that objects of any size but sensible sizes interact correctly in the world? As of right now, all I'm doing for the world is:
mWorld = new OgreNewt::World();
....and then of course creating planes to represent its boundaries and so on....