Triangle Mesh acting weird

Pitje
Posts: 2
Joined: Mon Sep 19, 2011 6:44 am

Triangle Mesh acting weird

Post by Pitje »

Hello,

I'm currently in the building process of a 3D OpenGL engine with Bullet Physics.
I've implemented bullet correctly (I believe).
Anyways. Box shapes work and are not problem. But when I use a btTriangleMesh with a btBvhTriangleMeshShape and apply an angular velocity to that object. It bounces right the first time. Than it sort of digs itself in the ground en starts rotating further and eventually falls through it.

my code for making the triangle mesh is:

Code: Select all

btTriangleMesh* mTriMesh = new btTriangleMesh();

        while(node->getMesh()->triangle != NULL)
        {

            btVector3 v0(node->getMesh()->triangle->data.x[0], node->getMesh()->triangle->data.y[0], node->getMesh()->triangle->data.z[0]);
            btVector3 v1(node->getMesh()->triangle->data.x[1], node->getMesh()->triangle->data.y[1], node->getMesh()->triangle->data.z[1]);
            btVector3 v2(node->getMesh()->triangle->data.x[2], node->getMesh()->triangle->data.y[2], node->getMesh()->triangle->data.z[2]);

            mTriMesh->addTriangle(v0, v1, v2);

            node->getMesh()->triangle = node->getMesh()->triangle->next;
        }

        this->shape = new btBvhTriangleMeshShape(mTriMesh, true);
then I add set all the motionstates and make the body :

Code: Select all

oge::getConvexShapes().push_back(this->shape);

    bool isDynamic = (mass != 0.0);
    btVector3 localInertia = btVector3(0,0,0);

    if(isDynamic)
    {
        this->shape->calculateLocalInertia(mass, localInertia);
    }

    btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(node->getPosition().x, node->getPosition().y, node->getPosition().z)));

    btRigidBody::btRigidBodyConstructionInfo ci(mass, motionState, this->shape, localInertia);
    ci.m_restitution = 1;
    body = new btRigidBody(ci);
    body->setActivationState(DISABLE_DEACTIVATION);

    body->setAngularVelocity(btVector3(0.7f,0.0f,0.0f));

    body->setDamping(0.1, 0.1);

    oge::getDynamicsWorld()->addRigidBody(body);
Now I render it using the transform::getOpenGLMatrix();

But I get the same result whatever I try.

Does someone have a solution?

Thanks in advance.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Triangle Mesh acting weird

Post by dphil »

mm try btGImpactMeshShape instead. It is supposed to be for dynamic meshes, while btBvhTriangleMeshShape is meant for static meshes (though frankly I've had times where btBvhTriangleMeshShape seems to work better, so who knows). Though this may not be the cause of your problem.