1/*!****************************************************************************
2
3 @file         PVRTMatrix.h
4 @copyright    Copyright (c) Imagination Technologies Limited.
5 @brief        Vector and Matrix functions for floating and fixed point math.
6 @details      The general matrix format used is directly compatible with, for
7               example, both DirectX and OpenGL.
8
9******************************************************************************/
10#ifndef _PVRTMATRIX_H_
11#define _PVRTMATRIX_H_
12
13#include "PVRTGlobal.h"
14/****************************************************************************
15** Defines
16****************************************************************************/
17#define MAT00 0
18#define MAT01 1
19#define MAT02 2
20#define MAT03 3
21#define MAT10 4
22#define MAT11 5
23#define MAT12 6
24#define MAT13 7
25#define MAT20 8
26#define MAT21 9
27#define MAT22 10
28#define MAT23 11
29#define MAT30 12
30#define MAT31 13
31#define MAT32 14
32#define MAT33 15
33
34/****************************************************************************
35** Typedefs
36****************************************************************************/
37/*!***************************************************************************
38 @brief     2D floating point vector
39*****************************************************************************/
40typedef struct
41{
42	float x;	/*!< x coordinate */
43	float y;	/*!< y coordinate */
44} PVRTVECTOR2f;
45
46/*!***************************************************************************
47 @brief     2D fixed point vector
48*****************************************************************************/
49typedef struct
50{
51	int x;	/*!< x coordinate */
52	int y;	/*!< y coordinate */
53} PVRTVECTOR2x;
54
55/*!***************************************************************************
56 @brief     3D floating point vector
57*****************************************************************************/
58typedef struct
59{
60	float x;	/*!< x coordinate */
61	float y;	/*!< y coordinate */
62	float z;	/*!< z coordinate */
63} PVRTVECTOR3f;
64
65/*!***************************************************************************
66 @brief     3D fixed point vector
67*****************************************************************************/
68typedef struct
69{
70	int x;	/*!< x coordinate */
71	int y;	/*!< y coordinate */
72	int z;	/*!< z coordinate */
73} PVRTVECTOR3x;
74
75/*!***************************************************************************
76 @brief     4D floating point vector
77*****************************************************************************/
78typedef struct
79{
80	float x;	/*!< x coordinate */
81	float y;	/*!< y coordinate */
82	float z;	/*!< z coordinate */
83	float w;	/*!< w coordinate */
84} PVRTVECTOR4f;
85
86/*!***************************************************************************
87 @brief     4D fixed point vector
88*****************************************************************************/
89typedef struct
90{
91	int x;	/*!< x coordinate */
92	int y;	/*!< y coordinate */
93	int z;	/*!< z coordinate */
94	int w;	/*!< w coordinate */
95} PVRTVECTOR4x;
96
97/*!***************************************************************************
98 @class     PVRTMATRIXf
99 @brief     4x4 floating point matrix
100*****************************************************************************/
101class PVRTMATRIXf
102{
103public:
104    float* operator [] ( const int Row )
105	{
106		return &f[Row<<2];
107	}
108	float f[16];	/*!< Array of float */
109};
110
111/*!***************************************************************************
112 @class     PVRTMATRIXx
113 @brief     4x4 fixed point matrix
114*****************************************************************************/
115class PVRTMATRIXx
116{
117public:
118    int* operator [] ( const int Row )
119	{
120		return &f[Row<<2];
121	}
122	int f[16];
123};
124
125/*!***************************************************************************
126 @class     PVRTMATRIX3f
127 @brief     3x3 floating point matrix
128*****************************************************************************/
129
130class PVRTMATRIX3f
131{
132public:
133    float* operator [] ( const int Row )
134	{
135		return &f[Row*3];
136	}
137	float f[9];	/*!< Array of float */
138};
139
140/*!***************************************************************************
141 @class     PVRTMATRIX3x
142 @brief     3x3 fixed point matrix
143*****************************************************************************/
144class PVRTMATRIX3x
145{
146public:
147    int* operator [] ( const int Row )
148	{
149		return &f[Row*3];
150	}
151	int f[9];
152};
153
154
155/****************************************************************************
156** Float or fixed
157****************************************************************************/
158#ifdef PVRT_FIXED_POINT_ENABLE
159	typedef PVRTVECTOR2x		PVRTVECTOR2;
160	typedef PVRTVECTOR3x		PVRTVECTOR3;
161	typedef PVRTVECTOR4x		PVRTVECTOR4;
162	typedef PVRTMATRIX3x		PVRTMATRIX3;
163	typedef PVRTMATRIXx			PVRTMATRIX;
164	#define PVRTMatrixIdentity					PVRTMatrixIdentityX
165	#define PVRTMatrixMultiply					PVRTMatrixMultiplyX
166	#define PVRTMatrixTranslation				PVRTMatrixTranslationX
167	#define PVRTMatrixScaling					PVRTMatrixScalingX
168	#define PVRTMatrixRotationX					PVRTMatrixRotationXX
169	#define PVRTMatrixRotationY					PVRTMatrixRotationYX
170	#define PVRTMatrixRotationZ					PVRTMatrixRotationZX
171	#define PVRTMatrixTranspose					PVRTMatrixTransposeX
172	#define PVRTMatrixInverse					PVRTMatrixInverseX
173	#define PVRTMatrixInverseEx					PVRTMatrixInverseExX
174	#define PVRTMatrixLookAtLH					PVRTMatrixLookAtLHX
175	#define PVRTMatrixLookAtRH					PVRTMatrixLookAtRHX
176	#define PVRTMatrixPerspectiveFovLH			PVRTMatrixPerspectiveFovLHX
177	#define PVRTMatrixPerspectiveFovRH			PVRTMatrixPerspectiveFovRHX
178	#define PVRTMatrixOrthoLH					PVRTMatrixOrthoLHX
179	#define PVRTMatrixOrthoRH					PVRTMatrixOrthoRHX
180	#define PVRTMatrixVec3Lerp					PVRTMatrixVec3LerpX
181	#define PVRTMatrixVec3DotProduct			PVRTMatrixVec3DotProductX
182	#define PVRTMatrixVec3CrossProduct			PVRTMatrixVec3CrossProductX
183	#define PVRTMatrixVec3Normalize				PVRTMatrixVec3NormalizeX
184	#define PVRTMatrixVec3Length				PVRTMatrixVec3LengthX
185	#define PVRTMatrixLinearEqSolve				PVRTMatrixLinearEqSolveX
186#else
187	typedef PVRTVECTOR2f		PVRTVECTOR2;
188	typedef PVRTVECTOR3f		PVRTVECTOR3;
189	typedef PVRTVECTOR4f		PVRTVECTOR4;
190	typedef PVRTMATRIX3f		PVRTMATRIX3;
191	typedef PVRTMATRIXf			PVRTMATRIX;
192	#define PVRTMatrixIdentity					PVRTMatrixIdentityF
193	#define PVRTMatrixMultiply					PVRTMatrixMultiplyF
194	#define PVRTMatrixTranslation				PVRTMatrixTranslationF
195	#define PVRTMatrixScaling					PVRTMatrixScalingF
196	#define PVRTMatrixRotationX					PVRTMatrixRotationXF
197	#define PVRTMatrixRotationY					PVRTMatrixRotationYF
198	#define PVRTMatrixRotationZ					PVRTMatrixRotationZF
199	#define PVRTMatrixTranspose					PVRTMatrixTransposeF
200	#define PVRTMatrixInverse					PVRTMatrixInverseF
201	#define PVRTMatrixInverseEx					PVRTMatrixInverseExF
202	#define PVRTMatrixLookAtLH					PVRTMatrixLookAtLHF
203	#define PVRTMatrixLookAtRH					PVRTMatrixLookAtRHF
204	#define PVRTMatrixPerspectiveFovLH			PVRTMatrixPerspectiveFovLHF
205	#define PVRTMatrixPerspectiveFovRH			PVRTMatrixPerspectiveFovRHF
206	#define PVRTMatrixOrthoLH					PVRTMatrixOrthoLHF
207	#define PVRTMatrixOrthoRH					PVRTMatrixOrthoRHF
208	#define PVRTMatrixVec3Lerp					PVRTMatrixVec3LerpF
209	#define PVRTMatrixVec3DotProduct			PVRTMatrixVec3DotProductF
210	#define PVRTMatrixVec3CrossProduct			PVRTMatrixVec3CrossProductF
211	#define PVRTMatrixVec3Normalize				PVRTMatrixVec3NormalizeF
212	#define PVRTMatrixVec3Length				PVRTMatrixVec3LengthF
213	#define PVRTMatrixLinearEqSolve				PVRTMatrixLinearEqSolveF
214#endif
215
216/****************************************************************************
217** Functions
218****************************************************************************/
219
220/*!***************************************************************************
221 @fn      			PVRTMatrixIdentityF
222 @param[out]			mOut	Set to identity
223 @brief      		Reset matrix to identity matrix.
224*****************************************************************************/
225void PVRTMatrixIdentityF(PVRTMATRIXf &mOut);
226
227/*!***************************************************************************
228 @fn      			PVRTMatrixIdentityX
229 @param[out]			mOut	Set to identity
230 @brief      		Reset matrix to identity matrix.
231*****************************************************************************/
232void PVRTMatrixIdentityX(PVRTMATRIXx &mOut);
233
234/*!***************************************************************************
235 @fn      			PVRTMatrixMultiplyF
236 @param[out]			mOut	Result of mA x mB
237 @param[in]				mA		First operand
238 @param[in]				mB		Second operand
239 @brief      		Multiply mA by mB and assign the result to mOut
240					(mOut = p1 * p2). A copy of the result matrix is done in
241					the function because mOut can be a parameter mA or mB.
242*****************************************************************************/
243void PVRTMatrixMultiplyF(
244	PVRTMATRIXf			&mOut,
245	const PVRTMATRIXf	&mA,
246	const PVRTMATRIXf	&mB);
247/*!***************************************************************************
248 @fn      			PVRTMatrixMultiplyX
249 @param[out]			mOut	Result of mA x mB
250 @param[in]				mA		First operand
251 @param[in]				mB		Second operand
252 @brief      		Multiply mA by mB and assign the result to mOut
253					(mOut = p1 * p2). A copy of the result matrix is done in
254					the function because mOut can be a parameter mA or mB.
255					The fixed-point shift could be performed after adding
256					all four intermediate results together however this might
257					cause some overflow issues.
258*****************************************************************************/
259void PVRTMatrixMultiplyX(
260	PVRTMATRIXx			&mOut,
261	const PVRTMATRIXx	&mA,
262	const PVRTMATRIXx	&mB);
263
264/*!***************************************************************************
265 @fn           		PVRTMatrixTranslationF
266 @param[out]			mOut	Translation matrix
267 @param[in]				fX		X component of the translation
268 @param[in]				fY		Y component of the translation
269 @param[in]				fZ		Z component of the translation
270 @brief      		Build a transaltion matrix mOut using fX, fY and fZ.
271*****************************************************************************/
272void PVRTMatrixTranslationF(
273	PVRTMATRIXf	&mOut,
274	const float	fX,
275	const float	fY,
276	const float	fZ);
277/*!***************************************************************************
278 @fn        		PVRTMatrixTranslationX
279 @param[out]			mOut	Translation matrix
280 @param[in]				fX		X component of the translation
281 @param[in]				fY		Y component of the translation
282 @param[in]				fZ		Z component of the translation
283 @brief      		Build a transaltion matrix mOut using fX, fY and fZ.
284*****************************************************************************/
285void PVRTMatrixTranslationX(
286	PVRTMATRIXx	&mOut,
287	const int	fX,
288	const int	fY,
289	const int	fZ);
290
291/*!***************************************************************************
292 @fn           		PVRTMatrixScalingF
293 @param[out]			mOut	Scale matrix
294 @param[in]				fX		X component of the scaling
295 @param[in]				fY		Y component of the scaling
296 @param[in]				fZ		Z component of the scaling
297 @brief      		Build a scale matrix mOut using fX, fY and fZ.
298*****************************************************************************/
299void PVRTMatrixScalingF(
300	PVRTMATRIXf	&mOut,
301	const float fX,
302	const float fY,
303	const float fZ);
304
305/*!***************************************************************************
306 @fn           		PVRTMatrixScalingX
307 @param[out]			mOut	Scale matrix
308 @param[in]				fX		X component of the scaling
309 @param[in]				fY		Y component of the scaling
310 @param[in]				fZ		Z component of the scaling
311 @brief      		Build a scale matrix mOut using fX, fY and fZ.
312*****************************************************************************/
313void PVRTMatrixScalingX(
314	PVRTMATRIXx	&mOut,
315	const int	fX,
316	const int	fY,
317	const int	fZ);
318
319/*!***************************************************************************
320 @fn           		PVRTMatrixRotationXF
321 @param[out]			mOut	Rotation matrix
322 @param[in]				fAngle	Angle of the rotation
323 @brief      		Create an X rotation matrix mOut.
324*****************************************************************************/
325void PVRTMatrixRotationXF(
326	PVRTMATRIXf	&mOut,
327	const float fAngle);
328
329/*!***************************************************************************
330 @fn           		PVRTMatrixRotationXX
331 @param[out]			mOut	Rotation matrix
332 @param[in]				fAngle	Angle of the rotation
333 @brief      		Create an X rotation matrix mOut.
334*****************************************************************************/
335void PVRTMatrixRotationXX(
336	PVRTMATRIXx	&mOut,
337	const int	fAngle);
338
339/*!***************************************************************************
340 @fn           		PVRTMatrixRotationYF
341 @param[out]			mOut	Rotation matrix
342 @param[in]				fAngle	Angle of the rotation
343 @brief      		Create an Y rotation matrix mOut.
344*****************************************************************************/
345void PVRTMatrixRotationYF(
346	PVRTMATRIXf	&mOut,
347	const float fAngle);
348
349/*!***************************************************************************
350 @fn           		PVRTMatrixRotationYX
351 @param[out]			mOut	Rotation matrix
352 @param[in]				fAngle	Angle of the rotation
353 @brief      		Create an Y rotation matrix mOut.
354*****************************************************************************/
355void PVRTMatrixRotationYX(
356	PVRTMATRIXx	&mOut,
357	const int	fAngle);
358
359/*!***************************************************************************
360 @fn           		PVRTMatrixRotationZF
361 @param[out]			mOut	Rotation matrix
362 @param[in]				fAngle	Angle of the rotation
363 @brief      		Create an Z rotation matrix mOut.
364*****************************************************************************/
365void PVRTMatrixRotationZF(
366	PVRTMATRIXf	&mOut,
367	const float fAngle);
368/*!***************************************************************************
369 @fn           		PVRTMatrixRotationZX
370 @param[out]			mOut	Rotation matrix
371 @param[in]				fAngle	Angle of the rotation
372 @brief      		Create an Z rotation matrix mOut.
373*****************************************************************************/
374void PVRTMatrixRotationZX(
375	PVRTMATRIXx	&mOut,
376	const int	fAngle);
377
378/*!***************************************************************************
379 @fn           		PVRTMatrixTransposeF
380 @param[out]			mOut	Transposed matrix
381 @param[in]				mIn		Original matrix
382 @brief      		Compute the transpose matrix of mIn.
383*****************************************************************************/
384void PVRTMatrixTransposeF(
385	PVRTMATRIXf			&mOut,
386	const PVRTMATRIXf	&mIn);
387/*!***************************************************************************
388 @fn           		PVRTMatrixTransposeX
389 @param[out]			mOut	Transposed matrix
390 @param[in]				mIn		Original matrix
391 @brief      		Compute the transpose matrix of mIn.
392*****************************************************************************/
393void PVRTMatrixTransposeX(
394	PVRTMATRIXx			&mOut,
395	const PVRTMATRIXx	&mIn);
396
397/*!***************************************************************************
398 @fn      			PVRTMatrixInverseF
399 @param[out]			mOut	Inversed matrix
400 @param[in]				mIn		Original matrix
401 @brief      		Compute the inverse matrix of mIn.
402					The matrix must be of the form :
403					A 0
404					C 1
405					Where A is a 3x3 matrix and C is a 1x3 matrix.
406*****************************************************************************/
407void PVRTMatrixInverseF(
408	PVRTMATRIXf			&mOut,
409	const PVRTMATRIXf	&mIn);
410/*!***************************************************************************
411 @fn      			PVRTMatrixInverseX
412 @param[out]			mOut	Inversed matrix
413 @param[in]				mIn		Original matrix
414 @brief      		Compute the inverse matrix of mIn.
415					The matrix must be of the form :
416					A 0
417					C 1
418					Where A is a 3x3 matrix and C is a 1x3 matrix.
419*****************************************************************************/
420void PVRTMatrixInverseX(
421	PVRTMATRIXx			&mOut,
422	const PVRTMATRIXx	&mIn);
423
424/*!***************************************************************************
425 @fn      			PVRTMatrixInverseExF
426 @param[out]			mOut	Inversed matrix
427 @param[in]				mIn		Original matrix
428 @brief      		Compute the inverse matrix of mIn.
429					Uses a linear equation solver and the knowledge that M.M^-1=I.
430					Use this fn to calculate the inverse of matrices that
431					PVRTMatrixInverse() cannot.
432*****************************************************************************/
433void PVRTMatrixInverseExF(
434	PVRTMATRIXf			&mOut,
435	const PVRTMATRIXf	&mIn);
436/*!***************************************************************************
437 @fn      			PVRTMatrixInverseExX
438 @param[out]			mOut	Inversed matrix
439 @param[in]				mIn		Original matrix
440 @brief      		Compute the inverse matrix of mIn.
441					Uses a linear equation solver and the knowledge that M.M^-1=I.
442					Use this fn to calculate the inverse of matrices that
443					PVRTMatrixInverse() cannot.
444*****************************************************************************/
445void PVRTMatrixInverseExX(
446	PVRTMATRIXx			&mOut,
447	const PVRTMATRIXx	&mIn);
448
449/*!***************************************************************************
450 @fn      			PVRTMatrixLookAtLHF
451 @param[out]			mOut	Look-at view matrix
452 @param[in]				vEye	Position of the camera
453 @param[in]				vAt		Point the camera is looking at
454 @param[in]				vUp		Up direction for the camera
455 @brief      		Create a look-at view matrix.
456*****************************************************************************/
457void PVRTMatrixLookAtLHF(
458	PVRTMATRIXf			&mOut,
459	const PVRTVECTOR3f	&vEye,
460	const PVRTVECTOR3f	&vAt,
461	const PVRTVECTOR3f	&vUp);
462/*!***************************************************************************
463 @fn      			PVRTMatrixLookAtLHX
464 @param[out]			mOut	Look-at view matrix
465 @param[in]				vEye	Position of the camera
466 @param[in]				vAt		Point the camera is looking at
467 @param[in]				vUp		Up direction for the camera
468 @brief      		Create a look-at view matrix.
469*****************************************************************************/
470void PVRTMatrixLookAtLHX(
471	PVRTMATRIXx			&mOut,
472	const PVRTVECTOR3x	&vEye,
473	const PVRTVECTOR3x	&vAt,
474	const PVRTVECTOR3x	&vUp);
475
476/*!***************************************************************************
477 @fn      			PVRTMatrixLookAtRHF
478 @param[out]			mOut	Look-at view matrix
479 @param[in]				vEye	Position of the camera
480 @param[in]				vAt		Point the camera is looking at
481 @param[in]				vUp		Up direction for the camera
482 @brief      		Create a look-at view matrix.
483*****************************************************************************/
484void PVRTMatrixLookAtRHF(
485	PVRTMATRIXf			&mOut,
486	const PVRTVECTOR3f	&vEye,
487	const PVRTVECTOR3f	&vAt,
488	const PVRTVECTOR3f	&vUp);
489/*!***************************************************************************
490 @fn      			PVRTMatrixLookAtRHX
491 @param[out]			mOut	Look-at view matrix
492 @param[in]				vEye	Position of the camera
493 @param[in]				vAt		Point the camera is looking at
494 @param[in]				vUp		Up direction for the camera
495 @brief      		Create a look-at view matrix.
496*****************************************************************************/
497void PVRTMatrixLookAtRHX(
498	PVRTMATRIXx			&mOut,
499	const PVRTVECTOR3x	&vEye,
500	const PVRTVECTOR3x	&vAt,
501	const PVRTVECTOR3x	&vUp);
502
503/*!***************************************************************************
504 @fn      		PVRTMatrixPerspectiveFovLHF
505 @param[out]		mOut		Perspective matrix
506 @param[in]			fFOVy		Field of view
507 @param[in]			fAspect		Aspect ratio
508 @param[in]			fNear		Near clipping distance
509 @param[in]			fFar		Far clipping distance
510 @param[in]			bRotate		Should we rotate it ? (for upright screens)
511 @brief      	Create a perspective matrix.
512*****************************************************************************/
513void PVRTMatrixPerspectiveFovLHF(
514	PVRTMATRIXf	&mOut,
515	const float	fFOVy,
516	const float	fAspect,
517	const float	fNear,
518	const float	fFar,
519	const bool  bRotate = false);
520/*!***************************************************************************
521 @fn      		PVRTMatrixPerspectiveFovLHX
522 @param[out]		mOut		Perspective matrix
523 @param[in]			fFOVy		Field of view
524 @param[in]			fAspect		Aspect ratio
525 @param[in]			fNear		Near clipping distance
526 @param[in]			fFar		Far clipping distance
527 @param[in]			bRotate		Should we rotate it ? (for upright screens)
528 @brief      	Create a perspective matrix.
529*****************************************************************************/
530void PVRTMatrixPerspectiveFovLHX(
531	PVRTMATRIXx	&mOut,
532	const int	fFOVy,
533	const int	fAspect,
534	const int	fNear,
535	const int	fFar,
536	const bool  bRotate = false);
537
538/*!***************************************************************************
539 @fn      		PVRTMatrixPerspectiveFovRHF
540 @param[out]		mOut		Perspective matrix
541 @param[in]			fFOVy		Field of view
542 @param[in]			fAspect		Aspect ratio
543 @param[in]			fNear		Near clipping distance
544 @param[in]			fFar		Far clipping distance
545 @param[in]			bRotate		Should we rotate it ? (for upright screens)
546 @brief      	Create a perspective matrix.
547*****************************************************************************/
548void PVRTMatrixPerspectiveFovRHF(
549	PVRTMATRIXf	&mOut,
550	const float	fFOVy,
551	const float	fAspect,
552	const float	fNear,
553	const float	fFar,
554	const bool  bRotate = false);
555/*!***************************************************************************
556 @fn      		PVRTMatrixPerspectiveFovRHX
557 @param[out]		mOut		Perspective matrix
558 @param[in]			fFOVy		Field of view
559 @param[in]			fAspect		Aspect ratio
560 @param[in]			fNear		Near clipping distance
561 @param[in]			fFar		Far clipping distance
562 @param[in]			bRotate		Should we rotate it ? (for upright screens)
563 @brief      	Create a perspective matrix.
564*****************************************************************************/
565void PVRTMatrixPerspectiveFovRHX(
566	PVRTMATRIXx	&mOut,
567	const int	fFOVy,
568	const int	fAspect,
569	const int	fNear,
570	const int	fFar,
571	const bool  bRotate = false);
572
573/*!***************************************************************************
574 @fn      		PVRTMatrixOrthoLHF
575 @param[out]		mOut		Orthographic matrix
576 @param[in]			w			Width of the screen
577 @param[in]			h			Height of the screen
578 @param[in]			zn			Near clipping distance
579 @param[in]			zf			Far clipping distance
580 @param[in]			bRotate		Should we rotate it ? (for upright screens)
581 @brief      	Create an orthographic matrix.
582*****************************************************************************/
583void PVRTMatrixOrthoLHF(
584	PVRTMATRIXf	&mOut,
585	const float w,
586	const float h,
587	const float zn,
588	const float zf,
589	const bool  bRotate = false);
590/*!***************************************************************************
591 @fn      		PVRTMatrixOrthoLHX
592 @param[out]		mOut		Orthographic matrix
593 @param[in]			w			Width of the screen
594 @param[in]			h			Height of the screen
595 @param[in]			zn			Near clipping distance
596 @param[in]			zf			Far clipping distance
597 @param[in]			bRotate		Should we rotate it ? (for upright screens)
598 @brief      	Create an orthographic matrix.
599*****************************************************************************/
600void PVRTMatrixOrthoLHX(
601	PVRTMATRIXx	&mOut,
602	const int	w,
603	const int	h,
604	const int	zn,
605	const int	zf,
606	const bool  bRotate = false);
607
608/*!***************************************************************************
609 @fn      		PVRTMatrixOrthoRHF
610 @param[out]		mOut		Orthographic matrix
611 @param[in]			w			Width of the screen
612 @param[in]			h			Height of the screen
613 @param[in]			zn			Near clipping distance
614 @param[in]			zf			Far clipping distance
615 @param[in]			bRotate		Should we rotate it ? (for upright screens)
616 @brief      	Create an orthographic matrix.
617*****************************************************************************/
618void PVRTMatrixOrthoRHF(
619	PVRTMATRIXf	&mOut,
620	const float w,
621	const float h,
622	const float zn,
623	const float zf,
624	const bool  bRotate = false);
625/*!***************************************************************************
626 @fn      		PVRTMatrixOrthoRHX
627 @param[out]		mOut		Orthographic matrix
628 @param[in]			w			Width of the screen
629 @param[in]			h			Height of the screen
630 @param[in]			zn			Near clipping distance
631 @param[in]			zf			Far clipping distance
632 @param[in]			bRotate		Should we rotate it ? (for upright screens)
633 @brief      	Create an orthographic matrix.
634*****************************************************************************/
635void PVRTMatrixOrthoRHX(
636	PVRTMATRIXx	&mOut,
637	const int	w,
638	const int	h,
639	const int	zn,
640	const int	zf,
641	const bool  bRotate = false);
642
643/*!***************************************************************************
644 @fn      			PVRTMatrixVec3LerpF
645 @param[out]			vOut	Result of the interpolation
646 @param[in]				v1		First vector to interpolate from
647 @param[in]				v2		Second vector to interpolate form
648 @param[in]				s		Coefficient of interpolation
649 @brief      		This function performs the linear interpolation based on
650					the following formula: V1 + s(V2-V1).
651*****************************************************************************/
652void PVRTMatrixVec3LerpF(
653	PVRTVECTOR3f		&vOut,
654	const PVRTVECTOR3f	&v1,
655	const PVRTVECTOR3f	&v2,
656	const float			s);
657/*!***************************************************************************
658 @fn      			PVRTMatrixVec3LerpX
659 @param[out]			vOut	Result of the interpolation
660 @param[in]				v1		First vector to interpolate from
661 @param[in]				v2		Second vector to interpolate form
662 @param[in]				s		Coefficient of interpolation
663 @brief      		This function performs the linear interpolation based on
664					the following formula: V1 + s(V2-V1).
665*****************************************************************************/
666void PVRTMatrixVec3LerpX(
667	PVRTVECTOR3x		&vOut,
668	const PVRTVECTOR3x	&v1,
669	const PVRTVECTOR3x	&v2,
670	const int			s);
671
672/*!***************************************************************************
673 @fn      			PVRTMatrixVec3DotProductF
674 @param[in]				v1		First vector
675 @param[in]				v2		Second vector
676 @return			Dot product of the two vectors.
677 @brief      		This function performs the dot product of the two
678					supplied vectors.
679*****************************************************************************/
680float PVRTMatrixVec3DotProductF(
681	const PVRTVECTOR3f	&v1,
682	const PVRTVECTOR3f	&v2);
683/*!***************************************************************************
684 @fn      			PVRTMatrixVec3DotProductX
685 @param[in]				v1		First vector
686 @param[in]				v2		Second vector
687 @return			Dot product of the two vectors.
688 @brief      		This function performs the dot product of the two
689					supplied vectors.
690					A single >> 16 shift could be applied to the final accumulated
691					result however this runs the risk of overflow between the
692					results of the intermediate additions.
693*****************************************************************************/
694int PVRTMatrixVec3DotProductX(
695	const PVRTVECTOR3x	&v1,
696	const PVRTVECTOR3x	&v2);
697
698/*!***************************************************************************
699 @fn      			PVRTMatrixVec3CrossProductF
700 @param[out]			vOut	Cross product of the two vectors
701 @param[in]				v1		First vector
702 @param[in]				v2		Second vector
703 @brief      		This function performs the cross product of the two
704					supplied vectors.
705*****************************************************************************/
706void PVRTMatrixVec3CrossProductF(
707	PVRTVECTOR3f		&vOut,
708	const PVRTVECTOR3f	&v1,
709	const PVRTVECTOR3f	&v2);
710/*!***************************************************************************
711 @fn      			PVRTMatrixVec3CrossProductX
712 @param[out]			vOut	Cross product of the two vectors
713 @param[in]				v1		First vector
714 @param[in]				v2		Second vector
715 @brief      		This function performs the cross product of the two
716					supplied vectors.
717*****************************************************************************/
718void PVRTMatrixVec3CrossProductX(
719	PVRTVECTOR3x		&vOut,
720	const PVRTVECTOR3x	&v1,
721	const PVRTVECTOR3x	&v2);
722
723/*!***************************************************************************
724 @fn      			PVRTMatrixVec3NormalizeF
725 @param[out]			vOut	Normalized vector
726 @param[in]				vIn		Vector to normalize
727 @brief      		Normalizes the supplied vector.
728*****************************************************************************/
729void PVRTMatrixVec3NormalizeF(
730	PVRTVECTOR3f		&vOut,
731	const PVRTVECTOR3f	&vIn);
732/*!***************************************************************************
733 @fn      			PVRTMatrixVec3NormalizeX
734 @param[out]			vOut	Normalized vector
735 @param[in]				vIn		Vector to normalize
736 @brief      		Normalizes the supplied vector.
737					The square root function is currently still performed
738					in floating-point.
739					Original vector is scaled down prior to be normalized in
740					order to avoid overflow issues.
741*****************************************************************************/
742void PVRTMatrixVec3NormalizeX(
743	PVRTVECTOR3x		&vOut,
744	const PVRTVECTOR3x	&vIn);
745/*!***************************************************************************
746 @fn      			PVRTMatrixVec3LengthF
747 @param[in]				vIn		Vector to get the length of
748 @return			The length of the vector
749  @brief      		Gets the length of the supplied vector.
750*****************************************************************************/
751float PVRTMatrixVec3LengthF(
752	const PVRTVECTOR3f	&vIn);
753/*!***************************************************************************
754 @fn      			PVRTMatrixVec3LengthX
755 @param[in]				vIn		Vector to get the length of
756 @return			The length of the vector
757 @brief      		Gets the length of the supplied vector
758*****************************************************************************/
759int PVRTMatrixVec3LengthX(
760	const PVRTVECTOR3x	&vIn);
761/*!***************************************************************************
762 @fn      			PVRTMatrixLinearEqSolveF
763 @param[in]				pSrc	2D array of floats. 4 Eq linear problem is 5x4
764							matrix, constants in first column
765 @param[in]				nCnt	Number of equations to solve
766 @param[out]			pRes	Result
767 @brief      		Solves 'nCnt' simultaneous equations of 'nCnt' variables.
768					pRes should be an array large enough to contain the
769					results: the values of the 'nCnt' variables.
770					This fn recursively uses Gaussian Elimination.
771*****************************************************************************/
772
773void PVRTMatrixLinearEqSolveF(
774	float		* const pRes,
775	float		** const pSrc,
776	const int	nCnt);
777/*!***************************************************************************
778 @fn      			PVRTMatrixLinearEqSolveX
779 @param[in]				pSrc	2D array of floats. 4 Eq linear problem is 5x4
780							matrix, constants in first column
781 @param[in]				nCnt	Number of equations to solve
782 @param[out]			pRes	Result
783 @brief      		Solves 'nCnt' simultaneous equations of 'nCnt' variables.
784					pRes should be an array large enough to contain the
785					results: the values of the 'nCnt' variables.
786					This fn recursively uses Gaussian Elimination.
787*****************************************************************************/
788void PVRTMatrixLinearEqSolveX(
789	int			* const pRes,
790	int			** const pSrc,
791	const int	nCnt);
792
793#endif
794
795/*****************************************************************************
796 End of file (PVRTMatrix.h)
797*****************************************************************************/
798
799