Density, mass, volume

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:


// 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?

rewb0rn

01-02-2008 00:57:07

Could it be that the first parameter in the mass constructor is the same that you set by calling setDensity()? Personally I never use this function. The center of gravity can not be changed in ode, at least that was case when I read the manual about a year ago, but maybe things have changed (and the manual was already outdated then). For both questions the ode mailing list would be a good place to ask. Subscribe at ode.org.

Piet

01-02-2008 10:36:26

Thanks rewb0rn.

In the tutorial (http://www.ogre3d.org/wiki/index.php/First_steps_with_OgreODE) and many examples I find, this is what's done:


OgreOde::BoxMass mMass(0.5,size);
mMass.setDensity(5.0,size);
mGeom = (OgreOde::Geometry*)new OgreOde::BoxGeometry(size, mWorld, mSpace);
mNode->setScale(size.x * 0.1,size.y * 0.1,size.z * 0.1);


Mass divided by density equals the multiplier used in setScale.
SetScale() parameters result in 1,1,1.
I have no idea what setDensity() actually accomplishes, but it seems to have a certain influence on the physics.

What happens for you when you do not call setDensity()?

rewb0rn

01-02-2008 11:39:19

I can not tell if there is a difference to calling it, but physics work well for me. The setScale() seems to have no effect, so maybe setDensity() with same parameters like mass has neither. In fact, some parts of OgreOde seem to be redundant or not too well tested sometimes. If you are interested have a look at the OgreOde code and from there you may want to dive into the ode code.

kalda

01-02-2008 21:17:39

Maybe I know the problem...
From physics: density = mass/volume => volume=mass/density

That's way I think at the beginning is volume readed from the geometry size, but when you set the density, ode automatically recalculate the volume(size)... Maybe this is why the objects go trought another.

I think the best way is leave density alone.

Piet

02-02-2008 18:05:03

I'll give that a shot.

I stumbled on another problem now:
The Ogre RaySceneQuery gives me an entity's bounding box, and not the actual location where a polygon was hit!
Is there a way to change this?

I may make a new post on this one later.

rewb0rn

03-02-2008 15:28:03

Use OgreOde::RayGeometry instead.

Piet

03-02-2008 22:06:47

Thank you, rewb0rn!

Does it find plain Ogre entities, or do I need to convert those in any way?

rewb0rn

03-02-2008 23:18:43

Yea sure it is only able to interact with other OgreOde geometries, and it will not return the polygon but the position of the intersection. If thats not what you need, have a look at the ogre wiki, I believe there was a code snippet how to do a ray query on polygon level in Ogre, but I would prefer to use the physics engine.