dd_matrix.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef DD_MATRIX_H
  2. #define DD_MATRIX_H
  3. /* a series of functions to manipulate a 4x4 matrix.
  4. * these functions allow transformation, scale and rotation (experimental)
  5. */
  6. struct dd_matrix {
  7. float cell[16];
  8. };
  9. void dd_matrix_create(float mat[16]);
  10. /* identity matrix
  11. * identity : makes an identity matrix
  12. * identityt : makes an identity matrix, except from translation
  13. (so it cancels rotation and scale)
  14. */
  15. void dd_matrix_identity (float mat[16]);
  16. void dd_matrix_identityt(float mat[16]);
  17. /* Translate - Seperated in add, set and multiply
  18. * add : adds fixed translation to the matrix
  19. * set : sets (overwrites) fixed translation to the matrix
  20. * multiply : creates a new matrix with given translation and
  21. multiplies the given matrix with it
  22. */
  23. void dd_matrix_translatea(float mat[16], float x, float y, float z);
  24. void dd_matrix_translates(float mat[16], float x, float y, float z);
  25. void dd_matrix_translatem(float mat[16], float x, float y, float z);
  26. /* Scale - Seperated in add and set */
  27. void dd_matrix_scalea(float mat[16], float x, float y, float z);
  28. void dd_matrix_scales(float mat[16], float x, float y, float z);
  29. void dd_matrix_scalem(float mat[16], float x, float y, float z);
  30. /* Rotate - experimental functions */
  31. void dd_matrix_rotate_x(float mat[16], float rad);
  32. void dd_matrix_rotate_y(float mat[16], float rad);
  33. void dd_matrix_rotate_z(float mat[16], float rad);
  34. void dd_matrix_rotatelocal_x(float mat[16], float rad);
  35. void dd_matrix_rotatelocal_y(float mat[16], float rad);
  36. void dd_matrix_rotatelocal_z(float mat[16], float rad);
  37. void dd_matrix_rotatem(float mat[16], float rad, float x, float y, float z);
  38. /* Matrix multiplication */
  39. void dd_matrix_mult(float mat1[16], float mat2[16]);
  40. void dd_matrix_copy(float mat1[16], float mat2[16]);
  41. void dd_matrix_copy_rs(float mat1[16], float mat2[16]);
  42. void dd_matrix_approach(float mat[16], float target[16], float counter);
  43. void dd_matrix_approach_rs(float mat[16], float target[16], float counter);
  44. /* Getters */
  45. float dd_matrix_x(float mat[16]);
  46. float dd_matrix_y(float mat[16]);
  47. float dd_matrix_z(float mat[16]);
  48. /* Print matrix - don't use this */
  49. void dd_matrix_print(float mat[16]);
  50. /*
  51. * manual implementation of the matrix stack
  52. */
  53. #define DD_MATRIX_STACK_LIMIT 10
  54. extern struct dd_matrix dd_cam[];
  55. extern int dd_cam_index;
  56. void dd_matrix_globalInit();
  57. void dd_matrix_push();
  58. void dd_matrix_pop ();
  59. struct dd_matrix *dd_matrix_globalGet();
  60. #define dd_pushMatrix() dd_matrix_push()
  61. #define dd_popMatrix() dd_matrix_pop()
  62. #define dd_translatef(x, y, z) dd_matrix_translatem((float*)dd_matrix_globalGet(), x, y, z)
  63. #define dd_scalef(x, y, z) dd_matrix_scalem((float*)dd_matrix_globalGet(), x, y, z)
  64. #define dd_rotatef(angle, x, y, z) dd_matrix_rotatem((float*)dd_matrix_globalGet(), angle, x, y, z)
  65. #define dd_multMatrixf(matrix) dd_matrix_mult((float*)dd_matrix_globalGet(), matrix);
  66. #endif