summaryrefslogtreecommitdiff
path: root/include/glu3_scalar.h
blob: eadc6d433905fdaa4e7c4497f8259f1973886d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include <math.h>

extern inline GLUvec4 gluMult4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] * v2->values[0];
	result.values[1] = v1->values[1] * v2->values[1];
	result.values[2] = v1->values[2] * v2->values[2];
	result.values[3] = v1->values[3] * v2->values[3];

	return result;
}


extern inline GLUvec4 gluDiv4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] / v2->values[0];
	result.values[1] = v1->values[1] / v2->values[1];
	result.values[2] = v1->values[2] / v2->values[2];
	result.values[3] = v1->values[3] / v2->values[3];

	return result;
}


extern inline GLUvec4 gluAdd4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] + v2->values[0];
	result.values[1] = v1->values[1] + v2->values[1];
	result.values[2] = v1->values[2] + v2->values[2];
	result.values[3] = v1->values[3] + v2->values[3];

	return result;
}


extern inline GLUvec4 gluSub4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] - v2->values[0];
	result.values[1] = v1->values[1] - v2->values[1];
	result.values[2] = v1->values[2] - v2->values[2];
	result.values[3] = v1->values[3] - v2->values[3];

	return result;
}


extern inline GLUvec4 gluMult4v_f(const GLUvec4 *v1, GLfloat f)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] * f;
	result.values[1] = v1->values[1] * f;
	result.values[2] = v1->values[2] * f;
	result.values[3] = v1->values[3] * f;

	return result;
}


extern inline GLUvec4 gluDiv4v_f(const GLUvec4 *v1, GLfloat f)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] / f;
	result.values[1] = v1->values[1] / f;
	result.values[2] = v1->values[2] / f;
	result.values[3] = v1->values[3] / f;

	return result;
}


extern inline GLUvec4 gluAdd4v_f(const GLUvec4 *v1, GLfloat f)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] + f;
	result.values[1] = v1->values[1] + f;
	result.values[2] = v1->values[2] + f;
	result.values[3] = v1->values[3] + f;

	return result;
}


extern inline GLUvec4 gluSub4v_f(const GLUvec4 *v1, GLfloat f)
{
	GLUvec4 result;

	result.values[0] = v1->values[0] - f;
	result.values[1] = v1->values[1] - f;
	result.values[2] = v1->values[2] - f;
	result.values[3] = v1->values[3] - f;

	return result;
}


extern inline GLUmat4 gluMult4m_f(const GLUmat4 *m, GLfloat f)
{
	GLUmat4 result;

	result.col[0] = gluMult4v_f(& m->col[0], f);
	result.col[1] = gluMult4v_f(& m->col[1], f);
	result.col[2] = gluMult4v_f(& m->col[2], f);
	result.col[3] = gluMult4v_f(& m->col[3], f);

	return result;
}


extern inline GLUvec4 gluMult4m_4v(const GLUmat4 *m, const GLUvec4 *v)
{
	GLUvec4 a = gluMult4v_f(& m->col[0], v->values[0]);
	GLUvec4 b = gluMult4v_f(& m->col[1], v->values[1]);
	GLUvec4 c = gluMult4v_f(& m->col[2], v->values[2]);
	GLUvec4 d = gluMult4v_f(& m->col[3], v->values[3]);

	a = gluAdd4v_4v(&a, &b);
	c = gluAdd4v_4v(&c, &d);

	return gluAdd4v_4v(&a, &c);
}


extern inline GLUmat4 gluAdd4m_4m(const GLUmat4 *m1, const GLUmat4 *m2)
{
	GLUmat4 result;

	result.col[0] = gluAdd4v_4v(& m1->col[0], & m2->col[0]);
	result.col[1] = gluAdd4v_4v(& m1->col[1], & m2->col[1]);
	result.col[2] = gluAdd4v_4v(& m1->col[2], & m2->col[2]);
	result.col[3] = gluAdd4v_4v(& m1->col[3], & m2->col[3]);

	return result;
}

extern inline GLUmat4 gluSub4m_4m(const GLUmat4 *m1, const GLUmat4 *m2)
{
	GLUmat4 result;

	result.col[0] = gluSub4v_4v(& m1->col[0], & m2->col[0]);
	result.col[1] = gluSub4v_4v(& m1->col[1], & m2->col[1]);
	result.col[2] = gluSub4v_4v(& m1->col[2], & m2->col[2]);
	result.col[3] = gluSub4v_4v(& m1->col[3], & m2->col[3]);

	return result;
}

extern inline GLfloat gluDot4_4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	return v1->values[0] * v2->values[0]
		+ v1->values[1] * v2->values[1]
		+ v1->values[2] * v2->values[2]
		+ v1->values[3] * v2->values[3];
}


extern inline GLfloat gluDot3_4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	return v1->values[0] * v2->values[0]
		+ v1->values[1] * v2->values[1]
		+ v1->values[2] * v2->values[2];
}


extern inline GLfloat gluDot2_4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	return v1->values[0] * v2->values[0]
		+ v1->values[1] * v2->values[1];
}


extern inline GLUvec4 gluCross4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	GLUvec4 result;

	result.values[0] = (v1->values[1] * v2->values[2]) 
		- (v1->values[2] * v2->values[1]);
	result.values[1] = (v1->values[2] * v2->values[0]) 
		- (v1->values[0] * v2->values[2]);
	result.values[2] = (v1->values[0] * v2->values[1]) 
		- (v1->values[1] * v2->values[0]);
	result.values[3] = 0.0;

	return result;
}


extern inline GLUmat4 gluOuter4v(const GLUvec4 *v1, const GLUvec4 *v2)
{
	GLUmat4 result;

	result.col[0] = gluMult4v_f(v1, v2->values[0]);
	result.col[1] = gluMult4v_f(v1, v2->values[1]);
	result.col[2] = gluMult4v_f(v1, v2->values[2]);
	result.col[3] = gluMult4v_f(v1, v2->values[3]);

	return result;
}


extern inline GLfloat gluLengthSqr4v(const GLUvec4 *v)
{
	return gluDot4_4v(v, v);
}


extern inline GLfloat gluLength4v(const GLUvec4 *v)
{
	return sqrt(gluLengthSqr4v(v));
}


extern inline GLUvec4 gluNormalize4v(const GLUvec4 *v)
{
	return gluDiv4v_f(v, gluLength4v(v));
}



extern inline GLUmat4 gluTranspose4(const GLUmat4 *m)
{
	unsigned i;
	unsigned j;
	GLUmat4 result;

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			result.col[i].values[j] = m->col[j].values[i];
		}
	}

	return result;
}


extern inline GLUmat4 gluMult4m_4m(const GLUmat4 *m1, const GLUmat4 *m2)
{
	GLUmat4 result;
	unsigned i;

	for (i = 0; i < 4; i++) {
		result.col[i] = gluMult4m_4v(m1, & m2->col[i]);
	}

	return result;
}



extern inline GLUmat4 gluTranslate3(GLfloat x, GLfloat y, GLfloat z)
{
	GLUmat4 result;

	memcpy(&result, & gluIdentityMatrix, sizeof(result));
	result.col[3].values[0] = x;
	result.col[3].values[1] = y;
	result.col[3].values[2] = z;

	return result;
}


#ifdef __cplusplus
extern inline GLfloat gluDot4(const GLUvec4 &v1, const GLUvec4 &v2)
{
	return v1.values[0] * v2.values[0]
		+ v1.values[1] * v2.values[1]
		+ v1.values[2] * v2.values[2]
		+ v1.values[3] * v2.values[3];
}


extern inline GLfloat gluDot3(const GLUvec4 &v1, const GLUvec4 &v2)
{
	return v1.values[0] * v2.values[0]
		+ v1.values[1] * v2.values[1]
		+ v1.values[2] * v2.values[2];
}


extern inline GLfloat gluDot2(const GLUvec4 &v1, const GLUvec4 &v2)
{
	return v1.values[0] * v2.values[0]
		+ v1.values[1] * v2.values[1];
}


inline GLUvec4 GLUvec4::operator+(const GLUvec4 &v) const
{
	return GLUvec4(values[0] + v.values[0],
		       values[1] + v.values[1],
		       values[2] + v.values[2],
		       values[3] + v.values[3]);
}


inline GLUvec4 GLUvec4::operator-(const GLUvec4 &v) const
{
	return GLUvec4(values[0] - v.values[0],
		       values[1] - v.values[1],
		       values[2] - v.values[2],
		       values[3] - v.values[3]);
}


inline GLUvec4 GLUvec4::operator*(const GLUvec4 &v) const
{
	return GLUvec4(values[0] * v.values[0],
		       values[1] * v.values[1],
		       values[2] * v.values[2],
		       values[3] * v.values[3]);
}


inline GLUvec4 GLUvec4::operator*(GLfloat f) const
{
	return GLUvec4(values[0] * f,
		       values[1] * f,
		       values[2] * f,
		       values[3] * f);
}


inline GLUvec4 GLUvec4::operator*(const GLUmat4 &m) const
{
	return GLUvec4(gluDot4(*this, m.col[0]),
		       gluDot4(*this, m.col[1]),
		       gluDot4(*this, m.col[2]),
		       gluDot4(*this, m.col[3]));
}


inline GLUmat4 GLUmat4::operator+(const GLUmat4 &m) const
{
	return gluAdd4m_4m(this, &m);
}


inline GLUmat4 GLUmat4::operator-(const GLUmat4 &m) const
{
	return GLUmat4(col[0] - m.col[0],
		       col[1] - m.col[1],
		       col[2] - m.col[2],
		       col[3] - m.col[3]);
}


inline GLUmat4 GLUmat4::operator*(GLfloat f) const
{
	return gluMult4m_f(this, f);
}


inline GLUvec4 GLUmat4::operator*(const GLUvec4 &v) const
{
	return (col[0] * v.values[0])
		+ (col[1] * v.values[1])
		+ (col[2] * v.values[2])
		+ (col[3] * v.values[3]);
}


inline GLUmat4 GLUmat4::operator*(const GLUmat4 &m) const
{
	return gluMult4m_4m(this, &m);
}


#endif /* __cplusplus */