Finding the angle of triangles in a btBvhTriangleMeshShape

sharith3
Posts: 4
Joined: Sun Feb 27, 2011 8:16 pm

Finding the angle of triangles in a btBvhTriangleMeshShape

Post by sharith3 »

Problem: I have a Level a btBvhTriangleMeshShape btCollisionObject, and a player which is a btRigidBody and the player is inside the Levels AABB box at all times since the level is enclosed. I need to know the angle of triangle in the btBvhTriangleMeshShape that the player is colliding with. So far I have tried two methods and both have not worked out for me.

Method number one I cycled through the manifold and created my own callback to it. This allowed me to get at the btPersistentManifold of each collision as well as each btCollisionObject. Due to this I was able to touch the variable m_normalWorldOnB which I was hoping to use to calculate the angle, but the value never changed. So I kind of got stuck.

Ex 1:

btPersistentManifold* contactManifold = dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(x);
btCollisionObject* body1 = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* body2 = static_cast<btCollisionObject*>(contactManifold->getBody1());

int points = contactManifold->getNumContacts();

base1 = static_cast<Base*>(body1->getUserPointer());
base2 = static_cast<Base*>(body2->getUserPointer());

if(base1->GetType() == "player" || base1->GetType() == "enemy")
{
static_cast<BaseObject*>(base1)->CollisionCreated(contactManifold, body2);
}
//this is repeated for base2


Method two I figured I would use the btBvhTriangleMeshShape's processAllTriangles function with my own btTriangleCallback to get the information of each triangle that the players AABB box collided with. It was all fine and dandy until I realized that by the time it hit my callback all I had was the position of the triangle and its indexes... With that amount of info I do not know how to find the angle of the plane.

Ex 2:

//The triangle callback
void Terrain::processTriangle(btVector3* triangle, int partId, int triangleIndex)
{
return;
}

void Terrain::CollisionCreated(btPersistentManifold* manifold, btCollisionObject* body)
{
btTransform transform;
btVector3 minAABB;
btVector3 maxAABB;

body->getCollisionShape()->getAabb(body->getWorldTransform(), minAABB, maxAABB);
static_cast<btBvhTriangleMeshShape*>(nodeShape)->processAllTriangles(this, minAABB, maxAABB);
}


So what my point boils down to is, am I missing something, or is there a better way of doing this?
DragonGeo2
Posts: 16
Joined: Sat Dec 18, 2010 1:30 am

Re: Finding the angle of triangles in a btBvhTriangleMeshSha

Post by DragonGeo2 »

The way I handle this is with a btCollisionWorld::convexSweepTest. My player is represented by a collision shape and I take that shape and cast it in the direction of the player's velocity vector (mostly downwards due to gravity, but also sometimes in the direction the player is moving). The convex sweep test returns the hit normal where the player's shape intersected the world geometry.
sharith3
Posts: 4
Joined: Sun Feb 27, 2011 8:16 pm

Re: Finding the angle of triangles in a btBvhTriangleMeshSha

Post by sharith3 »

So I've been working on the convexSweepTest for the past few days. I did some research on it and found a previous post by you, which was most helpful in getting started with the convexSweep. Though I am now running into a different problem, the m_hitNormalWorld that I receive from the callback never changes as I move across the triangles of my level. Currently I am using

start.setIdentity();
start.setOrigin(nodeRigidBody->getWorldTransform().getOrigin());

end.setIdentity();
end.setOrigin(nodeRigidBody->getWorldTransform().getOrigin() + nodeRigidBody->getLinearVelocity());

To get the start and target points for the sweep. I am using the ClosestConvexResultCallback and I use start and end for it's constructor. Then I call the convexSweepTest

dynamicsWorld->convexSweepTest(static_cast<btCapsuleShape*>(nodeRigidBody->getCollisionShape()), start, end, callback);

All I can think of is that my target is wrong, but even still I figure I should at least be seeing the numbers change even if they are faulty. One other thing I noticed is that the m_hitCollisionObject that is returned seems to be a null pointer. Cause I should be able to get the userPointer from it but it crashes when I try to do that and the majority of all its values are undefined.

Thanks for the help so far.
sharith3
Posts: 4
Joined: Sun Feb 27, 2011 8:16 pm

Re: Finding the angle of triangles in a btBvhTriangleMeshSha

Post by sharith3 »

So I figured out why the numbers never change, its cause it is never registering as colliding. I called the function hasHit() every frame not once is does it ever equate to true, even though the player is colliding with the terrain.
sharith3
Posts: 4
Joined: Sun Feb 27, 2011 8:16 pm

Re: Finding the angle of triangles in a btBvhTriangleMeshSha

Post by sharith3 »

So... I am going to just say it... I'm stupid. The problem was that I had everything assigned collision groups and masks and I was not setting that for the convexSweep callback so it was just ignoring the collision... thanks for the help, I now have the info I want.