PVRTMatrix.h 30 KB

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