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) const;
81 
83  DtVector4 operator-(const DtVector4& rhs) const;
84 
86  bool isEqual(const DtVector4& rhs, T tolerance) const;
87 
89  T operator[](size_t index) const;
91  T& operator[](size_t index);
92 
94  bool operator==(const DtVector4& rhs) const;
95 
97  bool operator!=(const DtVector4& rhs) const;
98 
100  T length(void) const;
102  T squaredLength(void) const;
103 
104  DtVector4 componentMultiply(const DtVector4& rhs) const;
105 
107  T dotProduct(const DtVector4& rhs) const;
108 
109 
110  public:
111  static size_t sizeInBytes(void);
112  public:
113  T x, y, z, w;
114  };
115 
117  typedef std::list<Vector4_32> Vector4_32_List;
118  typedef std::vector<Vector4_32> Vector4_32_Vector;
119 
120  template <class T>
122  {
123  return DtVector4<T>(x+fScalar, y+fScalar, z+fScalar, w+fScalar);
124  }
125  template <class T>
127  {
128  return DtVector4<T>(x-fScalar, y-fScalar, z-fScalar, w-fScalar);
129  }
130 
131  template <class T>
133  {
134  return DtVector4<T>(x*fScalar, y*fScalar, z*fScalar, w*fScalar);
135  }
136 
137  template <class T>
139  {
140  T OneByfScalar = T(1.0)/fScalar;
141  return DtVector4<T>(x*OneByfScalar, y*OneByfScalar, z*OneByfScalar, w*OneByfScalar);
142  }
143 
144 
145  template <class T>
146  bool DtVector4<T>::isEqual(const DtVector4<T>& rhs, T tolerance) const
147  {
148  return DtMath::isEqual(this->x, rhs.x,tolerance)
149  && DtMath::isEqual(this->y, rhs.y,tolerance)
150  && DtMath::isEqual(this->z, rhs.z,tolerance)
151  ;
152  // PPP: What about the w component???
153  }
154 
155  template <class T>
156  T DtVector4<T>::operator[](size_t index) const
157  {
158  ASSERT_PREDICATE(index<=3);
159  const T* ptrT = static_cast<const T*>(ptr());
160  return ptrT[index];
161  }
162 
163  template <class T>
164  T& DtVector4<T>::operator[](size_t index)
165  {
166  ASSERT_PREDICATE(index<=3);
167  T* ptrT = &x;
168  return ptrT[index];
169  }
170 
171  template <class T>
173  {
174  x += fScalar;
175  y += fScalar;
176  z += fScalar;
177  w += fScalar;
178  return *this;
179  }
180 
181  template <class T>
183  {
184  x -= fScalar;
185  y -= fScalar;
186  z -= fScalar;
187  w -= fScalar;
188  return *this;
189  }
190 
191  template <class T>
193  {
194  x *= fScalar;
195  y *= fScalar;
196  z *= fScalar;
197  w *= fScalar;
198  return *this;
199  }
200 
201  template <class T>
203  {
204  return this->operator*=(T(1.0)/fScalar);
205  }
206 
207  template <class T>
208  bool DtVector4<T>::operator==(const DtVector4<T>& rhs) const
209  {
210  return x == rhs.x&&y == rhs.y && z == rhs.z && w==rhs.w;
211  }
212 
213  template <class T>
214  bool DtVector4<T>::operator!=(const DtVector4<T>& rhs) const
215  {
216  const DtVector4<T>& lhs = *this;
217  return !(lhs == rhs);
218  }
219 
220  template<class T>
221  inline std::ostream& operator <<( std::ostream& o, const DtVector4<T>& v )
222  {
223  o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
224  return o;
225  }
226 
227  template <class T>
229  {
230  return 4*sizeof(T);
231  }
232 
233  template <class T>
234  T DtVector4<T>::length(void) const
235  {
236  return DtMath::Sqrt(x * x + y * y + z * z + w * w);
237  }
238 
239  template <class T>
241  {
242  return x * x + y * y + z * z + w*w;
243  }
244 
245  template <class T>
247  {
248  return DtVector4<T>(x + rhs.x,y + rhs.y,z + rhs.z,w + rhs.w);
249  }
250 
251  template <class T>
253  {
254  return DtVector4<T>(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w);
255  }
256 
257  template <class T>
259  {
260  return DtVector4<T>(x * rhs.x, y * rhs.y, z * rhs.z, w * rhs.w);
261  }
262 
263  template <class T>
265  {
266  return x * rhs.x + y * rhs.y + z * rhs.z + w * rhs.w;
267  }
268 
272  typedef std::list<Vector4_32> Vector4_32_List;
273  typedef std::vector<Vector4_32> Vector4_32_Vector;
274 
276  typedef std::list<Vector4_64> Vector4_64_List;
277  typedef std::vector<Vector4_64> Vector4_64_Vector;
278 
279 } //namespace makVrv
T length(void) const
get the length of this vector
Definition: DtVector4.h:234
const void * ptr(void) const
access the pointer to the data
Definition: DtVector4.h:50
DtVector4< uint32 > Vector4_uint32
Definition: DtVector4.h:271
DtVector4 & operator-=(T fScalar)
subtract a scalar from this vector
Definition: DtVector4.h:182
~DtVector4()
DTOR.
Definition: DtVector4.h:44
T x
Definition: DtVector4.h:113
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:264
bool operator==(const DtVector4 &rhs) const
equality
Definition: DtVector4.h:208
std::list< Vector4_32 > Vector4_32_List
Definition: DtVector4.h:117
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:214
DtVector4 & operator*=(T fScalar)
multiply a scalar to this vector
Definition: DtVector4.h:192
DtVector4< int32 > Vector4_int
Definition: DtVector4.h:270
DtVector4 operator+(T fScalar) const
add a scalar to this vector
Definition: DtVector4.h:121
DtVector4 componentMultiply(const DtVector4 &rhs) const
Definition: DtVector4.h:258
DtVector4 operator/(T fScalar) const
divide this vector by a scalar
Definition: DtVector4.h:138
4 dimensional vector
Definition: DtMath.h:22
std::vector< Vector4_32 > Vector4_32_Vector
Definition: DtVector4.h:118
Math utilities.
T operator[](size_t index) const
access a component of this vector
Definition: DtVector4.h:156
DtVector4(const T1 &v)
CTOR construct from type with constructable components.
Definition: DtVector4.h:41
T z
Definition: DtVector4.h:113
std::list< Vector4_64 > Vector4_64_List
Definition: DtVector4.h:276
DtVector4 & operator+=(T fScalar)
add a scalar to this vector
Definition: DtVector4.h:172
bool isEqual(const DtVector4 &rhs, T tolerance) const
is this vector == to rhs within the tolerance/epsilon
Definition: DtVector4.h:146
static size_t sizeInBytes(void)
Definition: DtVector4.h:228
T w
Definition: DtVector4.h:113
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:277
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:116
DtVector4()
CTOR.
Definition: DtVector4.h:31
DtVector4 operator*(T fScalar) const
multiply a scalar to this vector
Definition: DtVector4.h:132
#define ASSERT_PREDICATE(p)
Definition: DtAssert.h:28
assert macros
T squaredLength(void) const
get the length squared of this vector
Definition: DtVector4.h:240
DtVector4< float64 > Vector4_64
Definition: DtVector4.h:275
T y
Definition: DtVector4.h:113
DtVector4 & operator/=(T fScalar)
divide this vector by a scalar
Definition: DtVector4.h:202

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)