OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SSE2/Single/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 __SSE2_ArrayVector3_H__
29 #define __SSE2_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 
63  class _OgreExport ArrayVector3
64  {
65  public:
66  ArrayReal mChunkBase[3];
67 
69  ArrayVector3( ArrayReal chunkX, ArrayReal chunkY, ArrayReal chunkZ )
70  {
71  mChunkBase[0] = chunkX;
72  mChunkBase[1] = chunkY;
73  mChunkBase[2] = chunkZ;
74  }
75 
76  void getAsVector3( Vector3 &out, size_t index ) const
77  {
78  //Be careful of not writing to these regions or else strict aliasing rule gets broken!!!
79  const Real *aliasedReal = reinterpret_cast<const Real*>( mChunkBase );
80  out.x = aliasedReal[ARRAY_PACKED_REALS * 0 + index]; //X
81  out.y = aliasedReal[ARRAY_PACKED_REALS * 1 + index]; //Y
82  out.z = aliasedReal[ARRAY_PACKED_REALS * 2 + index]; //Z
83  }
84 
87  Vector3 getAsVector3( size_t index ) const
88  {
89  //Be careful of not writing to these regions or else strict aliasing rule gets broken!!!
90  const Real *aliasedReal = reinterpret_cast<const Real*>( mChunkBase );
91  return Vector3( aliasedReal[ARRAY_PACKED_REALS * 0 + index], //X
92  aliasedReal[ARRAY_PACKED_REALS * 1 + index], //Y
93  aliasedReal[ARRAY_PACKED_REALS * 2 + index] ); //Z
94  }
95 
96  void setFromVector3( const Vector3 &v, size_t index )
97  {
98  Real *aliasedReal = reinterpret_cast<Real*>( mChunkBase );
99  aliasedReal[ARRAY_PACKED_REALS * 0 + index] = v.x;
100  aliasedReal[ARRAY_PACKED_REALS * 1 + index] = v.y;
101  aliasedReal[ARRAY_PACKED_REALS * 2 + index] = v.z;
102  }
103 
105  void setAll( const Vector3 &v )
106  {
107  mChunkBase[0] = _mm_set_ps1( v.x );
108  mChunkBase[1] = _mm_set_ps1( v.y );
109  mChunkBase[2] = _mm_set_ps1( v.z );
110  }
111 
113  /*void copyScalar( size_t ourIndex, const ArrayVector3 &copy, size_t copyIndex )
114  {
115  Vector3 tmp;
116  copy.getAsVector3( tmp );
117  this->setFromVector3( tmp );
118  }*/
119 
120  inline ArrayVector3& operator = ( const Real fScalar )
121  {
122  //set1_ps is a composite instrinsic using shuffling instructions.
123  //Store the actual result in a tmp variable and copy. We don't
124  //do mChunkBase[1] = mChunkBase[0]; because of a potential LHS
125  //depending on how smart the compiler was
126  ArrayReal tmp = _mm_set1_ps( fScalar );
127  mChunkBase[0] = tmp;
128  mChunkBase[1] = tmp;
129  mChunkBase[2] = tmp;
130 
131  return *this;
132  }
133 
134  // Arithmetic operations
135  inline const ArrayVector3& operator + () const;
136  inline ArrayVector3 operator - () const;
137 
138  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
139  inline friend ArrayVector3 operator + ( Real fScalar, const ArrayVector3 &rhs );
140  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, Real fScalar );
141 
142  inline friend ArrayVector3 operator + ( ArrayReal fScalar, const ArrayVector3 &rhs );
143  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, ArrayReal fScalar );
144 
145  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
146  inline friend ArrayVector3 operator - ( Real fScalar, const ArrayVector3 &rhs );
147  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, Real fScalar );
148 
149  inline friend ArrayVector3 operator - ( ArrayReal fScalar, const ArrayVector3 &rhs );
150  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, ArrayReal fScalar );
151 
152  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
153  inline friend ArrayVector3 operator * ( Real fScalar, const ArrayVector3 &rhs );
154  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, Real fScalar );
155 
156  inline friend ArrayVector3 operator * ( ArrayReal fScalar, const ArrayVector3 &rhs );
157  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, ArrayReal fScalar );
158 
159  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
160  inline friend ArrayVector3 operator / ( Real fScalar, const ArrayVector3 &rhs );
161  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, Real fScalar );
162 
163  inline friend ArrayVector3 operator / ( ArrayReal fScalar, const ArrayVector3 &rhs );
164  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, ArrayReal fScalar );
165 
166  inline void operator += ( const ArrayVector3 &a );
167  inline void operator += ( const Real fScalar );
168  inline void operator += ( const ArrayReal fScalar );
169 
170  inline void operator -= ( const ArrayVector3 &a );
171  inline void operator -= ( const Real fScalar );
172  inline void operator -= ( const ArrayReal fScalar );
173 
174  inline void operator *= ( const ArrayVector3 &a );
175  inline void operator *= ( const Real fScalar );
176  inline void operator *= ( const ArrayReal fScalar );
177 
178  inline void operator /= ( const ArrayVector3 &a );
179  inline void operator /= ( const Real fScalar );
180  inline void operator /= ( const ArrayReal fScalar );
181 
183  inline ArrayReal length() const;
184 
186  inline ArrayReal squaredLength() const;
187 
189  inline ArrayReal distance( const ArrayVector3& rhs ) const;
190 
192  inline ArrayReal squaredDistance( const ArrayVector3& rhs ) const;
193 
195  inline ArrayReal dotProduct( const ArrayVector3& vec ) const;
196 
198  inline ArrayReal absDotProduct( const ArrayVector3& vec ) const;
199 
202  inline void normalise( void );
203 
205  inline ArrayVector3 crossProduct( const ArrayVector3& rkVector ) const;
206 
208  inline ArrayVector3 midPoint( const ArrayVector3& vec ) const;
209 
211  inline void makeFloor( const ArrayVector3& cmp );
212 
214  inline void makeCeil( const ArrayVector3& cmp );
215 
217  inline ArrayReal getMinComponent() const;
218 
220  inline ArrayReal getMaxComponent() const;
221 
230  inline void setToSign();
231 
233  inline ArrayVector3 perpendicular( void ) const;
234 
236  inline ArrayVector3 normalisedCopy( void ) const;
237 
239  inline ArrayVector3 reflect( const ArrayVector3& normal ) const;
240 
249  inline void inverseLeaveZeroes( void );
250 
256  inline int isNaN( void ) const;
257 
259  inline ArrayVector3 primaryAxis( void ) const;
260 
270  inline Vector3 collapseMin( void ) const;
271 
281  inline Vector3 collapseMax( void ) const;
282 
303  inline void Cmov4( ArrayMaskR mask, const ArrayVector3 &replacement );
304 
325  inline void CmovRobust( ArrayMaskR mask, const ArrayVector3 &replacement );
326 
344  inline static ArrayVector3 Cmov4( const ArrayVector3 &arg1, const ArrayVector3 &arg2, ArrayMaskR mask );
345 
359  inline void loadFromAoS( const Real * RESTRICT_ALIAS src );
360 
361  static const ArrayVector3 ZERO;
362  static const ArrayVector3 UNIT_X;
363  static const ArrayVector3 UNIT_Y;
364  static const ArrayVector3 UNIT_Z;
365  static const ArrayVector3 NEGATIVE_UNIT_X;
366  static const ArrayVector3 NEGATIVE_UNIT_Y;
367  static const ArrayVector3 NEGATIVE_UNIT_Z;
368  static const ArrayVector3 UNIT_SCALE;
369  };
370 
374 }
375 
376 #include "OgreArrayVector3.inl"
377 
378 #endif
bool ArrayMaskR
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
ArrayVector3(ArrayReal chunkX, ArrayReal chunkY, ArrayReal chunkZ)
Real ArrayReal
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
#define RESTRICT_ALIAS
Definition: OgrePlatform.h:448
Radian operator/(Real a, const Radian &b)
Definition: OgreMath.h:787
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.