~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletCollision/Gimpact/gim_math.h

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef GIM_MATH_H_INCLUDED
2
 
#define GIM_MATH_H_INCLUDED
3
 
/*! \file gim_math.h
4
 
\author Francisco Len N�jera
5
 
*/
6
 
/*
7
 
-----------------------------------------------------------------------------
8
 
This source file is part of GIMPACT Library.
9
 
 
10
 
For the latest info, see http://gimpact.sourceforge.net/
11
 
 
12
 
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
13
 
email: projectileman@yahoo.com
14
 
 
15
 
 This library is free software; you can redistribute it and/or
16
 
 modify it under the terms of EITHER:
17
 
   (1) The GNU Lesser General Public License as published by the Free
18
 
       Software Foundation; either version 2.1 of the License, or (at
19
 
       your option) any later version. The text of the GNU Lesser
20
 
       General Public License is included with this library in the
21
 
       file GIMPACT-LICENSE-LGPL.TXT.
22
 
   (2) The BSD-style license that is included with this library in
23
 
       the file GIMPACT-LICENSE-BSD.TXT.
24
 
   (3) The zlib/libpng license that is included with this library in
25
 
       the file GIMPACT-LICENSE-ZLIB.TXT.
26
 
 
27
 
 This library is distributed in the hope that it will be useful,
28
 
 but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
30
 
 GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
31
 
 
32
 
-----------------------------------------------------------------------------
33
 
*/
34
 
 
35
 
#include "LinearMath/btScalar.h"
36
 
 
37
 
 
38
 
/*! \defgroup BASIC_TYPES
39
 
Basic types and constants
40
 
Conventions:
41
 
Types starting with G
42
 
Constants starting with G_
43
 
*/
44
 
//! @{
45
 
 
46
 
#define GREAL btScalar
47
 
#define GREAL2 double
48
 
#define GINT int
49
 
#define GUINT unsigned int
50
 
#define GSHORT short
51
 
#define GUSHORT unsigned short
52
 
#define GINT64 long long
53
 
#define GUINT64 unsigned long long
54
 
 
55
 
//! @}
56
 
 
57
 
/*! \defgroup BASIC_CONSTANTS
58
 
Basic constants
59
 
Conventions:
60
 
Types starting with G
61
 
Constants starting with G_
62
 
*/
63
 
//! @{
64
 
 
65
 
#define G_PI 3.14159265358979f
66
 
#define G_HALF_PI 1.5707963f
67
 
//267948966
68
 
#define G_TWO_PI 6.28318530f
69
 
//71795864
70
 
#define G_ROOT3 1.73205f
71
 
#define G_ROOT2 1.41421f
72
 
#define G_UINT_INFINITY 0xffffffff //!< A very very high value
73
 
#define G_REAL_INFINITY FLT_MAX
74
 
#define G_SIGN_BITMASK                  0x80000000
75
 
#define G_EPSILON SIMD_EPSILON
76
 
//! @}
77
 
 
78
 
 
79
 
/*! \defgroup SCALAR_TYPES
80
 
\brief
81
 
Precision type constants
82
 
*/
83
 
//! @{
84
 
enum GIM_SCALAR_TYPES
85
 
{
86
 
        G_STYPE_REAL =0,
87
 
        G_STYPE_REAL2,
88
 
        G_STYPE_SHORT,
89
 
        G_STYPE_USHORT,
90
 
        G_STYPE_INT,
91
 
        G_STYPE_UINT,
92
 
        G_STYPE_INT64,
93
 
        G_STYPE_UINT64
94
 
};
95
 
//! @}
96
 
 
97
 
/*! \defgroup MATH_FUNCTIONS
98
 
mathematical functions
99
 
*/
100
 
//! @{
101
 
 
102
 
#define G_DEGTORAD(X) ((X)*3.1415926f/180.0f)
103
 
#define G_RADTODEG(X) ((X)*180.0f/3.1415926f)
104
 
 
105
 
//! Integer representation of a floating-point value.
106
 
#define GIM_IR(x)                                       ((GUINT&)(x))
107
 
 
108
 
//! Signed integer representation of a floating-point value.
109
 
#define GIM_SIR(x)                                      ((GINT&)(x))
110
 
 
111
 
//! Absolute integer representation of a floating-point value
112
 
#define GIM_AIR(x)                                      (GIM_IR(x)&0x7fffffff)
113
 
 
114
 
//! Floating-point representation of an integer value.
115
 
#define GIM_FR(x)                                       ((GREAL&)(x))
116
 
 
117
 
#define GIM_MAX(a,b) (a<b?b:a)
118
 
#define GIM_MIN(a,b) (a>b?b:a)
119
 
 
120
 
#define GIM_MAX3(a,b,c) GIM_MAX(a,GIM_MAX(b,c))
121
 
#define GIM_MIN3(a,b,c) GIM_MIN(a,GIM_MIN(b,c))
122
 
 
123
 
#define GIM_IS_ZERO(value) (value < G_EPSILON &&  value > -G_EPSILON)
124
 
 
125
 
#define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON)
126
 
 
127
 
#define GIM_IS_POSISITVE(value) (value >= G_EPSILON)
128
 
 
129
 
#define GIM_NEAR_EQUAL(v1,v2) GIM_IS_ZERO((v1-v2))
130
 
 
131
 
///returns a clamped number
132
 
#define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number))
133
 
 
134
 
#define GIM_GREATER(x, y)       fabsf(x) > (y)
135
 
 
136
 
///Swap numbers
137
 
#define GIM_SWAP_NUMBERS(a,b){ \
138
 
    a = a+b; \
139
 
    b = a-b; \
140
 
    a = a-b; \
141
 
}\
142
 
 
143
 
#define GIM_INV_SQRT(va,isva)\
144
 
{\
145
 
    if(va<=0.0000001f)\
146
 
    {\
147
 
        isva = G_REAL_INFINITY;\
148
 
    }\
149
 
    else\
150
 
    {\
151
 
        GREAL _x = va * 0.5f;\
152
 
        GUINT _y = 0x5f3759df - ( GIM_IR(va) >> 1);\
153
 
        isva = GIM_FR(_y);\
154
 
        isva  = isva * ( 1.5f - ( _x * isva * isva ) );\
155
 
    }\
156
 
}\
157
 
 
158
 
#define GIM_SQRT(va,sva)\
159
 
{\
160
 
    GIM_INV_SQRT(va,sva);\
161
 
    sva = 1.0f/sva;\
162
 
}\
163
 
 
164
 
//! Computes 1.0f / sqrtf(x). Comes from Quake3. See http://www.magic-software.com/3DGEDInvSqrt.html
165
 
inline GREAL gim_inv_sqrt(GREAL f)
166
 
{
167
 
    GREAL r;
168
 
    GIM_INV_SQRT(f,r);
169
 
    return r;
170
 
}
171
 
 
172
 
inline GREAL gim_sqrt(GREAL f)
173
 
{
174
 
    GREAL r;
175
 
    GIM_SQRT(f,r);
176
 
    return r;
177
 
}
178
 
 
179
 
//! @}
180
 
 
181
 
#endif // GIM_MATH_H_INCLUDED
 
1
#ifndef GIM_MATH_H_INCLUDED
 
2
#define GIM_MATH_H_INCLUDED
 
3
/*! \file gim_math.h
 
4
\author Francisco Len N�jera
 
5
*/
 
6
/*
 
7
-----------------------------------------------------------------------------
 
8
This source file is part of GIMPACT Library.
 
9
 
 
10
For the latest info, see http://gimpact.sourceforge.net/
 
11
 
 
12
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
 
13
email: projectileman@yahoo.com
 
14
 
 
15
 This library is free software; you can redistribute it and/or
 
16
 modify it under the terms of EITHER:
 
17
   (1) The GNU Lesser General Public License as published by the Free
 
18
       Software Foundation; either version 2.1 of the License, or (at
 
19
       your option) any later version. The text of the GNU Lesser
 
20
       General Public License is included with this library in the
 
21
       file GIMPACT-LICENSE-LGPL.TXT.
 
22
   (2) The BSD-style license that is included with this library in
 
23
       the file GIMPACT-LICENSE-BSD.TXT.
 
24
   (3) The zlib/libpng license that is included with this library in
 
25
       the file GIMPACT-LICENSE-ZLIB.TXT.
 
26
 
 
27
 This library is distributed in the hope that it will be useful,
 
28
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
29
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 
30
 GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
 
31
 
 
32
-----------------------------------------------------------------------------
 
33
*/
 
34
 
 
35
#include "LinearMath/btScalar.h"
 
36
 
 
37
 
 
38
 
 
39
#define GREAL btScalar
 
40
#define GREAL2 double
 
41
#define GINT int
 
42
#define GUINT unsigned int
 
43
#define GSHORT short
 
44
#define GUSHORT unsigned short
 
45
#define GINT64 long long
 
46
#define GUINT64 unsigned long long
 
47
 
 
48
 
 
49
 
 
50
#define G_PI 3.14159265358979f
 
51
#define G_HALF_PI 1.5707963f
 
52
//267948966
 
53
#define G_TWO_PI 6.28318530f
 
54
//71795864
 
55
#define G_ROOT3 1.73205f
 
56
#define G_ROOT2 1.41421f
 
57
#define G_UINT_INFINITY 0xffffffff //!< A very very high value
 
58
#define G_REAL_INFINITY FLT_MAX
 
59
#define G_SIGN_BITMASK                  0x80000000
 
60
#define G_EPSILON SIMD_EPSILON
 
61
 
 
62
 
 
63
 
 
64
enum GIM_SCALAR_TYPES
 
65
{
 
66
        G_STYPE_REAL =0,
 
67
        G_STYPE_REAL2,
 
68
        G_STYPE_SHORT,
 
69
        G_STYPE_USHORT,
 
70
        G_STYPE_INT,
 
71
        G_STYPE_UINT,
 
72
        G_STYPE_INT64,
 
73
        G_STYPE_UINT64
 
74
};
 
75
 
 
76
 
 
77
 
 
78
#define G_DEGTORAD(X) ((X)*3.1415926f/180.0f)
 
79
#define G_RADTODEG(X) ((X)*180.0f/3.1415926f)
 
80
 
 
81
//! Integer representation of a floating-point value.
 
82
#define GIM_IR(x)                                       ((GUINT&)(x))
 
83
 
 
84
//! Signed integer representation of a floating-point value.
 
85
#define GIM_SIR(x)                                      ((GINT&)(x))
 
86
 
 
87
//! Absolute integer representation of a floating-point value
 
88
#define GIM_AIR(x)                                      (GIM_IR(x)&0x7fffffff)
 
89
 
 
90
//! Floating-point representation of an integer value.
 
91
#define GIM_FR(x)                                       ((GREAL&)(x))
 
92
 
 
93
#define GIM_MAX(a,b) (a<b?b:a)
 
94
#define GIM_MIN(a,b) (a>b?b:a)
 
95
 
 
96
#define GIM_MAX3(a,b,c) GIM_MAX(a,GIM_MAX(b,c))
 
97
#define GIM_MIN3(a,b,c) GIM_MIN(a,GIM_MIN(b,c))
 
98
 
 
99
#define GIM_IS_ZERO(value) (value < G_EPSILON &&  value > -G_EPSILON)
 
100
 
 
101
#define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON)
 
102
 
 
103
#define GIM_IS_POSISITVE(value) (value >= G_EPSILON)
 
104
 
 
105
#define GIM_NEAR_EQUAL(v1,v2) GIM_IS_ZERO((v1-v2))
 
106
 
 
107
///returns a clamped number
 
108
#define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number))
 
109
 
 
110
#define GIM_GREATER(x, y)       btFabs(x) > (y)
 
111
 
 
112
///Swap numbers
 
113
#define GIM_SWAP_NUMBERS(a,b){ \
 
114
    a = a+b; \
 
115
    b = a-b; \
 
116
    a = a-b; \
 
117
}\
 
118
 
 
119
#define GIM_INV_SQRT(va,isva)\
 
120
{\
 
121
    if(va<=0.0000001f)\
 
122
    {\
 
123
        isva = G_REAL_INFINITY;\
 
124
    }\
 
125
    else\
 
126
    {\
 
127
        GREAL _x = va * 0.5f;\
 
128
        GUINT _y = 0x5f3759df - ( GIM_IR(va) >> 1);\
 
129
        isva = GIM_FR(_y);\
 
130
        isva  = isva * ( 1.5f - ( _x * isva * isva ) );\
 
131
    }\
 
132
}\
 
133
 
 
134
#define GIM_SQRT(va,sva)\
 
135
{\
 
136
    GIM_INV_SQRT(va,sva);\
 
137
    sva = 1.0f/sva;\
 
138
}\
 
139
 
 
140
//! Computes 1.0f / sqrtf(x). Comes from Quake3. See http://www.magic-software.com/3DGEDInvSqrt.html
 
141
inline GREAL gim_inv_sqrt(GREAL f)
 
142
{
 
143
    GREAL r;
 
144
    GIM_INV_SQRT(f,r);
 
145
    return r;
 
146
}
 
147
 
 
148
inline GREAL gim_sqrt(GREAL f)
 
149
{
 
150
    GREAL r;
 
151
    GIM_SQRT(f,r);
 
152
    return r;
 
153
}
 
154
 
 
155
 
 
156
 
 
157
#endif // GIM_MATH_H_INCLUDED