VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtVector4.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2023 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
11 #include <vrvMath/DtCommonTypes.h>
12 #include <vrvMath/DtMath.h>
13 #include <vrvMath/DtAssert.h>
14 
15 #include <list>
16 #include <vector>
17 #include <iostream>
18 
19 namespace makVrv
20 {
21 
22  template <class T> class DtVector3;
23 
26  template <class T>
27  class DtVector4
28  {
29  public:
31  DtVector4() : x(0), y(0), z(0), w(0) {}
33  DtVector4(T _x, T _y, T _z, T _w) : x(_x), y (_y), z (_z), w (_w) {}
35  DtVector4(const DtVector3<T>& rhs, T _w)
36  : x(rhs.x), y(rhs.y), z(rhs.z), w(_w) {}
37 
40  template <class T1>
41  DtVector4(const T1& v): x(v.x), y(v.y), z(v.z), w(v.w){}
42 
45  {
46  //intentional nop
47  }
48  public:
50  const void* ptr(void) const{return &x;}
51 
53  const T* typePtr(void) const { return &x; }
54 
56  DtVector4 operator-(void) const
57  {
58  return DtVector4(-x,-y,-z,-w);
59  }
60 
62  DtVector4 operator+(T fScalar) const;
64  DtVector4 operator-(T fScalar) const;
66  DtVector4 operator*(T fScalar) const;
68  DtVector4 operator/(T fScalar) const;
69 
71  DtVector4& operator+=(T fScalar);
73  DtVector4& operator-=(T fScalar);
75  DtVector4& operator*=(T fScalar);
77  DtVector4& operator/=(T fScalar);
78 
80  DtVector4& operator+=(const DtVector4& rhs);
81 
83  DtVector4 operator+(const DtVector4& rhs) const;
84 
86  DtVector4 operator-(const DtVector4& rhs) const;
87 
89  bool isEqual(const DtVector4& rhs, T tolerance) const;
90 
92  T operator[](size_t index) const;
94  T& operator[](size_t index);
95 
97  bool operator==(const DtVector4& rhs) const;
98 
100  bool operator!=(const DtVector4& rhs) const;
101 
103  T length(void) const;
105  T squaredLength(void) const;
106 
107  DtVector4 componentMultiply(const DtVector4& rhs) const;
108 
110  T dotProduct(const DtVector4& rhs) const;
111 
113  void set(T x, T y, T z, T w);
114 
115  public:
116  static size_t sizeInBytes(void);
117  public:
118  T x, y, z, w;
119  public:
120  static const DtVector4 theZeroVector;
121  static const DtVector4 theUnitScale;
122  };
123 
125  typedef std::list<Vector4_32> Vector4_32_List;
126  typedef std::vector<Vector4_32> Vector4_32_Vector;
127 
128  template <class T>
130 
131  template <class T>
133 
134  template <class T>
136  {
137  return DtVector4<T>(x+fScalar, y+fScalar, z+fScalar, w+fScalar);
138  }
139  template <class T>
141  {
142  return DtVector4<T>(x-fScalar, y-fScalar, z-fScalar, w-fScalar);
143  }
144 
145  template <class T>
147  {
148  return DtVector4<T>(x*fScalar, y*fScalar, z*fScalar, w*fScalar);
149  }
150 
151  template <class T>
153  {
154  T OneByfScalar = T(1.0)/fScalar;
155  return DtVector4<T>(x*OneByfScalar, y*OneByfScalar, z*OneByfScalar, w*OneByfScalar);
156  }
157 
158 
159  template <class T>
160  bool DtVector4<T>::isEqual(const DtVector4<T>& rhs, T tolerance) const
161  {
162  return DtMath::isEqual(this->x, rhs.x,tolerance)
163  && DtMath::isEqual(this->y, rhs.y,tolerance)
164  && DtMath::isEqual(this->z, rhs.z,tolerance)
165  ;
166  // PPP: What about the w component???
167  }
168 
169  template <class T>
170  T DtVector4<T>::operator[](size_t index) const
171  {
172  ASSERT_PREDICATE(index<=3);
173  const T* ptrT = static_cast<const T*>(ptr());
174  return ptrT[index];
175  }
176 
177  template <class T>
178  T& DtVector4<T>::operator[](size_t index)
179  {
180  ASSERT_PREDICATE(index<=3);
181  T* ptrT = &x;
182  return ptrT[index];
183  }
184 
185  template <class T>
187  {
188  x += fScalar;
189  y += fScalar;
190  z += fScalar;
191  w += fScalar;
192  return *this;
193  }
194 
195  template <class T>
197  {
198  x -= fScalar;
199  y -= fScalar;
200  z -= fScalar;
201  w -= fScalar;
202  return *this;
203  }
204 
205  template <class T>
207  {
208  x *= fScalar;
209  y *= fScalar;
210  z *= fScalar;
211  w *= fScalar;
212  return *this;
213  }
214 
215  template <class T>
217  {
218  return this->operator*=(T(1.0)/fScalar);
219  }
220 
221  template <class T>
222  bool DtVector4<T>::operator==(const DtVector4<T>& rhs) const
223  {
224  return x == rhs.x&&y == rhs.y && z == rhs.z && w==rhs.w;
225  }
226 
227  template <class T>
228  bool DtVector4<T>::operator!=(const DtVector4<T>& rhs) const
229  {
230  const DtVector4<T>& lhs = *this;
231  return !(lhs == rhs);
232  }
233 
234  template<class T>
235  inline std::ostream& operator <<( std::ostream& o, const DtVector4<T>& v )
236  {
237  o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
238  return o;
239  }
240 
241  template <class T>
243  {
244  return 4*sizeof(T);
245  }
246 
247  template <class T>
248  T DtVector4<T>::length(void) const
249  {
250  return DtMath::Sqrt(x * x + y * y + z * z + w * w);
251  }
252 
253  template <class T>
255  {
256  return x * x + y * y + z * z + w*w;
257  }
258 
259  template <class T>
261  {
262  return DtVector4<T>(x + rhs.x,y + rhs.y,z + rhs.z,w + rhs.w);
263  }
264 
265  template <class T>
267  {
268  return DtVector4<T>(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w);
269  }
270 
271  template <class T>
273  {
274  return DtVector4<T>(x * rhs.x, y * rhs.y, z * rhs.z, w * rhs.w);
275  }
276 
277  template <class T>
279  {
280  return x * rhs.x + y * rhs.y + z * rhs.z + w * rhs.w;
281  }
282 
283  template <class T>
285  {
286  x += rhs.x;
287  y += rhs.y;
288  z += rhs.z;
289  w += rhs.w;
290  return *this;
291  }
292 
293  template <class T>
294  void DtVector4<T>::set(T _x, T _y, T _z, T _w)
295  {
296  x = _x;
297  y = _y;
298  z = _z;
299  w = _w;
300  }
301 
305  typedef std::list<Vector4_32> Vector4_32_List;
306  typedef std::vector<Vector4_32> Vector4_32_Vector;
307 
309  typedef std::list<Vector4_64> Vector4_64_List;
310  typedef std::vector<Vector4_64> Vector4_64_Vector;
311 
312 } //namespace makVrv
T length(void) const
get the length of this vector
Definition: DtVector4.h:248
const void * ptr(void) const
access the pointer to the data
Definition: DtVector4.h:50
DtVector4< uint32 > Vector4_uint32
Definition: DtVector4.h:304
DtVector4 & operator-=(T fScalar)
subtract a scalar from this vector
Definition: DtVector4.h:196
~DtVector4()
DTOR.
Definition: DtVector4.h:44
T x
Definition: DtVector4.h:118
static const DtVector4 theUnitScale
Definition: DtVector4.h:121
const T * typePtr(void) const
access the pointer to the data, with the type of the data
Definition: DtVector4.h:53
T dotProduct(const DtVector4 &rhs) const
get the dot product of this vector and rhs
Definition: DtVector4.h:278
bool operator==(const DtVector4 &rhs) const
equality
Definition: DtVector4.h:222
std::list< Vector4_32 > Vector4_32_List
Definition: DtVector4.h:125
DtVector4(const DtVector3< T > &rhs, T _w)
CTOR.
Definition: DtVector4.h:35
static T Sqrt(T val)
Standard math routines.
Definition: DtMath.h:58
bool operator!=(const DtVector4 &rhs) const
inequality
Definition: DtVector4.h:228
DtVector4 & operator*=(T fScalar)
multiply a scalar to this vector
Definition: DtVector4.h:206
DtVector4< int32 > Vector4_int
Definition: DtVector4.h:303
DtVector4 operator+(T fScalar) const
add a scalar to this vector
Definition: DtVector4.h:135
DtVector4 componentMultiply(const DtVector4 &rhs) const
Definition: DtVector4.h:272
DtVector4 operator/(T fScalar) const
divide this vector by a scalar
Definition: DtVector4.h:152
4 dimensional vector
Definition: DtMath.h:22
std::vector< Vector4_32 > Vector4_32_Vector
Definition: DtVector4.h:126
Math utilities.
T operator[](size_t index) const
access a component of this vector
Definition: DtVector4.h:170
static const DtVector4 theZeroVector
Definition: DtVector4.h:120
DtVector4(const T1 &v)
CTOR construct from type with constructable components.
Definition: DtVector4.h:41
T z
Definition: DtVector4.h:118
std::list< Vector4_64 > Vector4_64_List
Definition: DtVector4.h:309
DtVector4 & operator+=(T fScalar)
add a scalar to this vector
Definition: DtVector4.h:186
bool isEqual(const DtVector4 &rhs, T tolerance) const
is this vector == to rhs within the tolerance/epsilon
Definition: DtVector4.h:160
static size_t sizeInBytes(void)
Definition: DtVector4.h:242
T w
Definition: DtVector4.h:118
DtVector4 operator-(void) const
get the negated version of this vector
Definition: DtVector4.h:56
static bool isEqual(int32 lhs, int32 rhs, int32 tolerance=std::numeric_limits< int32 >::epsilon())
Test equality with tolerance.
std::vector< Vector4_64 > Vector4_64_Vector
Definition: DtVector4.h:310
void set(T x, T y, T z, T w)
set values
Definition: DtVector4.h:294
DtVector4(T _x, T _y, T _z, T _w)
CTOR.
Definition: DtVector4.h:33
2 dimensional vector
Definition: DtMath.h:21
DtVector4< float32 > Vector4_32
Definition: DtVector4.h:124
DtVector4()
CTOR.
Definition: DtVector4.h:31
DtVector4 operator*(T fScalar) const
multiply a scalar to this vector
Definition: DtVector4.h:146
#define ASSERT_PREDICATE(p)
Definition: DtAssert.h:28
assert macros
T squaredLength(void) const
get the length squared of this vector
Definition: DtVector4.h:254
DtVector4< float64 > Vector4_64
Definition: DtVector4.h:308
T y
Definition: DtVector4.h:118
DtVector4 & operator/=(T fScalar)
divide this vector by a scalar
Definition: DtVector4.h:216

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)