OGLplus (0.52.0) a C++ wrapper for OpenGL

plane.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_PLANE_1107121519_HPP
14 #define OGLPLUS_PLANE_1107121519_HPP
15 
16 #include <cmath>
17 
18 namespace oglplus {
19 
21 
26 template <typename T>
27 class Plane
28 {
29 private:
30  Vector<T, 4> _equation;
31 public:
33  Plane(T a, T b, T c, T d)
34  : _equation(a, b, c, d)
35  { }
36 
38  Plane(const Vector<T, 4>& v)
39  : _equation(v)
40  { }
41 
42  struct FromTriangle_ { };
43 
44  Plane(
45  FromTriangle_,
46  const Vector<T, 3>& p0,
47  const Vector<T, 3>& p1,
48  const Vector<T, 3>& p2
49  ): _equation(
50  Normalized(Cross(p1-p0, p2-p0)),
51  -Dot(Normalized(Cross(p1-p0, p2-p0)), p0)
52  )
53  { }
54 
55 
57  static inline Plane FromTriangle(
58  const Vector<T, 3>& p0,
59  const Vector<T, 3>& p1,
60  const Vector<T, 3>& p2
61  )
62  {
63  return Plane(
64  FromTriangle_(),
65  p0, p1, p2
66  );
67  }
68 
69  struct FromPointAndVectors_ { };
70 
71  Plane(
72  FromPointAndVectors_,
73  const Vector<T, 3>& p,
74  const Vector<T, 3>& v1,
75  const Vector<T, 3>& v2
76  ): _equation(
77  Normalized(Cross(v1, v2)),
78  -Dot(Normalized(Cross(v1, v2)), p)
79  )
80  { }
81 
83  static inline Plane FromPointAndVectors(
84  const Vector<T, 3>& p,
85  const Vector<T, 3>& v1,
86  const Vector<T, 3>& v2
87  )
88  {
89  return Plane(
90  FromPointAndVectors_(),
91  p, v1, v2
92  );
93  }
94 
95  struct FromNormal_ { };
96 
97  Plane(FromNormal_, const Vector<T, 3>& normal)
98  : _equation(normal, T(0))
99  { }
100 
102  static inline Plane FromNormal(const Vector<T, 3>& normal)
103  {
104  return Plane(FromNormal_(), normal);
105  }
106 
107  struct FromPointAndNormal_ { };
108 
109  Plane(
110  FromPointAndNormal_,
111  const Vector<T, 3>& point,
112  const Vector<T, 3>& normal
113  ): _equation(normal, -Dot(normal, point))
114  { }
115 
117  static inline Plane FromPointAndNormal(
118  const Vector<T, 3>& point,
119  const Vector<T, 3>& normal
120  )
121  {
122  return Plane(FromPointAndNormal_(), point, normal);
123  }
124 
126  const Vector<T, 4>& Equation(void) const
127  {
128  return _equation;
129  }
130 };
131 
132 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_FLOAT)
133 typedef Plane<GLfloat> Planef;
135 #endif
136 
137 } // namespace oglplus
138 
139 #endif // include guard
Definition: vector.hpp:14
Plane(T a, T b, T c, T d)
construction from parameters
Definition: plane.hpp:33
Class implementing plane-related functionality.
Definition: plane.hpp:27
const Vector< T, 4 > & Equation(void) const
Retuns the plane's equation parameters.
Definition: plane.hpp:126
Plane(const Vector< T, 4 > &v)
Constructions from parameter vector.
Definition: plane.hpp:38
static Plane FromTriangle(const Vector< T, 3 > &p0, const Vector< T, 3 > &p1, const Vector< T, 3 > &p2)
Constructs a plane defined by points p0, p1, p2.
Definition: plane.hpp:57
static Plane FromPointAndNormal(const Vector< T, 3 > &point, const Vector< T, 3 > &normal)
Constructs a plane from a point on in and its normal vector.
Definition: plane.hpp:117
static Plane FromNormal(const Vector< T, 3 > &normal)
Constructs a plane going through the origin from its normal vector.
Definition: plane.hpp:102
static Plane FromPointAndVectors(const Vector< T, 3 > &p, const Vector< T, 3 > &v1, const Vector< T, 3 > &v2)
Constructs a plane defined by point p0 and vectors v1 and v2.
Definition: plane.hpp:83
Definition: vector.hpp:14
Plane< GLfloat > Planef
Instantiation of Plane using GL floating-point as underlying type.
Definition: plane.hpp:134

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).