maxwave
21-04-2006 15:07:58
Please tell me, how to create several compound objects and calculate parameters for it(inertia,volume,offset).
I understand, how to work with single objects, but with compound...I don't now. How to aatach several nodes for compound objects?
I've got something that is maybe close to what you're looking for. The compound collision shape gets built correctly, but I don't yet know have to calculate the correect moment of inertia.
cPhysicsWorld, cIsland and several other things are my classes, so don't worry about those.
My "islands" are made up of a bunch of convex hulls, and the individual collisions for those are also created in this code, and then added to a std::vector which is then passed into OgreNewt::CollisionPrimitives::CompoundCollision.
Hope it makes sense! I just copied directly from my code but I can probably give more info if you need it.
Good luck...
OgreNewt::Body* cPhysicsWorld::createIslandBody(cIsland* pIsland)
{
// build the compound collision object
// first make a temporary array of all the hex collisions, including offsets
std::vector<OgreNewt::Collision*> collArray;
int numHexes = 0;
for(HEX_LIST_ITERATOR hexIter = pIsland->getHexListBegin(); hexIter != pIsland->getHexListEnd(); hexIter++)
{
const Ogre::Vector3& pos = (*hexIter)->getSceneNode()->getPosition();
const Ogre::Quaternion& orient = (*hexIter)->getSceneNode()->getOrientation();
OgreNewt::Collision* pHexColl = createConvexHull(cHexManager::kPlainHexMeshName, pos, orient);
collArray.push_back(pHexColl);
// count up hexes in order to determine total mass
numHexes++;
}
// create the compound collision
OgreNewt::Collision* pCompoundColl = new OgreNewt::CollisionPrimitives::CompoundCollision(mpWorld, collArray);
// create the body
OgreNewt::Body* pBody = new OgreNewt::Body( mpWorld, pCompoundColl );
delete pCompoundColl; // ref counted, so don't need this one anymore
// compute moment of inertia
//ASSERT(!"wrong - how to calc properly?");
#pragma message ("WRONG - need to calc using http://www.newtondynamics.com/forum/viewtopic.php?t=1199")
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid( cHexManager::kfHexMass,
cHexManager::kfHexRadius,
cHexManager::kfHexDepth);
// set mass and inertia matrix
float fTotalIslandMass = cHexManager::kfHexMass * numHexes;
pBody->setMassMatrix(fTotalIslandMass, inertia );
// set the standard force callback (as well as buoyancy below?)
pBody->setStandardForceCallback();
// set the buoyancy callback
pBody->setCustomForceAndTorqueCallback( fastdelegate::MakeDelegate( this, &cPhysicsWorld::standardForceCallback) );
// return pointer to the body
return pBody;
}