Overte C++ Documentation
Plane.h
1 //
2 // Plane.h
3 // libraries/shared/src/
4 //
5 // Created by Brad Hefta-Gaub on 04/11/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
9 // Simple plane class.
10 //
11 // Distributed under the Apache License, Version 2.0.
12 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
13 //
14 
15 #ifndef hifi_Plane_h
16 #define hifi_Plane_h
17 
18 #include <glm/glm.hpp>
19 
20 class Plane {
21 public:
22  Plane(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3) { set3Points(v1, v2, v3); }
23  Plane(const glm::vec3 &normal, const glm::vec3 &point) { setNormalAndPoint(normal, point); }
24  Plane(float a, float b, float c, float d) { setCoefficients(a, b, c, d); }
25  Plane() : _normal(0.0f), _point(0.0f), _dCoefficient(0.0f) {};
26  ~Plane() {} ;
27 
28  // methods for defining the plane
29  void set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3);
30  void setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point);
31  void setCoefficients(float a, float b, float c, float d);
32 
33  // getters
34  const glm::vec3& getNormal() const { return _normal; };
35  const glm::vec3& getPoint() const { return _point; };
36  float getDCoefficient() const { return _dCoefficient; };
37 
38  // utilities
39  void invalidate() { _normal = glm::vec3(0.0f), _dCoefficient = 1.0e6f; } // distance() never less than 10^6
40  float distance(const glm::vec3 &point) const;
41  void print() const;
42 
43 private:
44  glm::vec3 _normal;
45  glm::vec3 _point;
46  float _dCoefficient;
47 };
48 
49 
50 #endif // hifi_Plane_h