fixed setting rigidbody's matrix with opengl matrix

This commit is contained in:
Anselme 2016-12-10 16:02:17 +01:00
parent 5b36296c1d
commit 0e609cdac7
3 changed files with 19 additions and 10 deletions

View File

@ -17,12 +17,21 @@ void MeshNode::update()
m_geometry.modelMatrix = m_movement * m_geometry.modelMatrix;
if(m_transformChanged)
{
m_geometry.modelMatrix = m_parentTransform * m_transform;
if(m_rigidBody != nullptr)
{
btTransform transform;
transform.setFromOpenGLMatrix(glm::value_ptr(m_geometry.modelMatrix));
m_rigidBody->setWorldTransform(transform);
m_rigidBody->setLinearVelocity(btVector3(0,0,0));
}
}
}
btRigidBody* MeshNode::buildStaticCollider()
{
bulletMesh = new btIndexedMesh();
btIndexedMesh *bulletMesh = new btIndexedMesh();
Mesh *m = m_geometry.mesh;
// vertices
bulletMesh->m_numVertices = m->positions3D.size();
@ -40,10 +49,7 @@ btRigidBody* MeshNode::buildStaticCollider()
collisionShape->addIndexedMesh(*bulletMesh, PHY_INTEGER);
btBvhTriangleMeshShape *shape = new btBvhTriangleMeshShape(collisionShape, false);
// positionning
btTransform transform;
transform.getOpenGLMatrix(glm::value_ptr(m_geometry.modelMatrix));
btMotionState *motionState = new btDefaultMotionState(transform);
return new btRigidBody(0, motionState, shape);
btMotionState *motionState = new btDefaultMotionState();
m_rigidBody = new btRigidBody(0, motionState, shape);
return m_rigidBody;
}

View File

@ -7,6 +7,7 @@
class btRigidBody;
class btIndexedMesh;
class btRigidBody;
/**
* @brief The MeshNode class holds a mesh
@ -15,14 +16,16 @@ class btIndexedMesh;
class MeshNode : public GraphicalNode
{
GeometryNode m_geometry;
btIndexedMesh *bulletMesh;
// physics
btRigidBody *m_rigidBody;
public:
// temp
glm::mat4 m_movement;
glm::mat4 m_acceleration;
MeshNode(Mesh* mesh) : m_geometry(mesh, glm::mat4()), bulletMesh(nullptr) {}
MeshNode(Mesh* mesh) : m_geometry(mesh, glm::mat4()), m_rigidBody(nullptr) {}
virtual void update();

View File

@ -144,7 +144,7 @@ void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
MeshNode *node = new MeshNode(chunk->mesh);
node->setTransform(glm::translate(glm::scale(glm::mat4(), glm::vec3(2.f)), pos*8.f));
terrainContainer->addChild(node);
//world->addRigidBody(node->buildStaticCollider());
world->addRigidBody(node->buildStaticCollider());
}
}
}