VR-Forces 4.7 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) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
13 
14 #include <list>
15 #include <vector>
16 
17 namespace makVrv {
18 
21  template <class T>
22  class DtVector4
23  {
24  public:
28  DtVector4(T _x, T _y, T _z, T _w): x(_x), y (_y), z (_z), w (_w){}
30  DtVector4(const DtVector3<T>& rhs, T _w)
31  : x(rhs.x), y(rhs.y), z(rhs.z), w(_w){}
32 
35 
36  const void* ptr(void) const{return &x;}
37 
38  DtVector4 operator-(void) const {return DtVector4(-x,-y,-z,-w);}
39 
40  DtVector4 operator+(T fScalar) const;
41  DtVector4 operator-(T fScalar) const;
42  DtVector4 operator*(T fScalar) const;
43  DtVector4 operator/(T fScalar) const;
44 
45  DtVector4& operator+=(T fScalar);
46  DtVector4& operator-=(T fScalar);
47  DtVector4& operator*=(T fScalar);
48  DtVector4& operator/=(T fScalar);
49 
50  bool isEqual(const DtVector4& rhs, T tolerance) const;
51 
52  T operator[](size_t index) const;
53  T& operator[](size_t index);
54 
55  T x, y, z, w;
56 
57  static size_t sizeInBytes(void);
58  };
59 
61  typedef std::list<Vector4_32> Vector4_32_List;
62  typedef std::vector<Vector4_32> Vector4_32_Vector;
63 
64  template <class T>
66  {
67  return DtVector4<T>(x+fScalar, y+fScalar, z+fScalar, w+fScalar);
68  }
69  template <class T>
71  {
72  return DtVector4<T>(x-fScalar, y-fScalar, z-fScalar, w-fScalar);
73  }
74 
75  template <class T>
77  {
78  return DtVector4<T>(x*fScalar, y*fScalar, z*fScalar, w*fScalar);
79  }
80 
81  template <class T>
83  {
84  T OneByfScalar = T(1.0)/fScalar;
85  return DtVector4<T>(x*OneByfScalar, y*OneByfScalar, z*OneByfScalar, w*OneByfScalar);
86  }
87 
88 
89  template <class T>
90  bool DtVector4<T>::isEqual(const DtVector4<T>& rhs, T tolerance) const
91  {
92  return DtMath::isEqual(this->x, rhs.x,tolerance)
93  && DtMath::isEqual(this->y, rhs.y,tolerance)
94  && DtMath::isEqual(this->z, rhs.z,tolerance)
95  ;
96  // PPP: What about the w component???
97  }
98 
99  template <class T>
100  T DtVector4<T>::operator[](size_t index) const
101  {
102  ASSERT_PREDICATE(index<=3);
103  const T* ptrT = static_cast<const T*>(ptr());
104  return ptrT[index];
105  }
106 
107  template <class T>
108  T& DtVector4<T>::operator[](size_t index)
109  {
110  ASSERT_PREDICATE(index<=3);
111  T* ptrT = &x;
112  return ptrT[index];
113  }
114 
115  template <class T>
117  {
118  x += fScalar;
119  y += fScalar;
120  z += fScalar;
121  w += fScalar;
122  return *this;
123  }
124 
125  template <class T>
127  {
128  x -= fScalar;
129  y -= fScalar;
130  z -= fScalar;
131  w -= fScalar;
132  return *this;
133  }
134 
135  template <class T>
137  {
138  x *= fScalar;
139  y *= fScalar;
140  z *= fScalar;
141  w *= fScalar;
142  return *this;
143  }
144 
145  template <class T>
147  {
148  return this->operator*=(T(1.0)/fScalar);
149  }
150 
151  template<class T>
152  inline std::ostream& operator <<
153  ( std::ostream& o, const DtVector4<T>& v )
154  {
155  o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
156  return o;
157  }
158 
159  template <class T>
161  {
162  return 4*sizeof(T);
163  }
164 
165 } //namespace makVrv

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)