change the colour of a body that is sleeping

Artic_Ice83

23-02-2008 15:08:51

Hi! i want to change the colour of a body when it sleeps, but if i try this code it doesn't change the colour...



NxOgre::Body *cube, *sphere;

cube = mScene->createBody("cube;cube.1m.mesh", new CubeShape(1,1,1,"material: defaultMaterial"), Vector3(1.0f,5.0f,1.0f), "mass: 5");

sphere = mScene->createBody("sphere;sphere.50cm.mesh",new NxOgre::SphereShape(0.5,"material: defaultMaterial"),Vector3(4.0f,0.0f,1.0f), "mass: 5");

cube->setSleepLinearVelocity(0.15*0.15);
cube->setSleepAngularVelocity(0.14*0.14);

/*CREATE THE SLEEPING MATERIAL*/

Ogre::MaterialPtr mp = Ogre::MaterialManager::getSingleton().create("sleep",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

Ogre::Pass *p = mp->getTechnique(0)->getPass(0);
p->setAmbient(ColourValue(0.8,0.4,0.5));
p->setDiffuse(ColourValue(0.4,0.5,0.6));
p->setLightingEnabled(true);
p->setCullingMode(Ogre::CULL_CLOCKWISE);

mp->load();

if(cube->isSleeping())
{
Entity *ent = cube->getEntity();
ent->setMaterialName("sleep");

}



what is wrong?

betajaen

23-02-2008 18:18:12

You need to wait for the Actor to fall asleep, simply creating it, then checking if it's asleep won't do it; it'll be awake. Try checking in the next frame or there after.

Artic_Ice83

23-02-2008 19:18:34

so, if i want to ceck it, in the cake can i do this in the onFrame method?

betajaen

23-02-2008 19:23:20

Yeah, or any function that is run once a frame.

Artic_Ice83

23-02-2008 20:02:18

Wow! now goes perfectly!!!thanks a lot...i know that this was a very very noob question... :oops: