| 61 | } |
| 62 | |
| 63 | btBoxShape *genCollisionBox(std::vector<glm::vec3> model_vertices) { |
| 64 | glm::vec3 bottom_left = glm::vec3(model_vertices[0].x, model_vertices[0].y, model_vertices[0].z); |
| 65 | glm::vec3 top_right = glm::vec3(model_vertices[0].x, model_vertices[0].y, model_vertices[0].z); |
| 66 | |
| 67 | |
| 68 | for (auto &vertex : model_vertices) { |
| 69 | if (vertex.x < bottom_left.x) { |
| 70 | bottom_left.x = vertex.x; |
| 71 | } |
| 72 | if (vertex.y < bottom_left.y) { |
| 73 | bottom_left.y = vertex.y; |
| 74 | } |
| 75 | if (vertex.z < bottom_left.z) { |
| 76 | bottom_left.z = vertex.z; |
| 77 | } |
| 78 | if (vertex.x > top_right.x) { |
| 79 | top_right.x = vertex.x; |
| 80 | } |
| 81 | if (vertex.y > top_right.y) { |
| 82 | top_right.y = vertex.y; |
| 83 | } |
| 84 | if (vertex.z > top_right.z) { |
| 85 | top_right.z = vertex.z; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return new btBoxShape(btVector3((top_right.x - bottom_left.x) / 2, (top_right.y - bottom_left.y) / 2, (top_right.z - bottom_left.z) / 2)); |
| 90 | } |
| 91 | |
| 92 | glm::vec3 genDimensions(std::vector<glm::vec3> model_vertices) { |
| 93 | glm::vec3 bottom_left = glm::vec3(model_vertices[0].x, model_vertices[0].y, model_vertices[0].z); |