OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
C/OgreArrayVector3.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __C_ArrayVector3_H__
29 #define __C_ArrayVector3_H__
30 
31 #ifndef __ArrayVector3_H__
32  #error "Don't include this file directly. include Math/Array/OgreArrayVector3.h"
33 #endif
34 
35 #include "OgreVector3.h"
36 
37 #include "Math/Array/OgreMathlib.h"
38 
39 namespace Ogre
40 {
41  class ArrayInterQuaternion;
42 
65  {
66  public:
67  ArrayReal mChunkBase[3];
68 
70  ArrayVector3( ArrayReal chunkX, ArrayReal chunkY, ArrayReal chunkZ )
71  {
72  mChunkBase[0] = chunkX;
73  mChunkBase[1] = chunkY;
74  mChunkBase[2] = chunkZ;
75  }
76 
77  void getAsVector3( Vector3 &out, size_t index ) const
78  {
79  //Be careful of not writing to these regions or else strict aliasing rule gets broken!!!
80  const Real *aliasedReal = reinterpret_cast<const Real*>( mChunkBase );
81  out.x = aliasedReal[ARRAY_PACKED_REALS * 0 + index]; //X
82  out.y = aliasedReal[ARRAY_PACKED_REALS * 1 + index]; //Y
83  out.z = aliasedReal[ARRAY_PACKED_REALS * 2 + index]; //Z
84  }
85 
88  Vector3 getAsVector3( size_t index ) const
89  {
90  //Be careful of not writing to these regions or else strict aliasing rule gets broken!!!
91  const Real *aliasedReal = reinterpret_cast<const Real*>( mChunkBase );
92  return Vector3( aliasedReal[ARRAY_PACKED_REALS * 0 + index], //X
93  aliasedReal[ARRAY_PACKED_REALS * 1 + index], //Y
94  aliasedReal[ARRAY_PACKED_REALS * 2 + index] ); //Z
95  }
96 
97  void setFromVector3( const Vector3 &v, size_t index )
98  {
99  Real *aliasedReal = reinterpret_cast<Real*>( mChunkBase );
100  aliasedReal[ARRAY_PACKED_REALS * 0 + index] = v.x;
101  aliasedReal[ARRAY_PACKED_REALS * 1 + index] = v.y;
102  aliasedReal[ARRAY_PACKED_REALS * 2 + index] = v.z;
103  }
104 
106  void setAll( const Vector3 &v )
107  {
108  mChunkBase[0] = v.x;
109  mChunkBase[1] = v.y;
110  mChunkBase[2] = v.z;
111  }
112 
114  /*void copyScalar( size_t ourIndex, const ArrayVector3 &copy, size_t copyIndex )
115  {
116  Vector3 tmp;
117  copy.getAsVector3( tmp );
118  this->setFromVector3( tmp );
119  }*/
120 
121  inline ArrayVector3& operator = ( const Real fScalar )
122  {
123  mChunkBase[0] = fScalar;
124  mChunkBase[1] = fScalar;
125  mChunkBase[2] = fScalar;
126 
127  return *this;
128  }
129 
130  // Arithmetic operations
131  inline const ArrayVector3& operator + () const;
132  inline ArrayVector3 operator - () const;
133 
134  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
135  inline friend ArrayVector3 operator + ( Real fScalar, const ArrayVector3 &rhs );
136  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, Real fScalar );
137 
138  inline friend ArrayVector3 operator + ( ArrayReal fScalar, const ArrayVector3 &rhs );
139  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, ArrayReal fScalar );
140 
141  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
142  inline friend ArrayVector3 operator - ( Real fScalar, const ArrayVector3 &rhs );
143  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, Real fScalar );
144 
145  inline friend ArrayVector3 operator - ( ArrayReal fScalar, const ArrayVector3 &rhs );
146  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, ArrayReal fScalar );
147 
148  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
149  inline friend ArrayVector3 operator * ( Real fScalar, const ArrayVector3 &rhs );
150  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, Real fScalar );
151 
152  inline friend ArrayVector3 operator * ( ArrayReal fScalar, const ArrayVector3 &rhs );
153  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, ArrayReal fScalar );
154 
155  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
156  inline friend ArrayVector3 operator / ( Real fScalar, const ArrayVector3 &rhs );
157  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, Real fScalar );
158 
159  inline friend ArrayVector3 operator / ( ArrayReal fScalar, const ArrayVector3 &rhs );
160  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, ArrayReal fScalar );
161 
162  inline void operator += ( const ArrayVector3 &a );
163  inline void operator += ( const ArrayReal fScalar );
164 
165  inline void operator -= ( const ArrayVector3 &a );
166  inline void operator -= ( const ArrayReal fScalar );
167 
168  inline void operator *= ( const ArrayVector3 &a );
169  inline void operator *= ( const ArrayReal fScalar );
170 
171  inline void operator /= ( const ArrayVector3 &a );
172  inline void operator /= ( const ArrayReal fScalar );
173 
175  inline ArrayReal length() const;
176 
178  inline ArrayReal squaredLength() const;
179 
181  inline ArrayReal distance( const ArrayVector3& rhs ) const;
182 
184  inline ArrayReal squaredDistance( const ArrayVector3& rhs ) const;
185 
187  inline ArrayReal dotProduct( const ArrayVector3& vec ) const;
188 
190  inline ArrayReal absDotProduct( const ArrayVector3& vec ) const;
191 
194  inline void normalise( void );
195 
197  inline ArrayVector3 crossProduct( const ArrayVector3& rkVector ) const;
198 
200  inline ArrayVector3 midPoint( const ArrayVector3& vec ) const;
201 
203  inline void makeFloor( const ArrayVector3& cmp );
204 
206  inline void makeCeil( const ArrayVector3& cmp );
207 
209  inline ArrayReal getMinComponent() const;
210 
212  inline ArrayReal getMaxComponent() const;
213 
222  inline void setToSign();
223 
225  inline ArrayVector3 perpendicular( void ) const;
226 
228  inline ArrayVector3 normalisedCopy( void ) const;
229 
231  inline ArrayVector3 reflect( const ArrayVector3& normal ) const;
232 
241  inline void inverseLeaveZeroes( void );
242 
248  inline int isNaN( void ) const;
249 
251  inline ArrayVector3 primaryAxis( void ) const;
252 
262  inline Vector3 collapseMin( void ) const;
263 
273  inline Vector3 collapseMax( void ) const;
274 
295  inline void Cmov4( ArrayMaskR mask, const ArrayVector3 &replacement );
296 
317  inline void CmovRobust( ArrayMaskR mask, const ArrayVector3 &replacement );
318 
336  inline static ArrayVector3 Cmov4( const ArrayVector3 &arg1, const ArrayVector3 &arg2, ArrayMaskR mask );
337 
338  static const ArrayVector3 ZERO;
339  static const ArrayVector3 UNIT_X;
340  static const ArrayVector3 UNIT_Y;
341  static const ArrayVector3 UNIT_Z;
345  static const ArrayVector3 UNIT_SCALE;
346  };
350 }
351 
352 #include "OgreArrayVector3.inl"
353 
354 #endif
bool ArrayMaskR
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
static const ArrayVector3 NEGATIVE_UNIT_X
ArrayVector3(ArrayReal chunkX, ArrayReal chunkY, ArrayReal chunkZ)
static const ArrayVector3 ZERO
Real ArrayReal
static const ArrayVector3 UNIT_SCALE
static const ArrayVector3 NEGATIVE_UNIT_Y
Vector3 getAsVector3(size_t index) const
Prefer using.
void getAsVector3(Vector3 &out, size_t index) const
Radian operator*(Real a, const Radian &b)
Definition: OgreMath.h:782
Radian operator/(Real a, const Radian &b)
Definition: OgreMath.h:787
static const ArrayVector3 UNIT_Y
static const ArrayVector3 UNIT_Z
Cache-friendly array of 3-dimensional represented as a SoA array.
void setFromVector3(const Vector3 &v, size_t index)
#define ARRAY_PACKED_REALS
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
void setAll(const Vector3 &v)
Sets all packed vectors to the same value as the scalar input vector.
static const ArrayVector3 NEGATIVE_UNIT_Z
static const ArrayVector3 UNIT_X