OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreMathlibC.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 
29 #ifndef __MathlibC_H__
30 #define __MathlibC_H__
31 
32 #ifndef __Mathlib_H__
33  #error "Don't include this file directly. include Math/Array/OgreMathlib.h"
34 #endif
35 
36 #include "OgrePrerequisites.h"
37 #include "OgreCommon.h"
38 #include "OgreMath.h"
39 
40 namespace Ogre
41 {
43  {
44  public:
45  static const ArrayReal HALF; //0.5f, 0.5f, 0.5f, 0.5f
46  static const ArrayReal ONE; //1.0f, 1.0f, 1.0f, 1.0f
47  static const ArrayReal THREE; //3.0f, 3.0f, 3.0f, 3.0f
48  static const ArrayReal NEG_ONE; //-1.0f, -1.0f, -1.0f, -1.0f
49  static const ArrayReal PI; //PI, PI, PI, PI
50  static const ArrayReal TWO_PI; //2*PI, 2*PI, 2*PI, 2*PI
51  static const ArrayReal ONE_DIV_2PI; //1 / 2PI, 1 / 2PI, 1 / 2PI, 1 / 2PI
52  static const ArrayReal fEpsilon; //1e-6f, 1e-6f, 1e-6f, 1e-6f
53  static const ArrayReal fSqEpsilon; //1e-12f, 1e-12f, 1e-12f, 1e-12f
54  static const ArrayReal OneMinusEpsilon;//1 - 1e-6f, 1 - 1e-6f, 1 - 1e-6f, 1 - 1e-6f
55  static const ArrayReal fDeg2Rad; //Math::fDeg2Rad, Math::fDeg2Rad, Math::fDeg2Rad, Math::fDeg2Rad
56  static const ArrayReal fRad2Deg; //Math::fRad2Deg, Math::fRad2Deg, Math::fRad2Deg, Math::fRad2Deg
57  static const ArrayReal FLOAT_MIN; //FLT_MIN, FLT_MIN, FLT_MIN, FLT_MIN
58  static const ArrayReal SIGN_MASK; //0x80000000, 0x80000000, 0x80000000, 0x80000000
59  static const ArrayReal INFINITEA; //Inf, Inf, Inf, Inf
60  static const ArrayReal MAX_NEG; //Max negative number (x4)
61  static const ArrayReal MAX_POS; //Max negative number (x4)
62 
69  static inline ArrayReal Abs4( ArrayReal a )
70  {
71  return Math::Abs( a );
72  }
73 
94  static inline ArrayReal Cmov4( ArrayReal arg1, ArrayReal arg2, ArrayMaskR mask )
95  {
96  assert( !Math::isNaN( arg1 ) && !Math::isNaN( arg2 ) &&
97  "Passing NaN values to CMov4" );
98 #ifndef NDEBUG
99  ArrayReal newNan1 = arg1 * 0; //+-Inf * 0 = nan
100  ArrayReal newNan2 = arg2 * 0; //+-Inf * 0 = nan
101  assert( !Math::isNaN( newNan1 ) && !Math::isNaN( newNan2 ) &&
102  "Passing +/- Infinity values to CMov4" );
103 #endif
104 
105  return mask ? arg1 : arg2;
106  }
107 
134  static inline ArrayReal CmovRobust( ArrayReal arg1, ArrayReal arg2, ArrayMaskR mask )
135  {
136  return mask ? arg1 : arg2;
137  }
138  static inline ArrayInt CmovRobust( ArrayInt arg1, ArrayInt arg2, ArrayMaskI mask )
139  {
140  return mask ? arg1 : arg2;
141  }
142 
147  static inline ArrayInt And( ArrayInt a, ArrayInt b )
148  {
149  return a & b;
150  }
151 
152  static inline ArrayMaskI And( ArrayMaskI a, ArrayInt b )
153  {
154  return ((a ? 0xffffffff : 0) & b) != 0;
155  }
156 
157  static inline ArrayMaskI And( ArrayInt a, ArrayMaskI b )
158  {
159  return (a & (b ? 0xffffffff : 0)) != 0;
160  }
161 
162  static inline ArrayMaskI And( ArrayMaskI a, ArrayMaskI b )
163  {
164  return a & b;
165  }
166 
171  static inline ArrayMaskI TestFlags4( ArrayInt a, ArrayInt b )
172  {
173  return (a & b) != 0;
174  }
175 
176  static inline ArrayMaskI TestFlags4( ArrayMaskI a, ArrayInt b )
177  {
178  return ( (a ? 0xffffffff : 0) & b ) != 0;
179  }
180 
181  static inline ArrayMaskI TestFlags4( ArrayInt a, ArrayMaskI b )
182  {
183  return ( a & (b ? 0xffffffff : 0) ) != 0;
184  }
185 
190  static inline ArrayInt AndNot( ArrayInt a, ArrayInt b )
191  {
192  return a & ~b;
193  }
194 
195  static inline ArrayMaskI AndNot( ArrayMaskI a, ArrayInt b )
196  {
197  return ((a ? 0xffffffff : 0) & ~b) != 0;
198  }
199 
200  static inline ArrayMaskI AndNot( ArrayInt a, ArrayMaskI b )
201  {
202  return (a & (b ? 0 : 0xffffffff)) != 0;
203  }
204 
205  static inline ArrayMaskI AndNot( ArrayMaskI a, ArrayMaskI b )
206  {
207  return a & (!b);
208  }
209 
214  static inline ArrayInt Or( ArrayInt a, ArrayInt b )
215  {
216  return a | b;
217  }
218  static inline ArrayMaskI Or( ArrayMaskI a, ArrayMaskI b )
219  {
220  return a | b;
221  }
222 
223  static inline ArrayMaskI Or( ArrayMaskI a, ArrayInt b )
224  {
225  return ( (a ? 0xffffffff : 0) | b ) != 0;
226  }
227  static inline ArrayMaskI Or( ArrayInt a, ArrayMaskI b )
228  {
229  return ( a | (b ? 0xffffffff : 0) ) != 0;
230  }
231 
237  {
238  return a < b;
239  }
240 
246  {
247  return a <= b;
248  }
249 
255  {
256  return a > b;
257  }
258 
264  {
265  return a >= b;
266  }
267 
268  static inline ArrayReal SetAll( Real val )
269  {
270  return val;
271  }
272 
273  static inline ArrayInt SetAll( uint32 val )
274  {
275  return val;
276  }
277 
282  static inline ArrayMaskR isInfinity( ArrayReal a )
283  {
284  return a == std::numeric_limits<float>::infinity();
285  }
286 
288  static inline ArrayReal Max( ArrayReal a, ArrayReal b )
289  {
290  return Ogre::max( a, b );
291  }
292 
297  static inline Real ColapseMin( ArrayReal a )
298  {
299  return a;
300  }
301 
306  static inline Real ColapseMax( ArrayReal a )
307  {
308  return a;
309  }
310 
319  static inline ArrayReal Inv4( ArrayReal val )
320  {
321  return 1.0f / val;
322  }
323 
335  static inline ArrayReal InvNonZero4( ArrayReal val )
336  {
337  return 1.0f / val;
338  }
339 
344  static inline ArrayReal InvSqrt4( ArrayReal f )
345  {
346  return 1.0f / sqrt( f );
347  }
348 
354  {
355  return 1.0f / sqrt( f );
356  }
357 
366  static inline ArrayReal Modf4( ArrayReal x, ArrayReal &outIntegral );
367 
374  static inline ArrayReal ACos4( ArrayReal x );
375 
382  static inline ArrayReal Sin4( ArrayReal x );
383 
390  static inline ArrayReal Cos4( ArrayReal x );
391 
401  static void SinCos4( ArrayReal x, ArrayReal &outSin, ArrayReal &outCos );
402  };
403 }
404 
405 #include "OgreMathlibC.inl"
406 
407 #endif
static const ArrayReal ONE
Definition: OgreMathlibC.h:46
static ArrayReal SetAll(Real val)
Definition: OgreMathlibC.h:268
static const ArrayReal OneMinusEpsilon
Definition: OgreMathlibC.h:54
float Real
Software floating point type.
bool ArrayMaskR
unsigned int uint32
Definition: OgrePlatform.h:420
#define _OgreExport
Definition: OgrePlatform.h:255
static ArrayMaskI TestFlags4(ArrayMaskI a, ArrayInt b)
Definition: OgreMathlibC.h:176
static ArrayMaskR CompareLessEqual(ArrayReal a, ArrayReal b)
Returns the result of "a <= b".
Definition: OgreMathlibC.h:245
static const ArrayReal TWO_PI
Definition: OgreMathlibC.h:50
const float & max(const float &a, const float &b)
Definition: OgreCommon.h:851
static Real ColapseMax(ArrayReal a)
Returns the maximum value of all elements in a.
Definition: OgreMathlibC.h:306
static const ArrayReal THREE
Definition: OgreMathlibC.h:47
static ArrayMaskI Or(ArrayMaskI a, ArrayMaskI b)
Definition: OgreMathlibC.h:218
static const ArrayReal INFINITEA
Definition: OgreMathlibC.h:59
static ArrayMaskI AndNot(ArrayMaskI a, ArrayMaskI b)
Definition: OgreMathlibC.h:205
static ArrayMaskR isInfinity(ArrayReal a)
Returns the result of "a == std::numeric_limits::infinity()".
Definition: OgreMathlibC.h:282
Real ArrayReal
static const ArrayReal MAX_NEG
Definition: OgreMathlibC.h:60
static const ArrayReal MAX_POS
Definition: OgreMathlibC.h:61
static ArrayMaskR CompareLess(ArrayReal a, ArrayReal b)
Returns the result of "a < b".
Definition: OgreMathlibC.h:236
static const ArrayReal FLOAT_MIN
Definition: OgreMathlibC.h:57
static ArrayMaskR CompareGreaterEqual(ArrayReal a, ArrayReal b)
Returns the result of "a >= b".
Definition: OgreMathlibC.h:263
static const ArrayReal ONE_DIV_2PI
Definition: OgreMathlibC.h:51
static ArrayMaskI AndNot(ArrayInt a, ArrayMaskI b)
Definition: OgreMathlibC.h:200
static ArrayInt And(ArrayInt a, ArrayInt b)
Returns the result of "a & b".
Definition: OgreMathlibC.h:147
static const ArrayReal PI
Definition: OgreMathlibC.h:49
static ArrayMaskI TestFlags4(ArrayInt a, ArrayInt b)
Test if "a AND b" will result in non-zero, returning 0xffffffff on those cases.
Definition: OgreMathlibC.h:171
static Real Abs(Real fValue)
Absolute value function.
Definition: OgreMath.h:260
static const ArrayReal fRad2Deg
Definition: OgreMathlibC.h:56
static ArrayMaskR CompareGreater(ArrayReal a, ArrayReal b)
Returns the result of "a > b".
Definition: OgreMathlibC.h:254
static ArrayMaskI TestFlags4(ArrayInt a, ArrayMaskI b)
Definition: OgreMathlibC.h:181
static const ArrayReal fSqEpsilon
Definition: OgreMathlibC.h:53
static ArrayReal Abs4(ArrayReal a)
Returns the absolute values of each 4 floats.
Definition: OgreMathlibC.h:69
static ArrayReal InvSqrtNonZero4(ArrayReal f)
Returns the squared root of the reciprocal of x.
Definition: OgreMathlibC.h:353
static const ArrayReal SIGN_MASK
Definition: OgreMathlibC.h:58
bool ArrayMaskI
static ArrayMaskI And(ArrayMaskI a, ArrayInt b)
Definition: OgreMathlibC.h:152
static ArrayMaskI Or(ArrayMaskI a, ArrayInt b)
Definition: OgreMathlibC.h:223
static const ArrayReal fEpsilon
Definition: OgreMathlibC.h:52
static ArrayReal CmovRobust(ArrayReal arg1, ArrayReal arg2, ArrayMaskR mask)
Robust, branchless conditional move for a 128-bit value.
Definition: OgreMathlibC.h:134
static const ArrayReal NEG_ONE
Definition: OgreMathlibC.h:48
static ArrayMaskI AndNot(ArrayMaskI a, ArrayInt b)
Definition: OgreMathlibC.h:195
static ArrayReal Cmov4(ArrayReal arg1, ArrayReal arg2, ArrayMaskR mask)
Branchless conditional move for 4 floating point values.
Definition: OgreMathlibC.h:94
static ArrayReal InvNonZero4(ArrayReal val)
Returns the reciprocal of x.
Definition: OgreMathlibC.h:335
static ArrayInt CmovRobust(ArrayInt arg1, ArrayInt arg2, ArrayMaskI mask)
Definition: OgreMathlibC.h:138
static ArrayInt SetAll(uint32 val)
Definition: OgreMathlibC.h:273
static ArrayMaskI Or(ArrayInt a, ArrayMaskI b)
Definition: OgreMathlibC.h:227
static ArrayInt AndNot(ArrayInt a, ArrayInt b)
Returns the result of "a & ~b".
Definition: OgreMathlibC.h:190
static const ArrayReal fDeg2Rad
Definition: OgreMathlibC.h:55
static ArrayReal InvSqrt4(ArrayReal f)
Returns the squared root of the reciprocal of x.
Definition: OgreMathlibC.h:344
static ArrayMaskI And(ArrayInt a, ArrayMaskI b)
Definition: OgreMathlibC.h:157
static bool isNaN(Real f)
Definition: OgreMath.h:307
static const ArrayReal HALF
Definition: OgreMathlibC.h:45
static Real ColapseMin(ArrayReal a)
Returns the minimum value of all elements in a.
Definition: OgreMathlibC.h:297
static ArrayReal Max(ArrayReal a, ArrayReal b)
Returns the maximum value between a and b.
Definition: OgreMathlibC.h:288
static ArrayMaskI And(ArrayMaskI a, ArrayMaskI b)
Definition: OgreMathlibC.h:162
static ArrayReal Inv4(ArrayReal val)
Returns the reciprocal of x.
Definition: OgreMathlibC.h:319
uint32 ArrayInt
static ArrayInt Or(ArrayInt a, ArrayInt b)
Returns the result of "a | b".
Definition: OgreMathlibC.h:214