fixed setting rigidbody's matrix with opengl matrix
This commit is contained in:
parent
5b36296c1d
commit
0e609cdac7
@ -17,12 +17,21 @@ void MeshNode::update()
|
|||||||
m_geometry.modelMatrix = m_movement * m_geometry.modelMatrix;
|
m_geometry.modelMatrix = m_movement * m_geometry.modelMatrix;
|
||||||
|
|
||||||
if(m_transformChanged)
|
if(m_transformChanged)
|
||||||
|
{
|
||||||
m_geometry.modelMatrix = m_parentTransform * m_transform;
|
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()
|
btRigidBody* MeshNode::buildStaticCollider()
|
||||||
{
|
{
|
||||||
bulletMesh = new btIndexedMesh();
|
btIndexedMesh *bulletMesh = new btIndexedMesh();
|
||||||
Mesh *m = m_geometry.mesh;
|
Mesh *m = m_geometry.mesh;
|
||||||
// vertices
|
// vertices
|
||||||
bulletMesh->m_numVertices = m->positions3D.size();
|
bulletMesh->m_numVertices = m->positions3D.size();
|
||||||
@ -40,10 +49,7 @@ btRigidBody* MeshNode::buildStaticCollider()
|
|||||||
collisionShape->addIndexedMesh(*bulletMesh, PHY_INTEGER);
|
collisionShape->addIndexedMesh(*bulletMesh, PHY_INTEGER);
|
||||||
btBvhTriangleMeshShape *shape = new btBvhTriangleMeshShape(collisionShape, false);
|
btBvhTriangleMeshShape *shape = new btBvhTriangleMeshShape(collisionShape, false);
|
||||||
|
|
||||||
// positionning
|
btMotionState *motionState = new btDefaultMotionState();
|
||||||
btTransform transform;
|
m_rigidBody = new btRigidBody(0, motionState, shape);
|
||||||
transform.getOpenGLMatrix(glm::value_ptr(m_geometry.modelMatrix));
|
return m_rigidBody;
|
||||||
btMotionState *motionState = new btDefaultMotionState(transform);
|
|
||||||
|
|
||||||
return new btRigidBody(0, motionState, shape);
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
class btRigidBody;
|
class btRigidBody;
|
||||||
class btIndexedMesh;
|
class btIndexedMesh;
|
||||||
|
class btRigidBody;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The MeshNode class holds a mesh
|
* @brief The MeshNode class holds a mesh
|
||||||
@ -15,14 +16,16 @@ class btIndexedMesh;
|
|||||||
class MeshNode : public GraphicalNode
|
class MeshNode : public GraphicalNode
|
||||||
{
|
{
|
||||||
GeometryNode m_geometry;
|
GeometryNode m_geometry;
|
||||||
btIndexedMesh *bulletMesh;
|
|
||||||
|
// physics
|
||||||
|
btRigidBody *m_rigidBody;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// temp
|
// temp
|
||||||
glm::mat4 m_movement;
|
glm::mat4 m_movement;
|
||||||
glm::mat4 m_acceleration;
|
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();
|
virtual void update();
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
|
|||||||
MeshNode *node = new MeshNode(chunk->mesh);
|
MeshNode *node = new MeshNode(chunk->mesh);
|
||||||
node->setTransform(glm::translate(glm::scale(glm::mat4(), glm::vec3(2.f)), pos*8.f));
|
node->setTransform(glm::translate(glm::scale(glm::mat4(), glm::vec3(2.f)), pos*8.f));
|
||||||
terrainContainer->addChild(node);
|
terrainContainer->addChild(node);
|
||||||
//world->addRigidBody(node->buildStaticCollider());
|
world->addRigidBody(node->buildStaticCollider());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user