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

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)