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