VR-Forces 4.8 Class Documentation
 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) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
14 
15 #include <list>
16 #include <vector>
17 
18 namespace makVrv
19 {
20 
23  template <class T>
24  class DtVector4
25  {
26  public:
28  DtVector4() : x(0), y(0), z(0), w(0) {}
30  DtVector4(T _x, T _y, T _z, T _w) : x(_x), y (_y), z (_z), w (_w) {}
32  DtVector4(const DtVector3<T>& rhs, T _w)
33  : x(rhs.x), y(rhs.y), z(rhs.z), w(_w) {}
34 
37  template <class T1>
38  DtVector4(const T1& v): x(v.x), y(v.y), z(v.z), w(v.w){}
39 
42 
43  const void* ptr(void) const{return &x;}
44 
45  DtVector4 operator-(void) const {return DtVector4(-x,-y,-z,-w);}
46 
47  DtVector4 operator+(T fScalar) const;
48  DtVector4 operator-(T fScalar) const;
49  DtVector4 operator*(T fScalar) const;
50  DtVector4 operator/(T fScalar) const;
51 
52  DtVector4& operator+=(T fScalar);
53  DtVector4& operator-=(T fScalar);
54  DtVector4& operator*=(T fScalar);
55  DtVector4& operator/=(T fScalar);
56 
57  bool isEqual(const DtVector4& rhs, T tolerance) const;
58 
59  T operator[](size_t index) const;
60  T& operator[](size_t index);
61 
62  T x, y, z, w;
63 
64  static size_t sizeInBytes(void);
65  };
66 
68  typedef std::list<Vector4_32> Vector4_32_List;
69  typedef std::vector<Vector4_32> Vector4_32_Vector;
70 
71  template <class T>
73  {
74  return DtVector4<T>(x+fScalar, y+fScalar, z+fScalar, w+fScalar);
75  }
76  template <class T>
78  {
79  return DtVector4<T>(x-fScalar, y-fScalar, z-fScalar, w-fScalar);
80  }
81 
82  template <class T>
84  {
85  return DtVector4<T>(x*fScalar, y*fScalar, z*fScalar, w*fScalar);
86  }
87 
88  template <class T>
90  {
91  T OneByfScalar = T(1.0)/fScalar;
92  return DtVector4<T>(x*OneByfScalar, y*OneByfScalar, z*OneByfScalar, w*OneByfScalar);
93  }
94 
95 
96  template <class T>
97  bool DtVector4<T>::isEqual(const DtVector4<T>& rhs, T tolerance) const
98  {
99  return DtMath::isEqual(this->x, rhs.x,tolerance)
100  && DtMath::isEqual(this->y, rhs.y,tolerance)
101  && DtMath::isEqual(this->z, rhs.z,tolerance)
102  ;
103  // PPP: What about the w component???
104  }
105 
106  template <class T>
107  T DtVector4<T>::operator[](size_t index) const
108  {
109  ASSERT_PREDICATE(index<=3);
110  const T* ptrT = static_cast<const T*>(ptr());
111  return ptrT[index];
112  }
113 
114  template <class T>
115  T& DtVector4<T>::operator[](size_t index)
116  {
117  ASSERT_PREDICATE(index<=3);
118  T* ptrT = &x;
119  return ptrT[index];
120  }
121 
122  template <class T>
124  {
125  x += fScalar;
126  y += fScalar;
127  z += fScalar;
128  w += fScalar;
129  return *this;
130  }
131 
132  template <class T>
134  {
135  x -= fScalar;
136  y -= fScalar;
137  z -= fScalar;
138  w -= fScalar;
139  return *this;
140  }
141 
142  template <class T>
144  {
145  x *= fScalar;
146  y *= fScalar;
147  z *= fScalar;
148  w *= fScalar;
149  return *this;
150  }
151 
152  template <class T>
154  {
155  return this->operator*=(T(1.0)/fScalar);
156  }
157 
158  template<class T>
159  inline std::ostream& operator <<( std::ostream& o, const DtVector4<T>& v )
160  {
161  o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
162  return o;
163  }
164 
165  template <class T>
167  {
168  return 4*sizeof(T);
169  }
170 
171 } //namespace makVrv
const void * ptr(void) const
Definition: DtVector4.h:43
DtVector4 & operator-=(T fScalar)
Definition: DtVector4.h:133
~DtVector4()
DTOR.
Definition: DtVector4.h:41
T x
Definition: DtVector4.h:62
std::list< Vector4_32 > Vector4_32_List
Definition: DtVector4.h:68
DtVector4(const DtVector3< T > &rhs, T _w)
CTOR.
Definition: DtVector4.h:32
DtVector4 & operator*=(T fScalar)
Definition: DtVector4.h:143
3 dimensional vector
DtVector4 operator+(T fScalar) const
Definition: DtVector4.h:72
DtVector4 operator/(T fScalar) const
Definition: DtVector4.h:89
4 dimensional vector
Definition: DtVector4.h:24
std::vector< Vector4_32 > Vector4_32_Vector
Definition: DtVector4.h:69
T operator[](size_t index) const
Definition: DtVector4.h:107
DtVector4(const T1 &v)
CTOR construct from type with constructable components.
Definition: DtVector4.h:38
T z
Definition: DtVector4.h:62
DtVector4 & operator+=(T fScalar)
Definition: DtVector4.h:123
bool isEqual(const DtVector4 &rhs, T tolerance) const
Definition: DtVector4.h:97
static size_t sizeInBytes(void)
Definition: DtVector4.h:166
T w
Definition: DtVector4.h:62
DtVector4 operator-(void) const
Definition: DtVector4.h:45
static bool isEqual(int32 lhs, int32 rhs, int32 tolerance=std::numeric_limits< int32 >::epsilon())
Test equality with tolerance.
DtVector4(T _x, T _y, T _z, T _w)
CTOR.
Definition: DtVector4.h:30
2 dimensional vector
Definition: DtVector3.h:26
DtVector4< float32 > Vector4_32
Definition: DtVector4.h:67
DtVector4()
CTOR.
Definition: DtVector4.h:28
DtVector4 operator*(T fScalar) const
Definition: DtVector4.h:83
#define ASSERT_PREDICATE(p)
Definition: DtAssert.h:28
assert macros
T y
Definition: DtVector4.h:62
DtVector4 & operator/=(T fScalar)
Definition: DtVector4.h:153

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)