TreeCollision edges, upVector, strange collision behavior

micken

16-08-2008 05:32:03

Hello.

I am having a problem with ogrenewt. I have 2 bodies. 1 is a space ship (in this case, the green cube) and the other is a wall (the grey cubes). If I move the green cube towards the wall of grey cubes at an angle it will sometimes bounce straight out from the wall instead of at an angle. The green cube has a basic cylinder collision type and the wall is a treecollision type. The green cube will bounce off the wall fine in most cases except when it collides directly with an edge on the treecollision. The link below is a short fraps of the described behavior (in slow motion).

Video Link: https://www.yousendit.com/download/Q01I ... NUpjR0E9PQ

Relevant code:


// rigid body.
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Cylinder( wld, 1.5f, 3.0f, Quaternion(Degree(90), Vector3::UNIT_Z) );

mBody = new OgreNewt::Body( wld, col );
mBody->setAutoFreeze(false);
mBody->setMaterialGroupID(GameInfo::GetSingletonPtr()->charMatID);
mBody->setMassMatrix(10.0f, OgreNewt::MomentOfInertia::CalcCylinderSolid( 10.0f, 1.5f, 3.0f));

mBody->attachToNode(mBodyNode);

delete col;
this->mBody->setPositionOrientation(pos, Ogre::Quaternion::IDENTITY);

// set these very small to simulate zero-g.
mBody->setLinearDamping(0.00f);
mBody->setAngularDamping(Vector3(0.00f, 0.00f, 0.00f));

// add an up joint on Y axis to restrict movement to the XZ plane.
mUpJoint = new OgreNewt::BasicJoints::UpVector(wld, mBody, Vector3(Vector3::UNIT_Y) );



this->worldCharPair = new OgreNewt::MaterialPair(mWorld,worldMatID,charMatID);
this->worldCharPair->setDefaultElasticity(Real(0.35));
this->worldCharPair->setDefaultFriction(Real(0.4), Real(0.1));
this->worldCharPair->setDefaultSoftness(Real(0.2));



// From customForceAndTorqueCallback
me->setOmega(Ogre::Vector3(0, 0, 0));


If I allow the cylinder to spin it will bounce properly most of the time but the next wall it collides with will send the object in an undesired direction because of the spin. The design of this environment is that objects will bounce off of the wall at an angle opposite the one they came in at.

I have spent hours and hours fiddling with values and different shapes/settings trying to get to the root of this but I am unable to get any closer to a solution. I think it is a problem to do with upVector joints and/or something deeper in newton having to do with edges. This also happens even when there is 0 friction.

A logical solution would be to have no edges on any walls that the ship can bounce off of but this would make a lot of extra work for my team and I would like to see if anyone can help me find a way around this before I decide to go with it.

Any help would be greatly appreciated.