[SOLVED ] EnergySleepTest doesn't work!

People3d

06-05-2010 10:11:05

hi all, i'm little new about NxOgre..
i have a problem to put an object to spleep whit the Sleep energy Test..
my config is:
Ogre 1.7
Physx SDK 2.8.1
OpenAL 1.1 ver3.03 [threaded version]
BloodyMess 1.5.5

this is the constructor of my PhysxManager

PhysxManager::PhysxManager()
{
//DZ create Physx world
mWorld = NxOgre::World::createWorld();
//DZ init Physx Scene
NxOgre::SceneDescription sceneDesc;
sceneDesc.mGravity = NxOgre::Vec3(0, -9.8f, 0);
sceneDesc.mName = "IGELC_Scene";
//DZ create Physx Scene
mScene = mWorld->createScene(sceneDesc);
//DZ set param
mScene->getMaterial(0)->setStaticFriction(0.5);
mScene->getMaterial(0)->setDynamicFriction(0.5);
mScene->getMaterial(0)->setRestitution(0.1f);

//DZ set rendersystem mode
mRenderSystem = new OGRE3DRenderSystem(mScene);
//DZ intitialize time controller
mTimeController = NxOgre::TimeController::getSingleton();
//mScene->createSceneGeometry(new NxOgre::PlaneGeometry(0, NxOgre::Vec3(0, 1, 0)), Matrix44_Identity);
mCube = 0;
}




this is the function who crate a simple terrain whit height = 0

void PhysxManager::bringTerrain()
{
//var
int size = 100;//numero di vertici per lato (quadrato)
int minHeight = -60;
int maxHeight = 50;
int worldSize = 100; //unità mondo per lato a.k.a. lato lungo 100 mt.
Ogre::Vector3 position(0,0,0);
Ogre::String name = "myheightfield";

// Create the manual heightfield
NxOgre::ManualHeightField *mhf = OGRE_NEW_T(NxOgre::ManualHeightField, Ogre::MEMCATEGORY_GENERAL)();
mhf->begin(size, size);
Ogre::Real normMin = -32768.0f;
Ogre::Real normMax = 32767.0f;

// Sample the data to the manual heightfield
for(int x = 0; x < size; ++x)
{
NxOgre::Enums::HeightFieldTesselation tess = NxOgre::Enums::HeightFieldTesselation_NW_SE;
for(int z = size-1; z >= 0; --z)
{
Ogre::Real height = 0;
//((50-49)/(51-49))*(32767-(-32768)) + (-32768) = 0.5*65535 - 32768 = -0.5
short sample = (short)(((height - minHeight) / (maxHeight - minHeight)) * (normMax - normMin) + normMin);
mhf->sample(sample, 0, 0, tess);
if(tess == NxOgre::Enums::HeightFieldTesselation_NE_SW)
tess = NxOgre::Enums::HeightFieldTesselation_NW_SE;
else
tess = NxOgre::Enums::HeightFieldTesselation_NE_SW;
}
}

// Create the actual heightfield
NxOgre::HeightField *hf = mhf->end(name.c_str());
Ogre::Real hf_size = worldSize + (worldSize / size);
Ogre::Real hf_height = (maxHeight - minHeight) / 2.0f;
Ogre::Real hf_pose_x = position.x - (worldSize / 2.0f);
Ogre::Real hf_pose_y = position.y + ((maxHeight + minHeight) / 2.0f);
Ogre::Real hf_pose_z = position.z - (worldSize / 2.0f);

//curr version 1.5.4
#if NxOgreVersionMajor <= 1 && NxOgreVersionMinor <= 5
NxOgre::HeightFieldGeometry* hfg = new NxOgre::HeightFieldGeometry(hf, NxOgre::Vec3(hf_size, hf_height, hf_size));
hfg->setLocalPose(NxOgre::Matrix44(NxOgre::Vec3(hf_pose_x, hf_pose_y, hf_pose_z)));
mScene->createSceneGeometry(hfg);
#else
NxOgre::HeightFieldGeometryDescription desc(hf, NxOgre::Vec3(hf_size, hf_height, hf_size));
mScene->createSceneGeometry(desc, NxOgre::Matrix44(NxOgre::Vec3(hf_pose_x, hf_pose_y, hf_pose_z)));
#endif
// Free memory
OGRE_DELETE_T(mhf, ManualHeightField, Ogre::MEMCATEGORY_GENERAL);
}


and this is the code to create a cube..

void PhysxManager::createObject(NxOgre::Box *p_box, NxOgre::Vec3 p_pos, Ogre::String p_mesh, NxOgre::Vec3 p_force, Ogre::Vector3 p_scale, NxOgre::Real p_mass)
{
NxOgre::RigidBodyDescription t_desc = NxOgre::RigidBodyDescription();
t_desc.mBodyFlags |= NxOgre::Enums::BodyFlags_EnergySleepTest; //enable EnergySleepTest

t_desc.mSleepEnergyThreshold = NxOgre::Real(0.5); //set EnergySleepTest thresold

mCube = mRenderSystem->createBody(p_box, p_pos, p_mesh,t_desc); //create body

mCube->addForce(p_force);
mCube->getSceneNode()->setScale(p_scale);
mCube->setMass(p_mass);

mCube->getEntity()->setMaterialName("GameObject/Mgobbo");

}


and this is the function called by the frame listener to advance the time..

void PhysxManager::update(Ogre::Real p_timeSinceLastFrame)
{

mTimeController->advance(p_timeSinceLastFrame);

}


my simple cube falling down, and hit the ground correctly..but he doesn't stop to tremble and moving...

i check the KineticsEnergy by the method ComputeKineticsEnergy and i saw a value around 0.0002, i set the mSleepEnergyThreshold to 0.5 but isn't seems to works...the cube continue to tremble..!
any idea??

People3d

09-05-2010 18:48:30

we need to activte energysleeptest and set the mSkinWidth

//create Bleprint and set the mSkinWidth factor
NxOgre::ShapeBlueprint *sbp = new NxOgre::ShapeBlueprint();
sbp->mSkinWidth = 0.01;
//create shape using the shapeBlueprint
NxOgre::Box *t_shape = new NxOgre::Box(p_x, p_y, p_z, sbp);
//set RigidBody Desc
NxOgre::RigidBodyDescription t_desc = NxOgre::RigidBodyDescription();
t_desc.mBodyFlags |= NxOgre::Enums::BodyFlags_EnergySleepTest;