OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NEON/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 __NEON_ArrayVector3_H__
29 #define __NEON_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 
64  class _OgreExport ArrayVector3
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] = vdupq_n_f32( v.x );
109  mChunkBase[1] = vdupq_n_f32( v.y );
110  mChunkBase[2] = vdupq_n_f32( 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  //set1_ps is a composite instrinsic using shuffling instructions.
124  //Store the actual result in a tmp variable and copy. We don't
125  //do mChunkBase[1] = mChunkBase[0]; because of a potential LHS
126  //depending on how smart the compiler was
127  ArrayReal tmp = vdupq_n_f32( fScalar );
128  mChunkBase[0] = tmp;
129  mChunkBase[1] = tmp;
130  mChunkBase[2] = tmp;
131 
132  return *this;
133  }
134 
135  // Arithmetic operations
136  inline const ArrayVector3& operator + () const;
137  inline ArrayVector3 operator - () const;
138 
139  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
140  inline friend ArrayVector3 operator + ( Real fScalar, const ArrayVector3 &rhs );
141  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, Real fScalar );
142 
143  inline friend ArrayVector3 operator + ( ArrayReal fScalar, const ArrayVector3 &rhs );
144  inline friend ArrayVector3 operator + ( const ArrayVector3 &lhs, ArrayReal fScalar );
145 
146  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
147  inline friend ArrayVector3 operator - ( Real fScalar, const ArrayVector3 &rhs );
148  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, Real fScalar );
149 
150  inline friend ArrayVector3 operator - ( ArrayReal fScalar, const ArrayVector3 &rhs );
151  inline friend ArrayVector3 operator - ( const ArrayVector3 &lhs, ArrayReal fScalar );
152 
153  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
154  inline friend ArrayVector3 operator * ( Real fScalar, const ArrayVector3 &rhs );
155  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, Real fScalar );
156 
157  inline friend ArrayVector3 operator * ( ArrayReal fScalar, const ArrayVector3 &rhs );
158  inline friend ArrayVector3 operator * ( const ArrayVector3 &lhs, ArrayReal fScalar );
159 
160  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, const ArrayVector3 &rhs );
161  inline friend ArrayVector3 operator / ( Real fScalar, const ArrayVector3 &rhs );
162  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, Real fScalar );
163 
164  inline friend ArrayVector3 operator / ( ArrayReal fScalar, const ArrayVector3 &rhs );
165  inline friend ArrayVector3 operator / ( const ArrayVector3 &lhs, ArrayReal fScalar );
166 
167  inline void operator += ( const ArrayVector3 &a );
168  inline void operator += ( const Real fScalar );
169  inline void operator += ( const ArrayReal fScalar );
170 
171  inline void operator -= ( const ArrayVector3 &a );
172  inline void operator -= ( const Real fScalar );
173  inline void operator -= ( const ArrayReal fScalar );
174 
175  inline void operator *= ( const ArrayVector3 &a );
176  inline void operator *= ( const Real fScalar );
177  inline void operator *= ( const ArrayReal fScalar );
178 
179  inline void operator /= ( const ArrayVector3 &a );
180  inline void operator /= ( const Real fScalar );
181  inline void operator /= ( const ArrayReal fScalar );
182 
184  inline ArrayReal length() const;
185 
187  inline ArrayReal squaredLength() const;
188 
190  inline ArrayReal distance( const ArrayVector3& rhs ) const;
191 
193  inline ArrayReal squaredDistance( const ArrayVector3& rhs ) const;
194 
196  inline ArrayReal dotProduct( const ArrayVector3& vec ) const;
197 
199  inline ArrayReal absDotProduct( const ArrayVector3& vec ) const;
200 
203  inline void normalise( void );
204 
206  inline ArrayVector3 crossProduct( const ArrayVector3& rkVector ) const;
207 
209  inline ArrayVector3 midPoint( const ArrayVector3& vec ) const;
210 
212  inline void makeFloor( const ArrayVector3& cmp );
213 
215  inline void makeCeil( const ArrayVector3& cmp );
216 
218  inline ArrayReal getMinComponent() const;
219 
221  inline ArrayReal getMaxComponent() const;
222 
231  inline void setToSign();
232 
234  inline ArrayVector3 perpendicular( void ) const;
235 
237  inline ArrayVector3 normalisedCopy( void ) const;
238 
240  inline ArrayVector3 reflect( const ArrayVector3& normal ) const;
241 
250  inline void inverseLeaveZeroes( void );
251 
257  inline int isNaN( void ) const;
258 
260  inline ArrayVector3 primaryAxis( void ) const;
261 
271  inline Vector3 collapseMin( void ) const;
272 
282  inline Vector3 collapseMax( void ) const;
283 
304  inline void Cmov4( ArrayMaskR mask, const ArrayVector3 &replacement );
305 
326  inline void CmovRobust( ArrayMaskR mask, const ArrayVector3 &replacement );
327 
345  inline static ArrayVector3 Cmov4( const ArrayVector3 &arg1, const ArrayVector3 &arg2, ArrayMaskR mask );
346 
360  inline void loadFromAoS( const Real * RESTRICT_ALIAS src );
361 
362  static const ArrayVector3 ZERO;
363  static const ArrayVector3 UNIT_X;
364  static const ArrayVector3 UNIT_Y;
365  static const ArrayVector3 UNIT_Z;
366  static const ArrayVector3 NEGATIVE_UNIT_X;
367  static const ArrayVector3 NEGATIVE_UNIT_Y;
368  static const ArrayVector3 NEGATIVE_UNIT_Z;
369  static const ArrayVector3 UNIT_SCALE;
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.