Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // REMOVED IRRELEVANT CODE FOR READABILITY
- btConvexHullShape * SceneImporter::buildCollisionShape(glm::vec3 scale, std::vector<Vertex> vertices,
- std::vector<GLuint> indices) {
- btConvexHullShape *originalCollisionShape = new btConvexHullShape();
- glm::vec4 temp_pos;
- btVector3 current_position;
- btVector3 scaling(scale.x, scale.y, scale.z);
- bool updateLocalAabb = false;
- for(Vertex vertex : vertices) {
- current_position = btVector3(vertex.Position.x, vertex.Position.y, vertex.Position.z);
- current_position *= scaling;
- originalCollisionShape->addPoint(current_position, updateLocalAabb);
- }
- btShapeHull* hull = new btShapeHull(originalCollisionShape);
- btScalar margin = originalCollisionShape->getMargin();
- hull->buildHull(margin);
- btConvexHullShape* simplifiedConvexShape = new btConvexHullShape();
- for(int i = 0; i < hull->numVertices(); i++) {
- simplifiedConvexShape->addPoint(hull->getVertexPointer()[i], updateLocalAabb);
- }
- simplifiedConvexShape->recalcLocalAabb();
- simplifiedConvexShape->initializePolyhedralFeatures();
- delete originalCollisionShape;
- delete hull;
- return simplifiedConvexShape;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement