1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 
20 //
21 // rb_math.c
22 //
23 
24 #include "rb_local.h"
25 
26 /*
27 ==============
28 RB_FastSin
29 ==============
30 */
RB_FastSin(float t)31 float RB_FastSin (float t)
32 {
33 	return FTABLE_EVALUATE(rb_sinTable, t);
34 }
35 
36 
37 /*
38 ==============
39 RB_TableForFunc
40 ==============
41 */
RB_TableForFunc(shTableFunc_t func)42 float *RB_TableForFunc (shTableFunc_t func)
43 {
44 	switch (func) {
45 	case SHADER_FUNC_SIN:				return rb_sinTable;
46 	case SHADER_FUNC_TRIANGLE:			return rb_triangleTable;
47 	case SHADER_FUNC_SQUARE:			return rb_squareTable;
48 	case SHADER_FUNC_SAWTOOTH:			return rb_sawtoothTable;
49 	case SHADER_FUNC_INVERSESAWTOOTH:	return rb_inverseSawtoothTable;
50 	case SHADER_FUNC_NOISE:				return rb_noiseTable;
51 	}
52 
53 	// Assume error
54 	Com_Error (ERR_DROP, "RB_TableForFunc: unknown function");
55 
56 	return NULL;
57 }
58 
59 
60 /*
61 ===============
62 Matrix4_Copy2D
63 ===============
64 */
Matrix4_Copy2D(const mat4x4_t m1,mat4x4_t m2)65 void Matrix4_Copy2D (const mat4x4_t m1, mat4x4_t m2)
66 {
67 	m2[0] = m1[0];
68 	m2[1] = m1[1];
69 	m2[4] = m1[4];
70 	m2[5] = m1[5];
71 	m2[12] = m1[12];
72 	m2[13] = m1[13];
73 }
74 
75 
76 /*
77 ===============
78 Matrix4_Multiply2D
79 ===============
80 */
Matrix4_Multiply2D(const mat4x4_t m1,const mat4x4_t m2,mat4x4_t out)81 void Matrix4_Multiply2D (const mat4x4_t m1, const mat4x4_t m2, mat4x4_t out)
82 {
83 	out[0]  = m1[0] * m2[0] + m1[4] * m2[1];
84 	out[1]  = m1[1] * m2[0] + m1[5] * m2[1];
85 	out[4]  = m1[0] * m2[4] + m1[4] * m2[5];
86 	out[5]  = m1[1] * m2[4] + m1[5] * m2[5];
87 	out[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[12];
88 	out[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[13];
89 }
90 
91 
92 /*
93 ===============
94 Matrix4_Scale2D
95 ===============
96 */
Matrix4_Scale2D(mat4x4_t m,float x,float y)97 void Matrix4_Scale2D (mat4x4_t m, float x, float y)
98 {
99 	m[0] *= x;
100 	m[1] *= x;
101 	m[4] *= y;
102 	m[5] *= y;
103 }
104 
105 
106 /*
107 ===============
108 Matrix4_Stretch2D
109 ===============
110 */
Matrix4_Stretch2D(mat4x4_t m,float s,float t)111 void Matrix4_Stretch2D (mat4x4_t m, float s, float t)
112 {
113 	m[0] *= s;
114 	m[1] *= s;
115 	m[4] *= s;
116 	m[5] *= s;
117 	m[12] = s * m[12] + t;
118 	m[13] = s * m[13] + t;
119 }
120 
121 
122 /*
123 ===============
124 Matrix4_Translate2D
125 ===============
126 */
Matrix4_Translate2D(mat4x4_t m,float x,float y)127 void Matrix4_Translate2D (mat4x4_t m, float x, float y)
128 {
129 	m[12] += x;
130 	m[13] += y;
131 }
132