VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtVector4.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
11 #include "DtCommonTypes.h"
12 #include "DtAssert.h"
13 
14 #include <list>
15 #include <vector>
16 
17 #include "DtVector3.h"
18 
19 namespace makVrv {
20 
23  template <class T>
24  class DtVector4
25  {
26  public:
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 
36  virtual ~DtVector4(){}
37 
38  const void* ptr(void) const{return &x;}
39 
40  DtVector4 operator-(void) const {return DtVector4(-x,-y,-z,-w);}
41 
42  DtVector4 operator+(T fScalar) const;
43  DtVector4 operator-(T fScalar) const;
44  DtVector4 operator*(T fScalar) const;
45  DtVector4 operator/(T fScalar) const;
46 
47  DtVector4& operator+=(T fScalar);
48  DtVector4& operator-=(T fScalar);
49  DtVector4& operator*=(T fScalar);
50  DtVector4& operator/=(T fScalar);
51 
52  bool isEqual(const DtVector4& rhs, T tolerance) const;
53 
54  T operator[](size_t index) const;
55  T& operator[](size_t index);
56 
57  T x, y, z, w;
58 
59  static size_t sizeInBytes(void);
60  };
61 
63  typedef std::list<Vector4_32> Vector4_32_List;
64  typedef std::vector<Vector4_32> Vector4_32_Vector;
65 
66  template <class T>
68  {
69  return DtVector4<T>(x+fScalar, y+fScalar, z+fScalar, w+fScalar);
70  }
71  template <class T>
73  {
74  return DtVector4<T>(x-fScalar, y-fScalar, z-fScalar, w-fScalar);
75  }
76 
77  template <class T>
79  {
80  return DtVector4<T>(x*fScalar, y*fScalar, z*fScalar, w*fScalar);
81  }
82 
83  template <class T>
85  {
86  T OneByfScalar = T(1.0)/fScalar;
87  return DtVector4<T>(x*OneByfScalar, y*OneByfScalar, z*OneByfScalar, w*OneByfScalar);
88  }
89 
90 
91  template <class T>
92  bool DtVector4<T>::isEqual(const DtVector4<T>& rhs, T tolerance) const
93  {
94  return DtMath::isEqual(this->x, rhs.x,tolerance)
95  && DtMath::isEqual(this->y, rhs.y,tolerance)
96  && DtMath::isEqual(this->z, rhs.z,tolerance)
97  ;
98  // PPP: What about the w component???
99  }
100 
101  template <class T>
102  T DtVector4<T>::operator[](size_t index) const
103  {
105  const T* ptrT = static_cast<const T*>(ptr());
106  return ptrT[index];
107  }
108 
109  template <class T>
110  T& DtVector4<T>::operator[](size_t index)
111  {
112  ASSERT_PREDICATE(index<=3);
113  T* ptrT = &x;
114  return ptrT[index];
115  }
116 
117  template <class T>
119  {
120  x += fScalar;
121  y += fScalar;
122  z += fScalar;
123  w += fScalar;
124  return *this;
125  }
126 
127  template <class T>
129  {
130  x -= fScalar;
131  y -= fScalar;
132  z -= fScalar;
133  w -= fScalar;
134  return *this;
135  }
136 
137  template <class T>
139  {
140  x *= fScalar;
141  y *= fScalar;
142  z *= fScalar;
143  w *= fScalar;
144  return *this;
145  }
146 
147  template <class T>
149  {
150  return this->operator*=(T(1.0)/fScalar);
151  }
152 
153  template<class T>
154  inline std::ostream& operator <<
155  ( std::ostream& o, const DtVector4<T>& v )
156  {
157  o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
158  return o;
159  }
160 
161  template <class T>
163  {
164  return 4*sizeof(T);
165  }
166 
167 } //namespace makVrv

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)