[SOLVED] Hit response / Falling down

spacegaier

07-03-2008 16:06:38

If I let fall a sphere (or another object) down on a static body it isn't jumping back (or respoding in anyway). It is just lying there. What to do?

As I said I created this static object (a plane). The spheres I let falling down hit the plane (don't respond, except they don't fall deeper) and move on into the depth. Shouldn't they fall down after they left the plane?

Aiursrage2k

07-03-2008 21:26:11

It depends what you want it to do.

If you want the actor to really bounce. gives it shape a material, set that materials restitution to 1 and restitutionCombineMode to NX_CM_MAX

spacegaier

07-03-2008 21:34:25

Could you give my a short code example, please? I'm not finding the needed functions :(

EDIT: Got it. Found this snippet here:

NxOgre::MaterialList* list = m_pNxScene->getMaterials();
NxOgre::Material* mat = list->begin();
while(!list->_atEnd())
{
mat = list->next();
mat->setDynamicFriction(50.f);
mat->setDynamicFrictionV(50.f);
mat->setStaticFriction(50.f);
mat->setStaticFrictionV(50.f);
mat->setRestitution(0.5f);
}

betajaen

07-03-2008 22:02:00

Create the material using mScene->createMaterial(...), then create the Actor/Body with this added to the shape params "material: materialname".

spacegaier

07-03-2008 22:28:00

But this kind of material has nothing to do with the color and the others things specified by the Ogre::Material, right?

To change this I'll need a second material (one of Ogre)?

betajaen

07-03-2008 22:55:24

No, NxOgre deals only with the physics. Such things are left to Ogre as always.

But you shouldn't use that code snippet there. It's icky, and there are better ways to assign materials to Shapes.

spacegaier

07-03-2008 23:09:13

Is this the right way?

static int i = 0;
Ogre::String name = "mat"+Ogre::StringConverter::toString(i);
NxOgre::Material* mat = m_pNxScene->createMaterial(name);
mat->setDynamicFriction(50.f);
mat->setDynamicFrictionV(50.f);
mat->setStaticFriction(50.f);
mat->setStaticFrictionV(50.f);
mat->setRestitution(0.5f);

NxOgre::Body * b;
NxOgre::SphereShape * s = new NxOgre::SphereShape(1);
b = m_pNxScene->createBody("sphere.2m.mesh", s, m_pCamera->getPosition(), "mass: 20, material: name");

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

Ogre::Pass *p = mp->getTechnique(0)->getPass(0);
p->setAmbient( ColourValue( sin( (double)m_pTimer->getMicrosecondsCPU() + 0.7 ), sin( (double)m_pTimer->getMicrosecondsCPU() + 0.5 ), sin( (double)m_pTimer->getMicrosecondsCPU() + 0.3 ) ) );
p->setDiffuse( ColourValue( sin( (double)m_pTimer->getMicrosecondsCPU() + 0.7 ), sin( (double)m_pTimer->getMicrosecondsCPU() + 0.5 ), sin( (double)m_pTimer->getMicrosecondsCPU() + 0.3 ) ) );
p->setLightingEnabled(true);
p->setCullingMode(Ogre::CULL_CLOCKWISE);
mp->load();

b->getEntity()->setMaterialName(name);

b->addForce(m_pCamera->getDirection()*550,NxForceMode::NX_IMPULSE);

i++;

betajaen

08-03-2008 00:27:03

Or you could do this:

mScene->createMaterial("Material1")->setAll(0.5f, 1.0f, 1.0f);
mScene->createBody("mySphere;sphere.2m.mesh", new SphereShape(1.0f, "material: Material1"), mCamera->getPosition(), "mass: 20");



Not everything has to be dragged out you know.

Artic_Ice83

08-03-2008 22:30:37



b = m_pNxScene->createBody("sphere.2m.mesh", s, m_pCamera->getPosition(), "mass: 20, material: name");



the material must be passed to the shape blueprint like shape param.
the code that betajaen wrote is the correct one.