#include "meshnode.h" #include "mesh.h" #include "scenetree.h" #include #include #include void MeshNode::setDepth(float depth){ m_geometry.mesh->setDepth(depth); } void MeshNode::update() { // temp animation system m_movement = m_acceleration * m_movement; m_geometry.modelMatrix = m_movement * m_geometry.modelMatrix; if(m_transformChanged) m_geometry.modelMatrix = m_parentTransform * m_transform; } btRigidBody* MeshNode::buildStaticCollider() { bulletMesh = new btIndexedMesh(); Mesh *m = m_geometry.mesh; // vertices bulletMesh->m_numVertices = m->positions3D.size(); bulletMesh->m_vertexBase = (unsigned char*)(m->positions3D.data()); bulletMesh->m_vertexStride = sizeof(glm::vec3); bulletMesh->m_vertexType = PHY_FLOAT; // indices bulletMesh->m_numTriangles = m->indices.size()/3; bulletMesh->m_triangleIndexBase = (unsigned char*)(m->indices.data()); bulletMesh->m_triangleIndexStride = 3*sizeof(GLuint); bulletMesh->m_indexType = PHY_INTEGER; // building bullet rigidbody btTriangleIndexVertexArray* collisionShape = new btTriangleIndexVertexArray(); 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); }