My Project: dynamics.mod/NewtonDynamics/source/core/dgPlane.h Source File

My Project

dgPlane.h
Go to the documentation of this file.
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 {
31 public:
32 dgPlane ();
33 dgPlane (const dgVector& point);
34 dgPlane (dgFloat32 x, dgFloat32 y, dgFloat32 z, dgFloat32 w);
35 dgPlane (const dgVector &normal, dgFloat32 distance);
36 dgPlane (const dgVector &P0, const dgVector &P1, const dgVector &P2);
37 dgPlane Scale (dgFloat32 s) const;
38 dgFloat32 Evalue (const dgFloat32* const point) const;
39 dgFloat32 Evalue (const dgVector &point) const;
40
41
42 }DG_GCC_VECTOR_ALIGMENT;
43
44 DG_MSC_VECTOR_ALIGMENT
45 class dgBigPlane: public dgBigVector
46 {
47 public:
48 dgBigPlane ();
49 dgBigPlane (dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w);
50 dgBigPlane (const dgBigVector &normal, dgFloat64 distance);
51 dgBigPlane (const dgBigVector &P0, const dgBigVector &P1, const dgBigVector &P2);
52 dgBigPlane Scale (dgFloat64 s) const;
53 dgFloat64 Evalue (const dgFloat32* const point) const;
54 #ifndef _NEWTON_USE_DOUBLE
55 dgFloat64 Evalue (const dgFloat64* const point) const;
56 #endif
57 dgFloat64 Evalue (const dgVector &point) const;
58 dgFloat64 Evalue (const dgBigVector &point) const;
59 }DG_GCC_VECTOR_ALIGMENT;
60
61
62
63
64 DG_INLINE dgPlane::dgPlane ()
65 :dgVector ()
66 {
67 }
68
69 DG_INLINE dgPlane::dgPlane (const dgVector& point)
70 :dgVector (point)
71 {
72 }
73
74 DG_INLINE dgPlane::dgPlane (dgFloat32 x, dgFloat32 y, dgFloat32 z, dgFloat32 w)
75 :dgVector (x, y, z, w)
76 {
77 }
78
79 DG_INLINE dgPlane::dgPlane (const dgVector &normal, dgFloat32 distance)
80 :dgVector (normal)
81 {
82 m_w = distance;
83 }
84
85 DG_INLINE dgPlane::dgPlane (const dgVector &P0, const dgVector &P1, const dgVector &P2)
86 :dgVector ((P1 - P0) * (P2 - P0))
87 {
88 m_w = - (*this % P0);
89 }
90
91 DG_INLINE dgPlane dgPlane::Scale (dgFloat32 s) const
92 {
93 // return dgPlane (m_x * s, m_y * s, m_z * s, m_w * s);
94 return dgPlane (CompProduct4 (dgVector (s)));
95 }
96
97
98 DG_INLINE dgFloat32 dgPlane::Evalue (const dgFloat32* const point) const
99 {
100 // return m_x * point[0] + m_y * point[1] + m_z * point[2] + m_w;
101 return DotProduct4 (dgVector (point) | m_wOne).m_x;
102 }
103
104 DG_INLINE dgFloat32 dgPlane::Evalue (const dgVector& point) const
105 {
106 // return m_x * point.m_x + m_y * point.m_y + m_z * point.m_z + m_w;
107 return DotProduct4 ((point & m_triplexMask) | m_wOne).m_x;
108 }
109
110
111
112 DG_INLINE dgBigPlane::dgBigPlane ()
113 :dgBigVector ()
114 {
115 }
116
117 DG_INLINE dgBigPlane::dgBigPlane (dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w)
118 :dgBigVector (x, y, z, w)
119 {
120 }
121
122
123 DG_INLINE dgBigPlane::dgBigPlane (const dgBigVector &normal, dgFloat64 distance)
124 :dgBigVector (normal)
125 {
126 m_w = distance;
127 }
128
129 DG_INLINE dgBigPlane::dgBigPlane (const dgBigVector &P0, const dgBigVector &P1, const dgBigVector &P2)
130 :dgBigVector ((P1 - P0) * (P2 - P0))
131 {
132 m_w = - (*this % P0);
133 }
134
135 DG_INLINE dgBigPlane dgBigPlane::Scale (dgFloat64 s) const
136 {
137 return dgBigPlane (m_x * s, m_y * s, m_z * s, m_w * s);
138 }
139
140 DG_INLINE dgFloat64 dgBigPlane::Evalue (const dgFloat32* const point) const
141 {
142 return m_x * point[0] + m_y * point[1] + m_z * point[2] + m_w;
143 }
144
145 #ifndef _NEWTON_USE_DOUBLE
146 DG_INLINE dgFloat64 dgBigPlane::Evalue (const dgFloat64* const point) const
147 {
148 return m_x * point[0] + m_y * point[1] + m_z * point[2] + m_w;
149 }
150 #endif
151
152 DG_INLINE dgFloat64 dgBigPlane::Evalue (const dgVector &point) const
153 {
154 return m_x * point.m_x + m_y * point.m_y + m_z * point.m_z + m_w;
155 }
156
157 DG_INLINE dgFloat64 dgBigPlane::Evalue (const dgBigVector &point) const
158 {
159 return m_x * point.m_x + m_y * point.m_y + m_z * point.m_z + m_w;
160 }
161
162
163 #endif
164
165
dgPlane::Scale
dgPlane Scale(dgFloat32 s) const
Definition: dgPlane.h:91
dgPlane
Definition: dgPlane.h:29
dgBigPlane::Evalue
dgFloat64 Evalue(const dgFloat32 *const point) const
Definition: dgPlane.h:140
DG_INLINE
#define DG_INLINE
Definition: dgTypes.h:178
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgBigPlane::Scale
dgBigPlane Scale(dgFloat64 s) const
Definition: dgPlane.h:135
dgVector
Definition: dgVector.h:639
dgTemplateVector< dgFloat64 >::m_z
dgFloat64 m_z
Definition: dgVector.h:195
dgVector::m_z
dgFloat32 m_z
Definition: dgVector.h:1027
dgTemplateVector< dgFloat64 >::m_y
dgFloat64 m_y
Definition: dgVector.h:194
dgFloat64
double dgFloat64
Definition: dgTypes.h:224
dgVector.h
dgVector::m_wOne
static dgVector m_wOne
Definition: dgVector.h:1039
DG_MSC_VECTOR_ALIGMENT
#define DG_MSC_VECTOR_ALIGMENT
Definition: dgTypes.h:194
dgVector::m_triplexMask
static dgVector m_triplexMask
Definition: dgVector.h:1045
dgVector::m_x
dgFloat32 m_x
Definition: dgVector.h:1025
dgStdafx.h
dgPlane::Evalue
dgFloat32 Evalue(const dgFloat32 *const point) const
Definition: dgPlane.h:98
s
sem_t s
Definition: semaphore3.c:78
dgVector::CompProduct4
DG_INLINE dgVector CompProduct4(const dgVector &A) const
Definition: dgVector.h:851
dgBigPlane
Definition: dgPlane.h:45
DG_GCC_VECTOR_ALIGMENT
dgPlane DG_GCC_VECTOR_ALIGMENT
dgVector::DotProduct4
DG_INLINE dgVector DotProduct4(const dgVector &A) const
Definition: dgVector.h:783
dgVector::m_w
dgFloat32 m_w
Definition: dgVector.h:1028
dgTemplateVector< dgFloat64 >::m_w
dgFloat64 m_w
Definition: dgVector.h:196
dgPlane::dgPlane
dgPlane()
Definition: dgPlane.h:64
dgBigPlane::dgBigPlane
dgBigPlane()
Definition: dgPlane.h:112
dgBigVector
Definition: dgVector.h:207
dgTemplateVector< dgFloat64 >::m_x
dgFloat64 m_x
Definition: dgVector.h:193
dgVector::m_y
dgFloat32 m_y
Definition: dgVector.h:1026