Overte C++ Documentation
Extents.h
1 //
2 // Extents.h
3 // libraries/shared/src
4 //
5 // Created by Andrzej Kapolka on 9/18/13.
6 // Moved to shared by Brad Hefta-Gaub on 9/11/14
7 // Copyright 2013-2104 High Fidelity, Inc.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_Extents_h
14 #define hifi_Extents_h
15 
16 #include <glm/glm.hpp>
17 #include <glm/gtx/component_wise.hpp>
18 
19 #include <QDebug>
20 #include "StreamUtils.h"
21 #include "GLMHelpers.h"
22 
23 class AABox;
24 class Transform;
25 
26 class Extents {
27 public:
28  Extents() { }
29  Extents(const glm::vec3& minimum, const glm::vec3& maximum) : minimum(minimum), maximum(maximum) {}
30  Extents(const AABox& box) { reset(); add(box); }
31 
33  void reset();
34 
37  void addExtents(const Extents& extents);
38 
41  void add(const AABox& box);
42 
45  void addPoint(const glm::vec3& point);
46 
49  bool containsPoint(const glm::vec3& point) const;
50 
52  bool isEmpty() const { return minimum == maximum; }
53  bool isValid() const { return !((minimum == Vectors::MAX) && (maximum == Vectors::MIN)); }
54 
57  void shiftBy(const glm::vec3& delta) { minimum += delta; maximum += delta; }
58 
60  void rotate(const glm::quat& rotation);
61 
63  void scale(float scale) { minimum *= scale; maximum *= scale; }
64  void scale(const glm::vec3& scale) { minimum *= scale; maximum *= scale; }
65 
66  // Transform the extents with transform
67  void transform(const Transform& transform);
68 
69  glm::vec3 size() const { return maximum - minimum; }
70  float largestDimension() const { return glm::compMax(size()); }
71 
73  Extents getRotated(const glm::quat& rotation) const {
74  Extents temp(minimum, maximum);
75  temp.rotate(rotation);
76  return temp;
77  }
78 
79  glm::vec3 minimum{ Vectors::MAX };
80  glm::vec3 maximum{ Vectors::MIN };
81 };
82 
83 inline QDebug operator<<(QDebug debug, const Extents& extents) {
84  debug << "Extents[ ("
85  << extents.minimum << " ) to ("
86  << extents.maximum << ") size: ("
87  << (extents.maximum - extents.minimum) << ")"
88  << " ]";
89 
90  return debug;
91 }
92 
93 
94 #endif // hifi_Extents_h