CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrVisVector.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23// Vector definition
24
25#ifndef ODTRVISVECTOR
26#define ODTRVISVECTOR
27
28#include "TD_PackPush.h"
29
30#include "Ge/GePoint3d.h"
31#include "Ge/GeVector3d.h"
32
37template <typename DataType>
39{
40 DataType x, y;
41 typedef DataType EntryType;
42
43 static bool eqTol(float val , float eps = 1.e-8f) { return (val < eps) && (val > -eps); }
44 static bool eqTol(double val, double eps = 1.e-10) { return (val < eps) && (val > -eps); }
45
46 // Constructors
48 OdTrVisMiniVec2d(DataType _x, DataType _y) : x(_x), y(_y) { }
49 template <typename VecType>
50 OdTrVisMiniVec2d(const VecType &vec) : x((DataType)vec.x), y((DataType)vec.y) { }
51
52 // Setters
53 OdTrVisMiniVec2d &set(DataType _x, DataType _y)
54 { x = _x; y = _y; return *this; }
55 template <typename VecType>
56 OdTrVisMiniVec2d &set(const VecType &vec)
57 { x = (DataType)vec.x; y = (DataType)vec.y; return *this; }
58
59 // Getters
60 DataType operator [](int nAxis) const
61 { return (!nAxis) ? x : y; }
62 DataType &operator [](int nAxis)
63 { return (!nAxis) ? x : y; }
64
65 // Comparators
66 bool operator ==(const OdTrVisMiniVec2d &vec) const
67 { return eqTol(x - vec.x) && eqTol(y - vec.y); }
68 bool operator !=(const OdTrVisMiniVec2d &vec) const
69 { return !eqTol(x - vec.x) || !eqTol(y - vec.y); }
70
71 // Converters
72 operator OdGePoint2d() const { return OdGePoint2d(x, y); }
73 operator OdGeVector2d() const { return OdGeVector2d(x, y); }
74
75 // Basic math operators
77 { return OdTrVisMiniVec2d(x + vec.x, y + vec.y); }
79 { x += vec.x; y += vec.y; return *this; }
81 { return OdTrVisMiniVec2d(x - vec.x, y - vec.y); }
83 { x -= vec.x; y -= vec.y; return *this; }
84
85 // Dot/cross product
86 DataType operator *(const OdTrVisMiniVec2d &vec) const
87 { return x * vec.x + y * vec.y; }
88 DataType operator ^(const OdTrVisMiniVec2d &vec) const
89 { return x * vec.y - y * vec.x; }
90
91 // Scale operators
92 friend OdTrVisMiniVec2d operator *(const OdTrVisMiniVec2d &vec, DataType val)
93 { return OdTrVisMiniVec2d(vec.x * val, vec.y * val); }
94 friend OdTrVisMiniVec2d operator *(DataType val, const OdTrVisMiniVec2d &vec)
95 { return OdTrVisMiniVec2d(val * vec.x, val * vec.y); }
97 { x *= val; y *= val; return *this; }
98 friend OdTrVisMiniVec2d operator /(const OdTrVisMiniVec2d &vec, DataType val)
99 { return OdTrVisMiniVec2d(vec.x / val, vec.y / val); }
100 friend OdTrVisMiniVec2d operator /(DataType val, const OdTrVisMiniVec2d &vec)
101 { return OdTrVisMiniVec2d(val / vec.x, val / vec.y); }
103 { x /= val; y /= val; return *this; }
104
105 // Negate operator
107 OdTrVisMiniVec2d &negate() { x = -x; y = -y; return *this; }
108
109 // Component-wise operators
111 { return OdTrVisMiniVec2d(x * vec.x, y * vec.y); }
113 { x *= vec.x; y *= vec.y; return *this; }
115 { return OdTrVisMiniVec2d(x / vec.x, y / vec.y); }
117 { x /= vec.x; y /= vec.y; return *this; }
118
119 // Null operator
121 { x = y = 0.0f; return *this; }
122 bool isNull(DataType eps = 1.e-8f) const
123 { return eqTol(x, eps) && eqTol(y, eps); }
124
125 // Length operator
126 DataType length2() const
127 { return x * x + y * y; }
128 DataType length() const
129 { return (DataType)sqrt(length2()); }
130
131 // Normalization
133 { return OdTrVisMiniVec2d(*this).normalize(); }
134 OdTrVisMiniVec2d &normalize(DataType eps = 1.e-8f)
135 { DataType rd = length();
136 if (eqTol(rd, eps))
137 setNull();
138 else
139 rd = 1.0f / rd,
140 *this *= rd;
141 return *this;
142 }
143
144 // Min/max operators
145 DataType minimum() const
146 { return odmin(x, y); }
147 DataType maximum() const
148 { return odmax(x, y); }
149};
150
155template <typename DataType>
156struct OdTrVisMiniVec3d : public OdTrVisMiniVec2d<DataType>
157{
158 DataType z;
159
161 // Constructors
163 OdTrVisMiniVec3d(DataType _x, DataType _y, DataType _z) : OdTrVisMiniVec2d<DataType>(_x, _y), z(_z) { }
164 OdTrVisMiniVec3d(const BaseVec &xy, DataType _z) : OdTrVisMiniVec2d<DataType>(xy), z(_z) { }
165 template <typename VecType>
166 OdTrVisMiniVec3d(const VecType &vec) : OdTrVisMiniVec2d<DataType>((DataType)vec.x, (DataType)vec.y), z(vec.z) { }
167
168 // Setters
169 OdTrVisMiniVec3d &set(DataType _x, DataType _y, DataType _z)
170 { BaseVec::x = _x; BaseVec::y = _y; z = _z; return *this; }
171 OdTrVisMiniVec3d &set(const BaseVec &xy, DataType _z)
172 { BaseVec::x = xy.x; BaseVec::y = xy.y; z = _z; return *this; }
173 template <typename VecType>
174 OdTrVisMiniVec3d &set(const VecType &vec)
175 { BaseVec::x = (DataType)vec.x; BaseVec::y = (DataType)vec.y; z = (DataType)vec.z; return *this; }
176
177 // Getters
178 DataType operator [](int nAxis) const
179 { return (!nAxis) ? BaseVec::x : ((nAxis > 1) ? z : BaseVec::y); }
180 DataType &operator [](int nAxis)
181 { return (!nAxis) ? BaseVec::x : ((nAxis > 1) ? z : BaseVec::y); }
182
183 // Comparators
184 bool operator ==(const OdTrVisMiniVec3d &vec) const
185 { return BaseVec::eqTol(BaseVec::x - vec.x) && BaseVec::eqTol(BaseVec::y - vec.y) && BaseVec::eqTol(z - vec.z); }
186 bool operator !=(const OdTrVisMiniVec3d &vec) const
187 { return !BaseVec::eqTol(BaseVec::x - vec.x) || !BaseVec::eqTol(BaseVec::y - vec.y) || !BaseVec::eqTol(z - vec.z); }
188
189 // Converters
190 operator OdGePoint3d() const { return OdGePoint3d(BaseVec::x, BaseVec::y, z); }
191 operator OdGeVector3d() const { return OdGeVector3d(BaseVec::x, BaseVec::y, z); }
192
193 // Basic math operators
195 { return OdTrVisMiniVec3d(BaseVec::x + vec.x, BaseVec::y + vec.y, z + vec.z); }
197 { BaseVec::x += vec.x; BaseVec::y += vec.y; z += vec.z; return *this; }
199 { return OdTrVisMiniVec3d(BaseVec::x - vec.x, BaseVec::y - vec.y, z - vec.z); }
201 { BaseVec::x -= vec.x; BaseVec::y -= vec.y; z -= vec.z; return *this; }
202
203 // Dot/cross product
204 DataType operator *(const OdTrVisMiniVec3d &vec) const
205 { return BaseVec::x * vec.x + BaseVec::y * vec.y + z * vec.z; }
207 { return OdTrVisMiniVec3d(BaseVec::y * vec.z - z * vec.y, z * vec.x - BaseVec::x * vec.z, BaseVec::x * vec.y - BaseVec::y * vec.x); }
208
209 // Scale operators
210 friend OdTrVisMiniVec3d operator *(const OdTrVisMiniVec3d &vec, DataType val)
211 { return OdTrVisMiniVec3d(vec.x * val, vec.y * val, vec.z * val); }
212 friend OdTrVisMiniVec3d operator *(DataType val, const OdTrVisMiniVec3d &vec)
213 { return OdTrVisMiniVec3d(val * vec.x, val * vec.y, val * vec.z); }
215 { BaseVec::x *= val; BaseVec::y *= val; z *= val; return *this; }
216 friend OdTrVisMiniVec3d operator /(const OdTrVisMiniVec3d &vec, DataType val)
217 { return OdTrVisMiniVec3d(vec.x / val, vec.y / val, vec.z / val); }
218 friend OdTrVisMiniVec3d operator /(DataType val, const OdTrVisMiniVec3d &vec)
219 { return OdTrVisMiniVec3d(val / vec.x, val / vec.y, val / vec.z); }
221 { BaseVec::x /= val; BaseVec::y /= val; z /= val; return *this; }
222
223 // Negate operator
226
227 // Component-wise operators
229 { return OdTrVisMiniVec3d(BaseVec::x * vec.x, BaseVec::y * vec.y, z * vec.z); }
231 { BaseVec::x *= vec.x; BaseVec::y *= vec.y; z *= vec.z; return *this; }
233 { return OdTrVisMiniVec3d(BaseVec::x / vec.x, BaseVec::y / vec.y, z / vec.z); }
235 { BaseVec::x /= vec.x; BaseVec::y /= vec.y; z /= vec.z; return *this; }
236
237 // Null operator
239 { BaseVec::x = BaseVec::y = z = 0.0f; return *this; }
240 bool isNull(DataType eps = 1.e-8f) const
241 { return BaseVec::eqTol(BaseVec::x, eps) && BaseVec::eqTol(BaseVec::y, eps) && BaseVec::eqTol(z, eps); }
242
243 // Length operator
244 DataType length2() const
245 { return BaseVec::x * BaseVec::x + BaseVec::y * BaseVec::y + z * z; }
246 DataType length() const
247 { return (DataType)sqrt(length2()); }
248
249 // Normalization
251 { return OdTrVisMiniVec3d(*this).normalize(); }
252 OdTrVisMiniVec3d &normalize(DataType eps = 1.e-8f)
253 { DataType rd = length();
254 if (BaseVec::eqTol(rd, eps))
255 setNull();
256 else
257 rd = 1.0f / rd,
258 *this *= rd;
259 return *this;
260 }
261
262 // Min/max operators
263 DataType minimum() const
264 { return odmin(BaseVec::x, odmin(BaseVec::y, z)); }
265 DataType maximum() const
266 { return odmax(BaseVec::x, odmax(BaseVec::y, z)); }
267
268 // Reflection vector
270 { return *this = (*this * (-2.0f * (*this * n))).mul(n) + *this; }
271
272 // Refraction vector
273 OdTrVisMiniVec3d &refract(const OdTrVisMiniVec3d &n, DataType eta, DataType eps = 1.e-8f)
274 { const DataType idot = *this * n;
275 const DataType k = 1.0f - eta * eta * (1.0f - idot * idot);
276 if (BaseVec::eqTol(k, eps))
277 return setNull();
278 else
279 return *this = *this * eta - (n * (eta * idot + (DataType)sqrt(k)));
280 }
281};
282
283// Type definitions.
284
287
290
291// Current main matrix definition.
292
295
296#include "TD_PackPop.h"
297
298#endif // ODTRVISVECTOR
#define odmin(X, Y)
Definition: OdPlatform.h:34
#define odmax(X, Y)
Definition: OdPlatform.h:35
OdTrVisVector2df OdTrVisVector2d
Definition: TrVisVector.h:293
OdTrVisMiniVec3d< float > OdTrVisVector3df
Definition: TrVisVector.h:288
OdTrVisMiniVec3d< double > OdTrVisVector3dd
Definition: TrVisVector.h:289
OdTrVisVector3df OdTrVisVector
Definition: TrVisVector.h:294
OdTrVisMiniVec2d< float > OdTrVisVector2df
Definition: TrVisVector.h:285
OdTrVisMiniVec2d< double > OdTrVisVector2dd
Definition: TrVisVector.h:286
GLfloat GLfloat GLfloat z
Definition: gles2_ext.h:318
GLfloat x
Definition: gles2_ext.h:314
GLfloat GLfloat y
Definition: gles2_ext.h:316
OdTrVisMiniVec2d & setMul(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:112
DataType length() const
Definition: TrVisVector.h:128
bool operator==(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:66
OdTrVisMiniVec2d & operator*=(DataType val)
Definition: TrVisVector.h:96
friend OdTrVisMiniVec2d operator*(const OdTrVisMiniVec2d &vec, DataType val)
Definition: TrVisVector.h:92
OdTrVisMiniVec2d & operator-=(const OdTrVisMiniVec2d &vec)
Definition: TrVisVector.h:82
bool operator!=(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:68
OdTrVisMiniVec2d & operator+=(const OdTrVisMiniVec2d &vec)
Definition: TrVisVector.h:78
DataType operator^(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:88
DataType EntryType
Definition: TrVisVector.h:41
OdTrVisMiniVec2d(DataType _x, DataType _y)
Definition: TrVisVector.h:48
OdTrVisMiniVec2d div(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:114
bool isNull(DataType eps=1.e-8f) const
Definition: TrVisVector.h:122
OdTrVisMiniVec2d(const VecType &vec)
Definition: TrVisVector.h:50
OdTrVisMiniVec2d & negate()
Definition: TrVisVector.h:107
DataType operator[](int nAxis) const
Definition: TrVisVector.h:60
DataType minimum() const
Definition: TrVisVector.h:145
static bool eqTol(double val, double eps=1.e-10)
Definition: TrVisVector.h:44
OdTrVisMiniVec2d & setNull()
Definition: TrVisVector.h:120
DataType maximum() const
Definition: TrVisVector.h:147
DataType length2() const
Definition: TrVisVector.h:126
OdTrVisMiniVec2d operator+(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:76
OdTrVisMiniVec2d operator~() const
Definition: TrVisVector.h:132
OdTrVisMiniVec2d & set(const VecType &vec)
Definition: TrVisVector.h:56
OdTrVisMiniVec2d & setDiv(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:116
static bool eqTol(float val, float eps=1.e-8f)
Definition: TrVisVector.h:43
OdTrVisMiniVec2d mul(const OdTrVisMiniVec2d &vec) const
Definition: TrVisVector.h:110
OdTrVisMiniVec2d operator-() const
Definition: TrVisVector.h:106
OdTrVisMiniVec2d & set(DataType _x, DataType _y)
Definition: TrVisVector.h:53
OdTrVisMiniVec2d & operator/=(DataType val)
Definition: TrVisVector.h:102
friend OdTrVisMiniVec2d operator/(const OdTrVisMiniVec2d &vec, DataType val)
Definition: TrVisVector.h:98
OdTrVisMiniVec2d & normalize(DataType eps=1.e-8f)
Definition: TrVisVector.h:134
DataType length() const
Definition: TrVisVector.h:246
OdTrVisMiniVec3d & setMul(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:230
friend OdTrVisMiniVec3d operator*(const OdTrVisMiniVec3d &vec, DataType val)
Definition: TrVisVector.h:210
OdTrVisMiniVec3d mul(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:228
bool operator!=(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:186
OdTrVisMiniVec3d(const BaseVec &xy, DataType _z)
Definition: TrVisVector.h:164
DataType length2() const
Definition: TrVisVector.h:244
OdTrVisMiniVec3d & operator/=(DataType val)
Definition: TrVisVector.h:220
OdTrVisMiniVec3d & operator+=(const OdTrVisMiniVec3d &vec)
Definition: TrVisVector.h:196
friend OdTrVisMiniVec3d operator/(const OdTrVisMiniVec3d &vec, DataType val)
Definition: TrVisVector.h:216
OdTrVisMiniVec3d(const VecType &vec)
Definition: TrVisVector.h:166
OdTrVisMiniVec3d & reflect(const OdTrVisMiniVec3d &n)
Definition: TrVisVector.h:269
DataType maximum() const
Definition: TrVisVector.h:265
OdTrVisMiniVec3d & refract(const OdTrVisMiniVec3d &n, DataType eta, DataType eps=1.e-8f)
Definition: TrVisVector.h:273
DataType minimum() const
Definition: TrVisVector.h:263
DataType operator[](int nAxis) const
Definition: TrVisVector.h:178
bool isNull(DataType eps=1.e-8f) const
Definition: TrVisVector.h:240
bool operator==(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:184
OdTrVisMiniVec3d & set(const BaseVec &xy, DataType _z)
Definition: TrVisVector.h:171
OdTrVisMiniVec3d & set(const VecType &vec)
Definition: TrVisVector.h:174
OdTrVisMiniVec2d< DataType > BaseVec
Definition: TrVisVector.h:160
OdTrVisMiniVec3d & operator-=(const OdTrVisMiniVec3d &vec)
Definition: TrVisVector.h:200
OdTrVisMiniVec3d & setNull()
Definition: TrVisVector.h:238
OdTrVisMiniVec3d operator-() const
Definition: TrVisVector.h:224
OdTrVisMiniVec3d(DataType _x, DataType _y, DataType _z)
Definition: TrVisVector.h:163
OdTrVisMiniVec3d & setDiv(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:234
OdTrVisMiniVec3d & operator*=(DataType val)
Definition: TrVisVector.h:214
OdTrVisMiniVec3d & normalize(DataType eps=1.e-8f)
Definition: TrVisVector.h:252
OdTrVisMiniVec3d & set(DataType _x, DataType _y, DataType _z)
Definition: TrVisVector.h:169
OdTrVisMiniVec3d operator~() const
Definition: TrVisVector.h:250
OdTrVisMiniVec3d div(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:232
OdTrVisMiniVec3d operator+(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:194
OdTrVisMiniVec3d & negate()
Definition: TrVisVector.h:225
OdTrVisMiniVec3d operator^(const OdTrVisMiniVec3d &vec) const
Definition: TrVisVector.h:206