bounding_box.cpp
Go to the documentation of this file.
2 
3 namespace tango_gl {
4 BoundingBox::BoundingBox(const std::vector<float>& vertices) {
5  // Set min and max to the first vertice.
6  bounding_min_ = glm::vec3(vertices[0], vertices[1], vertices[2]);
8  size_t vertices_count = vertices.size() / 3;
9  for (size_t i = 1; i < vertices_count; i += 3) {
10  bounding_min_.x = std::min(vertices[i * 3], bounding_min_.x);
11  bounding_min_.y = std::min(vertices[i * 3 + 1], bounding_min_.y);
12  bounding_min_.z = std::min(vertices[i * 3 + 2], bounding_min_.z);
13 
14  bounding_max_.x = std::max(vertices[i * 3], bounding_max_.x);
15  bounding_max_.y = std::max(vertices[i * 3 + 1], bounding_max_.y);
16  bounding_max_.z = std::max(vertices[i * 3 + 2], bounding_max_.z);
17  }
18 }
19 
21  const glm::quat& rotation,
22  const glm::mat4& transformation) {
23  // The current bounding box.
24  glm::vec3 min, max;
25 
26  // If the mesh has been rotated, we need to derive a new bounding box
27  // based on the original one, if it just been translated or scaled,
28  // we can still use the original one with current model matrix applied.
29  if (rotation == glm::quat(1.0f, 0.0f, 0.0f, 0.0f)) {
30  min = util::ApplyTransform(transformation, bounding_min_);
31  max = util::ApplyTransform(transformation, bounding_max_);
32  } else {
33  std::vector<glm::vec3> box;
34  // Derive 8 vertices of the new bounding box from original min and max.
35  box.push_back(bounding_min_);
36  box.push_back(bounding_max_);
37 
40 
43 
46 
47  min = util::ApplyTransform(transformation, bounding_min_);
48  max = min;
49  for (size_t i = 1; i < box.size(); i++) {
50  glm::vec3 temp = util::ApplyTransform(transformation, box[i]);
51  min.x = std::min(temp.x, min.x);
52  min.y = std::min(temp.y, min.y);
53  min.z = std::min(temp.z, min.z);
54 
55  max.x = std::max(temp.x, max.x);
56  max.y = std::max(temp.y, max.y);
57  max.z = std::max(temp.z, max.z);
58  }
59  }
60  return util::SegmentAABBIntersect(min, max, segment.start, segment.end);
61 }
62 } // namespace tango_gl
highp_vec3 vec3
Definition: type_vec.hpp:392
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
glm::vec3 end
Definition: segment.h:32
f
static const float vertices[]
Definition: quad.cpp:39
glm::vec3 ApplyTransform(const glm::mat4 &mat, const glm::vec3 &vec)
Definition: util.cpp:237
bool IsIntersecting(const Segment &segment, const glm::quat &rotation, const glm::mat4 &transformation)
GLM_FUNC_DECL detail::tquat< T, P > rotation(detail::tvec3< T, P > const &orig, detail::tvec3< T, P > const &dest)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
bool SegmentAABBIntersect(const glm::vec3 &aabb_min, const glm::vec3 &aabb_max, const glm::vec3 &start, const glm::vec3 &end)
Definition: util.cpp:198
glm::vec3 start
Definition: segment.h:31


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:30