ScummVM API documentation
dgPlane.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __dgPlane__
23 #define __dgPlane__
24 
25 #include "dgStdafx.h"
26 #include "dgVector.h"
27 
28 DG_MSC_VECTOR_ALIGMENT
29 class dgPlane: public dgVector {
30 public:
31  dgPlane();
32  dgPlane(dgFloat32 x, dgFloat32 y, dgFloat32 z, dgFloat32 w);
33  dgPlane(const dgVector &normal, dgFloat32 distance);
34  dgPlane(const dgVector &P0, const dgVector &P1, const dgVector &P2);
35  dgPlane Scale(dgFloat32 s) const;
36  dgFloat32 Evalue(const dgFloat32 *point) const;
37  dgFloat32 Evalue(const dgVector &point) const;
38 } DG_GCC_VECTOR_ALIGMENT;
39 
40 DG_MSC_VECTOR_ALIGMENT
41 class dgBigPlane: public dgBigVector {
42 public:
43  dgBigPlane();
44  dgBigPlane(dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w);
45  dgBigPlane(const dgBigVector &normal, dgFloat64 distance);
46  dgBigPlane(const dgBigVector &P0, const dgBigVector &P1, const dgBigVector &P2);
47  dgBigPlane Scale(dgFloat64 s) const;
48  dgFloat64 Evalue(const dgFloat32 *point) const;
49 #ifndef __USE_DOUBLE_PRECISION__
50  dgFloat64 Evalue(const dgFloat64 *point) const;
51 #endif
52  dgFloat64 Evalue(const dgVector &point) const;
53  dgFloat64 Evalue(const dgBigVector &point) const;
54 } DG_GCC_VECTOR_ALIGMENT;
55 
56 
57 
58 
59 DG_INLINE dgPlane::dgPlane()
60  : dgVector() {
61 }
62 
63 DG_INLINE dgPlane::dgPlane(dgFloat32 x, dgFloat32 y, dgFloat32 z, dgFloat32 w)
64  : dgVector(x, y, z, w) {
65 }
66 
67 DG_INLINE dgPlane::dgPlane(const dgVector &normal, dgFloat32 distance)
68  : dgVector(normal) {
69  m_w = distance;
70 }
71 
72 DG_INLINE dgPlane::dgPlane(const dgVector &P0, const dgVector &P1, const dgVector &P2)
73  : dgVector((P1 - P0) * (P2 - P0)) {
74  m_w = - (*this % P0);
75 }
76 
77 DG_INLINE dgPlane dgPlane::Scale(dgFloat32 s) const {
78  return dgPlane(m_x * s, m_y * s, m_z * s, m_w * s);
79 }
80 
81 
82 DG_INLINE dgFloat32 dgPlane::Evalue(const dgFloat32 *point) const {
83  return m_x * point[0] + m_y * point[1] + m_z * point[2] + m_w;
84 }
85 
86 DG_INLINE dgFloat32 dgPlane::Evalue(const dgVector &point) const {
87  return m_x * point.m_x + m_y * point.m_y + m_z * point.m_z + m_w;
88 }
89 
90 
91 
92 DG_INLINE dgBigPlane::dgBigPlane()
93  : dgBigVector() {
94 }
95 
96 DG_INLINE dgBigPlane::dgBigPlane(dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w)
97  : dgBigVector(x, y, z, w) {
98 }
99 
100 
101 DG_INLINE dgBigPlane::dgBigPlane(const dgBigVector &normal, dgFloat64 distance)
102  : dgBigVector(normal) {
103  m_w = distance;
104 }
105 
106 DG_INLINE dgBigPlane::dgBigPlane(const dgBigVector &P0, const dgBigVector &P1, const dgBigVector &P2)
107  : dgBigVector((P1 - P0) * (P2 - P0)) {
108  m_w = - (*this % P0);
109 }
110 
111 DG_INLINE dgBigPlane dgBigPlane::Scale(dgFloat64 s) const {
112  return dgBigPlane(m_x * s, m_y * s, m_z * s, m_w * s);
113 }
114 
115 DG_INLINE dgFloat64 dgBigPlane::Evalue(const dgFloat32 *point) const {
116  return m_x * point[0] + m_y * point[1] + m_z * point[2] + m_w;
117 }
118 
119 #ifndef __USE_DOUBLE_PRECISION__
120 DG_INLINE dgFloat64 dgBigPlane::Evalue(const dgFloat64 *point) const {
121  return m_x * point[0] + m_y * point[1] + m_z * point[2] + m_w;
122 }
123 #endif
124 
125 DG_INLINE dgFloat64 dgBigPlane::Evalue(const dgVector &point) const {
126  return m_x * point.m_x + m_y * point.m_y + m_z * point.m_z + m_w;
127 }
128 
129 DG_INLINE dgFloat64 dgBigPlane::Evalue(const dgBigVector &point) const {
130  return m_x * point.m_x + m_y * point.m_y + m_z * point.m_z + m_w;
131 }
132 
133 
134 #endif
135 
136 
Definition: dgPlane.h:29
Definition: dgVector.h:86
Definition: dgPlane.h:41
Definition: dgVector.h:104