Advertisement
Guest User

Sceneimporter

a guest
May 19th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. // REMOVED IRRELEVANT CODE FOR READABILITY
  2.  
  3.  
  4.    btConvexHullShape * SceneImporter::buildCollisionShape(glm::vec3 scale, std::vector<Vertex> vertices,
  5.                                                           std::vector<GLuint> indices) {
  6.  
  7.         btConvexHullShape *originalCollisionShape = new btConvexHullShape();
  8.  
  9.  
  10.         glm::vec4 temp_pos;
  11.         btVector3 current_position;
  12.         btVector3 scaling(scale.x, scale.y, scale.z);
  13.  
  14.         bool updateLocalAabb = false;
  15.  
  16.         for(Vertex vertex : vertices) {
  17.             current_position = btVector3(vertex.Position.x, vertex.Position.y, vertex.Position.z);
  18.  
  19.             current_position *= scaling;
  20.  
  21.             originalCollisionShape->addPoint(current_position, updateLocalAabb);
  22.         }
  23.  
  24.  
  25.         btShapeHull* hull = new btShapeHull(originalCollisionShape);
  26.         btScalar margin = originalCollisionShape->getMargin();
  27.         hull->buildHull(margin);
  28.  
  29.         btConvexHullShape* simplifiedConvexShape = new btConvexHullShape();
  30.  
  31.         for(int i = 0; i < hull->numVertices(); i++) {
  32.             simplifiedConvexShape->addPoint(hull->getVertexPointer()[i], updateLocalAabb);
  33.         }
  34.  
  35.         simplifiedConvexShape->recalcLocalAabb();
  36.  
  37.         simplifiedConvexShape->initializePolyhedralFeatures();
  38.  
  39.  
  40.         delete originalCollisionShape;
  41.         delete hull;
  42.  
  43.  
  44.         return simplifiedConvexShape;
  45.  
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement