ReactOS 0.4.15-dev-7924-g5949c20
math.c File Reference
#include "d3drm_private.h"
Include dependency graph for math.c:

Go to the source code of this file.

Functions

D3DCOLOR WINAPI D3DRMCreateColorRGB (D3DVALUE red, D3DVALUE green, D3DVALUE blue)
 
D3DCOLOR WINAPI D3DRMCreateColorRGBA (D3DVALUE red, D3DVALUE green, D3DVALUE blue, D3DVALUE alpha)
 
D3DVALUE WINAPI D3DRMColorGetAlpha (D3DCOLOR color)
 
D3DVALUE WINAPI D3DRMColorGetBlue (D3DCOLOR color)
 
D3DVALUE WINAPI D3DRMColorGetGreen (D3DCOLOR color)
 
D3DVALUE WINAPI D3DRMColorGetRed (D3DCOLOR color)
 
D3DRMQUATERNION *WINAPI D3DRMQuaternionMultiply (D3DRMQUATERNION *q, D3DRMQUATERNION *a, D3DRMQUATERNION *b)
 
void WINAPI D3DRMMatrixFromQuaternion (D3DRMMATRIX4D m, D3DRMQUATERNION *q)
 
D3DRMQUATERNION *WINAPI D3DRMQuaternionFromRotation (D3DRMQUATERNION *q, D3DVECTOR *v, D3DVALUE theta)
 
D3DRMQUATERNION *WINAPI D3DRMQuaternionSlerp (D3DRMQUATERNION *q, D3DRMQUATERNION *a, D3DRMQUATERNION *b, D3DVALUE alpha)
 
D3DVECTOR *WINAPI D3DRMVectorAdd (D3DVECTOR *d, D3DVECTOR *s1, D3DVECTOR *s2)
 
D3DVECTOR *WINAPI D3DRMVectorSubtract (D3DVECTOR *d, D3DVECTOR *s1, D3DVECTOR *s2)
 
D3DVECTOR *WINAPI D3DRMVectorCrossProduct (D3DVECTOR *d, D3DVECTOR *s1, D3DVECTOR *s2)
 
D3DVALUE WINAPI D3DRMVectorDotProduct (D3DVECTOR *s1, D3DVECTOR *s2)
 
D3DVALUE WINAPI D3DRMVectorModulus (D3DVECTOR *v)
 
D3DVECTOR *WINAPI D3DRMVectorNormalize (D3DVECTOR *u)
 
D3DVECTOR *WINAPI D3DRMVectorRandom (D3DVECTOR *d)
 
D3DVECTOR *WINAPI D3DRMVectorReflect (D3DVECTOR *r, D3DVECTOR *ray, D3DVECTOR *norm)
 
D3DVECTOR *WINAPI D3DRMVectorRotate (D3DVECTOR *r, D3DVECTOR *v, D3DVECTOR *axis, D3DVALUE theta)
 
D3DVECTOR *WINAPI D3DRMVectorScale (D3DVECTOR *d, D3DVECTOR *s, D3DVALUE factor)
 

Function Documentation

◆ D3DRMColorGetAlpha()

D3DVALUE WINAPI D3DRMColorGetAlpha ( D3DCOLOR  color)

Definition at line 38 of file math.c.

39{
40 return (RGBA_GETALPHA(color)/255.0);
41}
#define RGBA_GETALPHA(rgb)
Definition: d3dtypes.h:57
GLuint color
Definition: glext.h:6243

Referenced by ColorTest().

◆ D3DRMColorGetBlue()

D3DVALUE WINAPI D3DRMColorGetBlue ( D3DCOLOR  color)

Definition at line 44 of file math.c.

45{
46 return (RGBA_GETBLUE(color)/255.0);
47}
#define RGBA_GETBLUE(rgb)
Definition: d3dtypes.h:60

Referenced by ColorTest().

◆ D3DRMColorGetGreen()

D3DVALUE WINAPI D3DRMColorGetGreen ( D3DCOLOR  color)

Definition at line 50 of file math.c.

51{
52 return (RGBA_GETGREEN(color)/255.0);
53}
#define RGBA_GETGREEN(rgb)
Definition: d3dtypes.h:59

Referenced by ColorTest().

◆ D3DRMColorGetRed()

D3DVALUE WINAPI D3DRMColorGetRed ( D3DCOLOR  color)

Definition at line 56 of file math.c.

57{
58 return (RGBA_GETRED(color)/255.0);
59}
#define RGBA_GETRED(rgb)
Definition: d3dtypes.h:58

Referenced by ColorTest().

◆ D3DRMCreateColorRGB()

D3DCOLOR WINAPI D3DRMCreateColorRGB ( D3DVALUE  red,
D3DVALUE  green,
D3DVALUE  blue 
)

Definition at line 23 of file math.c.

24{
25 return D3DRMCreateColorRGBA(red, green, blue, 1.0f);
26}
D3DCOLOR WINAPI D3DRMCreateColorRGBA(D3DVALUE red, D3DVALUE green, D3DVALUE blue, D3DVALUE alpha)
Definition: math.c:28
GLclampf green
Definition: gl.h:1740
GLclampf GLclampf blue
Definition: gl.h:1740
#define red
Definition: linetest.c:67

Referenced by ColorTest().

◆ D3DRMCreateColorRGBA()

D3DCOLOR WINAPI D3DRMCreateColorRGBA ( D3DVALUE  red,
D3DVALUE  green,
D3DVALUE  blue,
D3DVALUE  alpha 
)

Definition at line 28 of file math.c.

29{
31
33
34 return color;
35}
static void d3drm_set_color(D3DCOLOR *color, float r, float g, float b, float a)
GLclampf GLclampf GLclampf alpha
Definition: gl.h:1740

Referenced by ColorTest(), and D3DRMCreateColorRGB().

◆ D3DRMMatrixFromQuaternion()

void WINAPI D3DRMMatrixFromQuaternion ( D3DRMMATRIX4D  m,
D3DRMQUATERNION q 
)

Definition at line 78 of file math.c.

79{
80 D3DVALUE w,x,y,z;
81 w = q->s;
82 x = q->v.u1.x;
83 y = q->v.u2.y;
84 z = q->v.u3.z;
85 m[0][0] = 1.0-2.0*(y*y+z*z);
86 m[1][1] = 1.0-2.0*(x*x+z*z);
87 m[2][2] = 1.0-2.0*(x*x+y*y);
88 m[1][0] = 2.0*(x*y+z*w);
89 m[0][1] = 2.0*(x*y-z*w);
90 m[2][0] = 2.0*(x*z-y*w);
91 m[0][2] = 2.0*(x*z+y*w);
92 m[2][1] = 2.0*(y*z+x*w);
93 m[1][2] = 2.0*(y*z-x*w);
94 m[3][0] = 0.0;
95 m[3][1] = 0.0;
96 m[3][2] = 0.0;
97 m[0][3] = 0.0;
98 m[1][3] = 0.0;
99 m[2][3] = 0.0;
100 m[3][3] = 1.0;
101}
float D3DVALUE
Definition: d3dtypes.h:89
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLdouble GLdouble z
Definition: glext.h:5874
const GLfloat * m
Definition: glext.h:10848

Referenced by MatrixTest().

◆ D3DRMQuaternionFromRotation()

D3DRMQUATERNION *WINAPI D3DRMQuaternionFromRotation ( D3DRMQUATERNION q,
D3DVECTOR v,
D3DVALUE  theta 
)

Definition at line 104 of file math.c.

105{
106 q->s = cos(theta/2.0);
107 D3DRMVectorScale(&q->v, D3DRMVectorNormalize(v), sin(theta/2.0));
108 return q;
109}
_STLP_DECLSPEC complex< float > _STLP_CALL cos(const complex< float > &)
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)
D3DVECTOR *WINAPI D3DRMVectorScale(D3DVECTOR *d, D3DVECTOR *s, D3DVALUE factor)
Definition: math.c:253
D3DVECTOR *WINAPI D3DRMVectorNormalize(D3DVECTOR *u)
Definition: math.c:196
const GLdouble * v
Definition: gl.h:2040

Referenced by QuaternionTest(), and test_animation().

◆ D3DRMQuaternionMultiply()

D3DRMQUATERNION *WINAPI D3DRMQuaternionMultiply ( D3DRMQUATERNION q,
D3DRMQUATERNION a,
D3DRMQUATERNION b 
)

Definition at line 62 of file math.c.

63{
65 D3DVECTOR cross_product;
66
67 D3DRMVectorCrossProduct(&cross_product, &a->v, &b->v);
68 temp.s = a->s * b->s - D3DRMVectorDotProduct(&a->v, &b->v);
69 temp.v.u1.x = a->s * b->v.u1.x + b->s * a->v.u1.x + cross_product.u1.x;
70 temp.v.u2.y = a->s * b->v.u2.y + b->s * a->v.u2.y + cross_product.u2.y;
71 temp.v.u3.z = a->s * b->v.u3.z + b->s * a->v.u3.z + cross_product.u3.z;
72
73 *q = temp;
74 return q;
75}
D3DVECTOR *WINAPI D3DRMVectorCrossProduct(D3DVECTOR *d, D3DVECTOR *s1, D3DVECTOR *s2)
Definition: math.c:167
D3DVALUE WINAPI D3DRMVectorDotProduct(D3DVECTOR *s1, D3DVECTOR *s2)
Definition: math.c:180
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
static calc_node_t temp
Definition: rpn_ieee.c:38

Referenced by D3DRMVectorRotate().

◆ D3DRMQuaternionSlerp()

D3DRMQUATERNION *WINAPI D3DRMQuaternionSlerp ( D3DRMQUATERNION q,
D3DRMQUATERNION a,
D3DRMQUATERNION b,
D3DVALUE  alpha 
)

Definition at line 112 of file math.c.

114{
115 D3DVALUE dot, epsilon, temp, theta, u;
116 D3DVECTOR v1, v2;
117
118 dot = a->s * b->s + D3DRMVectorDotProduct(&a->v, &b->v);
119 epsilon = 1.0f;
120 temp = 1.0f - alpha;
121 u = alpha;
122 if (dot < 0.0)
123 {
124 epsilon = -1.0;
125 dot = -dot;
126 }
127 if( 1.0f - dot > 0.001f )
128 {
129 theta = acos(dot);
130 temp = sin(theta * temp) / sin(theta);
131 u = sin(theta * alpha) / sin(theta);
132 }
133 q->s = temp * a->s + epsilon * u * b->s;
134 D3DRMVectorScale(&v1, &a->v, temp);
135 D3DRMVectorScale(&v2, &b->v, epsilon * u);
136 D3DRMVectorAdd(&q->v, &v1, &v2);
137 return q;
138}
valarray< _Tp > acos(const valarray< _Tp > &__x)
Definition: _valarray.h:901
D3DVECTOR *WINAPI D3DRMVectorAdd(D3DVECTOR *d, D3DVECTOR *s1, D3DVECTOR *s2)
Definition: math.c:141
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240

Referenced by QuaternionTest().

◆ D3DRMVectorAdd()

D3DVECTOR *WINAPI D3DRMVectorAdd ( D3DVECTOR d,
D3DVECTOR s1,
D3DVECTOR s2 
)

Definition at line 141 of file math.c.

142{
144
145 temp.u1.x=s1->u1.x + s2->u1.x;
146 temp.u2.y=s1->u2.y + s2->u2.y;
147 temp.u3.z=s1->u3.z + s2->u3.z;
148
149 *d = temp;
150 return d;
151}
#define d
Definition: ke_i.h:81
struct S1 s1
struct S2 s2

Referenced by D3DRMQuaternionSlerp(), load_mesh_data(), and VectorTest().

◆ D3DRMVectorCrossProduct()

D3DVECTOR *WINAPI D3DRMVectorCrossProduct ( D3DVECTOR d,
D3DVECTOR s1,
D3DVECTOR s2 
)

Definition at line 167 of file math.c.

168{
170
171 temp.u1.x=s1->u2.y * s2->u3.z - s1->u3.z * s2->u2.y;
172 temp.u2.y=s1->u3.z * s2->u1.x - s1->u1.x * s2->u3.z;
173 temp.u3.z=s1->u1.x * s2->u2.y - s1->u2.y * s2->u1.x;
174
175 *d = temp;
176 return d;
177}

Referenced by D3DRMQuaternionMultiply(), load_mesh_data(), and VectorTest().

◆ D3DRMVectorDotProduct()

D3DVALUE WINAPI D3DRMVectorDotProduct ( D3DVECTOR s1,
D3DVECTOR s2 
)

Definition at line 180 of file math.c.

181{
182 D3DVALUE dot_product;
183 dot_product=s1->u1.x * s2->u1.x + s1->u2.y * s2->u2.y + s1->u3.z * s2->u3.z;
184 return dot_product;
185}

Referenced by D3DRMQuaternionMultiply(), D3DRMQuaternionSlerp(), D3DRMVectorReflect(), and VectorTest().

◆ D3DRMVectorModulus()

D3DVALUE WINAPI D3DRMVectorModulus ( D3DVECTOR v)

Definition at line 188 of file math.c.

189{
191 result=sqrt(v->u1.x * v->u1.x + v->u2.y * v->u2.y + v->u3.z * v->u3.z);
192 return result;
193}
_STLP_DECLSPEC complex< float > _STLP_CALL sqrt(const complex< float > &)
Definition: complex.cpp:188
GLuint64EXT * result
Definition: glext.h:11304

Referenced by D3DRMVectorNormalize(), and VectorTest().

◆ D3DRMVectorNormalize()

D3DVECTOR *WINAPI D3DRMVectorNormalize ( D3DVECTOR u)

Definition at line 196 of file math.c.

197{
199 if(modulus)
200 {
202 }
203 else
204 {
205 u->u1.x=1.0;
206 u->u2.y=0.0;
207 u->u3.z=0.0;
208 }
209 return u;
210}
D3DVALUE WINAPI D3DRMVectorModulus(D3DVECTOR *v)
Definition: math.c:188

Referenced by d3drm_matrix_set_rotation(), D3DRMQuaternionFromRotation(), D3DRMVectorRandom(), D3DRMVectorRotate(), load_mesh_data(), and VectorTest().

◆ D3DRMVectorRandom()

D3DVECTOR *WINAPI D3DRMVectorRandom ( D3DVECTOR d)

Definition at line 213 of file math.c.

214{
215 d->u1.x = rand();
216 d->u2.y = rand();
217 d->u3.z = rand();
219 return d;
220}
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10

◆ D3DRMVectorReflect()

D3DVECTOR *WINAPI D3DRMVectorReflect ( D3DVECTOR r,
D3DVECTOR ray,
D3DVECTOR norm 
)

Definition at line 223 of file math.c.

224{
225 D3DVECTOR sca, temp;
227
228 *r = temp;
229 return r;
230}
_Tp _STLP_CALL norm(const complex< _Tp > &__z)
Definition: _complex.h:741
D3DVECTOR *WINAPI D3DRMVectorSubtract(D3DVECTOR *d, D3DVECTOR *s1, D3DVECTOR *s2)
Definition: math.c:154
GLdouble GLdouble GLdouble r
Definition: gl.h:2055

Referenced by VectorTest().

◆ D3DRMVectorRotate()

D3DVECTOR *WINAPI D3DRMVectorRotate ( D3DVECTOR r,
D3DVECTOR v,
D3DVECTOR axis,
D3DVALUE  theta 
)

Definition at line 233 of file math.c.

234{
235 D3DRMQUATERNION quaternion1, quaternion2, quaternion3;
237
238 quaternion1.s = cos(theta * 0.5f);
239 quaternion2.s = cos(theta * 0.5f);
240 norm = *D3DRMVectorNormalize(axis);
241 D3DRMVectorScale(&quaternion1.v, &norm, sin(theta * 0.5f));
242 D3DRMVectorScale(&quaternion2.v, &norm, -sin(theta * 0.5f));
243 quaternion3.s = 0.0;
244 quaternion3.v = *v;
245 D3DRMQuaternionMultiply(&quaternion1, &quaternion1, &quaternion3);
246 D3DRMQuaternionMultiply(&quaternion1, &quaternion1, &quaternion2);
247
248 *r = *D3DRMVectorNormalize(&quaternion1.v);
249 return r;
250}
D3DRMQUATERNION *WINAPI D3DRMQuaternionMultiply(D3DRMQUATERNION *q, D3DRMQUATERNION *a, D3DRMQUATERNION *b)
Definition: math.c:62
D3DVALUE s
Definition: d3drmdef.h:42
D3DVECTOR v
Definition: d3drmdef.h:43

Referenced by VectorTest().

◆ D3DRMVectorScale()

D3DVECTOR *WINAPI D3DRMVectorScale ( D3DVECTOR d,
D3DVECTOR s,
D3DVALUE  factor 
)

Definition at line 253 of file math.c.

254{
256
257 temp.u1.x=factor * s->u1.x;
258 temp.u2.y=factor * s->u2.y;
259 temp.u3.z=factor * s->u3.z;
260
261 *d = temp;
262 return d;
263}
GLdouble s
Definition: gl.h:2039
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint factor
Definition: glfuncs.h:178

Referenced by D3DRMQuaternionFromRotation(), D3DRMQuaternionSlerp(), D3DRMVectorNormalize(), D3DRMVectorReflect(), D3DRMVectorRotate(), and VectorTest().

◆ D3DRMVectorSubtract()

D3DVECTOR *WINAPI D3DRMVectorSubtract ( D3DVECTOR d,
D3DVECTOR s1,
D3DVECTOR s2 
)

Definition at line 154 of file math.c.

155{
157
158 temp.u1.x=s1->u1.x - s2->u1.x;
159 temp.u2.y=s1->u2.y - s2->u2.y;
160 temp.u3.z=s1->u3.z - s2->u3.z;
161
162 *d = temp;
163 return d;
164}

Referenced by D3DRMVectorReflect(), load_mesh_data(), and VectorTest().