Collisions

kalda

29-01-2008 18:03:38

Hello!

I have small problem... I've code looks like simple scenes demo, but my Objects are falling trough the floor and trough other objects. Collision is detected in callback. I return true, but without change... Only Vehicle and ragdoll created by OgreOde loader are working...

Here is my code fe. for cube:


bool CPhysBox::Init(IModel *target,float mass,float density,float sizeX,float sizeY,float sizeZ,bool useGravity,World *world,Space *space)
{
if(!world || !space) return false;

CModel *model = (CModel*)target;
if(!model) return false;

Entity *entity = model->GetEntity();
if(!entity) return false;

m_body = new Body(world);
if(!m_body) return false;
model->AttachObject(m_body);

BoxMass Mass(mass,Vector3(sizeX,sizeY,sizeZ));
Mass.setDensity(density, Vector3(sizeX,sizeY,sizeZ));

m_geometry = (Geometry*)new BoxGeometry(Vector3(sizeX,sizeY,sizeZ),world,space);
if(!m_geometry) return false;

m_body->setMass(Mass);

m_geometry->setBody(m_body);
entity->setUserObject(m_geometry);

m_body->setAffectedByGravity(useGravity);

return true;
}

rewb0rn

29-01-2008 19:01:27

Attach the geometry to the scenenode, not to the entity.

by the way:

m_body = new Body(world);
if(!m_body) return false;

m_body will never be 0, instead an exception will be thrown when new fails.

kalda

29-01-2008 19:52:32

It isn't possible!

1) To SceneNode is attached body and to entity is attached geometry... (in demos too)

2) To scenenode can be attached only moveableobject but geometry is userdefinedobject

rewb0rn

29-01-2008 20:25:23

sry my bad, but at least i only do this:

Geometry->setBody(Body);
Node->attachObject(Body);

kalda

29-01-2008 21:18:36

I have this done...
Still the same...


But as I said, collision is detected but no response... in callback i'm returning true...


bool CPhysics::collision(OgreOde::Contact* contact)
{
Geometry * const g1 = contact->getFirstGeometry ();
Geometry * const g2 = contact->getSecondGeometry ();
const bool isg1Sphere = g1 && g1->getClass () != Geometry::Class_Sphere;
const bool isg2Sphere = g2 && g2->getClass () != Geometry::Class_Sphere;

if((isg1Sphere || isg2Sphere) &&
Vehicle::handleTyreCollision(contact))
{
//handled by Vehicle.
}
else
{
contact->setBouncyness(0.0);
contact->setCoulombFriction(18.0);
}

return true;
}

rewb0rn

29-01-2008 21:45:16

try with a bouncyness of 1.0 and what values do you set for mass and size?

try much higher or lower values for these, allthough i am not sure that its the reason.

edit: shouldnt the sphere detection be
const bool isg1Sphere = g1 && g1->getClass () == Geometry::Class_Sphere;
const bool isg2Sphere = g2 && g2->getClass () == Geometry::Class_Sphere;

?

I am quite sure and what you do would work well for the vehicle, because one geo always will be no sphere so whatever you do it will execute the vehicle handling.

kalda

30-01-2008 16:06:02

Thanks!

Lowering mass/density values and changing CFM to 10e-10 helps.
Only two thinks... Which is default mass and density unit? Kg and Kg/m3 ? And why trimesh models are shaking and other objects not?

rewb0rn

30-01-2008 18:49:11

There are no units, because if you change every value respectively you will get almost the same behavior. If you want you can specify that you use meters, kg and kg/m³. I am not a physics expert, but you can also specify to use other units that are scaled the same to each other, e.g. mm, g, and g/m³ (not sure if I scaled correctly). Refer to ode.org for more information on this.