Piet
31-01-2008 13:28:50
Could someone explain the application of density in OgreOde to me?
I'm making two entities, each with a body and geometry. I want them to bounce off against each other when they touch. I'm using a boxgeometry. Gravity is already working on the objects.
I was surprised that you are to set volume (or size), mass, AND density. Physically, if I set two, I should be unable to choose what the third is (rho = m/V).
How do these relate to one another in OgreOde?
Additional question: how do I set the center point of gravity?
Now for the concrete example.
This is the constructor for one of my objects:
I'm making two entities, each with a body and geometry. I want them to bounce off against each other when they touch. I'm using a boxgeometry. Gravity is already working on the objects.
I was surprised that you are to set volume (or size), mass, AND density. Physically, if I set two, I should be unable to choose what the third is (rho = m/V).
How do these relate to one another in OgreOde?
Additional question: how do I set the center point of gravity?
Now for the concrete example.
This is the constructor for one of my objects:
// Create the Ogre object
mNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
mEntity = mSceneManager->createEntity( UniqueName::get(), "OgreHead.mesh" );
mNode->attachObject( mEntity );
// Set start position from constructor argument
mNode->setPosition( aStartPos );
// Create a body
mBody = new OgreOde::Body( CollisionManager::getSingleton()->getWorld() );
// Create mass
// The density of 0.01 somehow seems to grant the result I want, but I have no idea what's going on
OgreOde::BoxMass mass( 1.0, mEntity->getBoundingBox().getSize() );
mass.setDensity( 0.01, mEntity->getBoundingBox().getSize() );
// Create geometry (same size as mEntity)
mGeom = (OgreOde::Geometry*)new OgreOde::BoxGeometry( mEntity->getBoundingBox().getSize(), CollisionManager::getSingleton()->getWorld(), CollisionManager::getSingleton()->getSpace() );
// Set scale
// Why would we set the scale?
// I've seen the "0.1*size" in the wiki tutorial, which came down setting the scale to Vector3(1,1,1). It already is.
// Connect everything
mBody->setMass( mass ); //Apply mass to mBody
mNode->attachObject( mBody ); //Attach mBody to mNode
mGeom->setBody( mBody ); //mGeom acts in conjunction with mBody
mEntity->setUserObject( mGeom ); //Do I need this? What for?