Newton Dynamics  4.00
ndPlane.h
1 /* Copyright (c) <2003-2022> <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 __ND_PLANE_H__
23 #define __ND_PLANE_H__
24 
25 #include "ndCoreStdafx.h"
26 #include "ndVector.h"
27 
28 
29 #ifdef D_NEWTON_USE_DOUBLE
30  #define ndPlane ndBigPlane
31 #else
32 
33 D_MSV_NEWTON_ALIGN_16
34 class ndPlane: public ndVector
35 {
36  public:
37  ndPlane ();
38  ndPlane (const ndVector& point);
39  ndPlane (ndFloat32 x, ndFloat32 y, ndFloat32 z, ndFloat32 w);
40  ndPlane (const ndVector &normal, ndFloat32 distance);
41  ndPlane (const ndVector &P0, const ndVector &P1, const ndVector &P2);
42  ndPlane Scale (ndFloat32 s) const;
43  ndFloat32 Evalue (const ndFloat32* const point) const;
44  ndFloat32 Evalue (const ndVector &point) const;
45 } D_GCC_NEWTON_ALIGN_32 ;
46 
47 #endif
48 
49 class ndBigPlane: public ndBigVector
50 {
51  public:
52  ndBigPlane ();
53  ndBigPlane (const ndBigVector& point);
54  ndBigPlane (ndFloat64 x, ndFloat64 y, ndFloat64 z, ndFloat64 w);
55  ndBigPlane (const ndBigVector &normal, ndFloat64 distance);
56  ndBigPlane (const ndBigVector &P0, const ndBigVector &P1, const ndBigVector &P2);
57  ndBigPlane Scale (ndFloat64 s) const;
58  ndFloat64 Evalue (const ndFloat64* const point) const;
59  ndFloat64 Evalue (const ndBigVector &point) const;
60 };
61 
62 #ifndef D_NEWTON_USE_DOUBLE
63 
64 inline ndPlane::ndPlane ()
65  :ndVector ()
66 {
67 }
68 
69 inline ndPlane::ndPlane (const ndVector& point)
70  :ndVector (point)
71 {
72 }
73 
74 inline ndPlane::ndPlane (ndFloat32 x, ndFloat32 y, ndFloat32 z, ndFloat32 w)
75  :ndVector (x, y, z, w)
76 {
77 }
78 
79 inline ndPlane::ndPlane (const ndVector &normal, ndFloat32 distance)
80  :ndVector (normal)
81 {
82  m_w = distance;
83 }
84 
85 inline ndPlane::ndPlane (const ndVector &P0, const ndVector &P1, const ndVector &P2)
86  :ndVector ((P1 - P0).CrossProduct(P2 - P0))
87 {
88  m_w = - DotProduct(P0 & ndVector::m_triplexMask).GetScalar();
89 }
90 
91 inline ndPlane ndPlane::Scale (ndFloat32 s) const
92 {
93  return ndPlane(*this * ndVector(s));
94 }
95 
96 inline ndFloat32 ndPlane::Evalue (const ndFloat32* const point) const
97 {
98  ndVector p (point);
99  return DotProduct ((p & m_triplexMask) | m_wOne).GetScalar();
100 }
101 
102 inline ndFloat32 ndPlane::Evalue (const ndVector& point) const
103 {
104  return DotProduct ((point & m_triplexMask) | m_wOne).GetScalar();
105 }
106 #endif
107 
108 
109 inline ndBigPlane::ndBigPlane ()
110  :ndBigVector ()
111 {
112 }
113 
114 inline ndBigPlane::ndBigPlane (const ndBigVector& point)
115  :ndBigVector (point)
116 {
117 }
118 
119 inline ndBigPlane::ndBigPlane (ndFloat64 x, ndFloat64 y, ndFloat64 z, ndFloat64 w)
120  :ndBigVector (x, y, z, w)
121 {
122 }
123 
124 inline ndBigPlane::ndBigPlane (const ndBigVector &normal, ndFloat64 distance)
125  :ndBigVector (normal)
126 {
127  m_w = distance;
128 }
129 
130 inline ndBigPlane::ndBigPlane (const ndBigVector &P0, const ndBigVector &P1, const ndBigVector &P2)
131  :ndBigVector ((P1 - P0).CrossProduct(P2 - P0))
132 {
133  m_w = - DotProduct(P0 & ndBigVector::m_triplexMask).GetScalar();
134 }
135 
136 inline ndBigPlane ndBigPlane::Scale (ndFloat64 s) const
137 {
138  return ndBigPlane (m_x * s, m_y * s, m_z * s, m_w * s);
139 }
140 
141 inline ndFloat64 ndBigPlane::Evalue (const ndFloat64* const point) const
142 {
143  return m_x * point[0] + m_y * point[1] + m_z * point[2] + m_w;
144 }
145 
146 
147 inline ndFloat64 ndBigPlane::Evalue (const ndBigVector &point) const
148 {
149  return m_x * point.m_x + m_y * point.m_y + m_z * point.m_z + m_w;
150 }
151 
152 #endif
153 
154 
ndPlane
Definition: ndPlane.h:35
ndBigPlane
Definition: ndPlane.h:50
ndBigVector
Definition: ndVectorArmNeon.h:463
ndVector
Definition: ndVectorArmNeon.h:41