Mat4Binds.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #include "ScriptSystem.h"
  2. #include "OS.h"
  3. namespace crown
  4. {
  5. extern "C"
  6. {
  7. Mat4* mat4(float r1c1, float r2c1, float r3c1, float r1c2, float r2c2, float r3c2, float r1c3, float r2c3, float r3c3);
  8. Mat4* mat4_add(Mat4* self, Mat4* m);
  9. Mat4* mat4_subtract(Mat4* self, Mat4* m);
  10. Mat4* mat4_multiply(Mat4* self, Mat4* m);
  11. Mat4* mat4_multiply_by_scalar(Mat4* self, float k);
  12. Mat4* mat4_divide_by_scalar(Mat4* self, float k);
  13. void mat4_build_rotation_x(Mat4* self, float radians);
  14. void mat4_build_rotation_y(Mat4* self, float radians);
  15. void mat4_build_rotation_z(Mat4* self, float radians);
  16. void mat4_build_rotation(Mat4* self, const Vec3* n, float radians);
  17. void mat4_build_projection_perspective_rh(Mat4* self, float fovy, float aspect, float near, float far);
  18. void mat4_build_projection_perspective_lh(Mat4* self, float fovy, float aspect, float near, float far);
  19. void mat4_build_projection_ortho_rh(Mat4* self, float width, float height, float near, float far);
  20. void mat4_build_projection_ortho_lh(Mat4* self, float width, float height, float near, float far);
  21. void mat4_build_projection_ortho_2d_rh(Mat4* self, float width, float height, float near, float far);
  22. void mat4_build_look_at_rh(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* up);
  23. void mat4_build_look_at_lh(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* up);
  24. void mat4_build_viewpoint_billboard(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* up);
  25. void mat4_build_axis_billboard(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* axis);
  26. Mat4* mat4_transpose(Mat4* self);
  27. float mat4_determinant(Mat4* self);
  28. Mat4* mat4_invert(Mat4* self);
  29. void mat4_load_identity(Mat4* self);
  30. Vec3* mat4_get_translation(Mat4* self);
  31. void mat4_set_translation(Mat4* self, const Vec3* trans);
  32. Vec3* mat4_get_scale(Mat4* self);
  33. void mat4_set_scale(Mat4* self, const Vec3* scale);
  34. void mat4_print(Mat4* self);
  35. }
  36. Mat4* mat4(float r1c1, float r2c1, float r3c1, float r1c2, float r2c2, float r3c2, float r1c3, float r2c3, float r3c3)
  37. {
  38. return scripter()->next_mat4(r1c1, r2c1, r3c1, r1c2, r2c2, r3c2, r1c3, r2c3, r3c3);
  39. }
  40. Mat4* mat4_add(Mat4* self, Mat4* m)
  41. {
  42. *self += *m;
  43. return self;
  44. }
  45. Mat4* mat4_subtract(Mat4* self, Mat4* m)
  46. {
  47. *self -= *m;
  48. return self;
  49. }
  50. Mat4* mat4_multiply(Mat4* self, Mat4* m)
  51. {
  52. *self *= *m;
  53. return self;
  54. }
  55. Mat4* mat4_multiply_by_scalar(Mat4* self, float k)
  56. {
  57. *self *= k;
  58. return self;
  59. }
  60. Mat4* mat4_divide_by_scalar(Mat4* self, float k)
  61. {
  62. *self /= k;
  63. return self;
  64. }
  65. void mat4_build_rotation_x(Mat4* self, float radians)
  66. {
  67. self->build_rotation_x(radians);
  68. }
  69. void mat4_build_rotation_y(Mat4* self, float radians)
  70. {
  71. self->build_rotation_y(radians);
  72. }
  73. void mat4_build_rotation_z(Mat4* self, float radians)
  74. {
  75. self->build_rotation_z(radians);
  76. }
  77. void mat4_build_rotation(Mat4* self, const Vec3* n, float radians)
  78. {
  79. self->build_rotation(*n, radians);
  80. }
  81. void mat4_build_projection_perspective_rh(Mat4* self, float fovy, float aspect, float near, float far)
  82. {
  83. self->build_projection_perspective_rh(fovy, aspect, near, far);
  84. }
  85. void mat4_build_projection_perspective_lh(Mat4* self, float fovy, float aspect, float near, float far)
  86. {
  87. self->build_projection_perspective_lh(fovy, aspect, near, far);
  88. }
  89. void mat4_build_projection_ortho_rh(Mat4* self, float width, float height, float near, float far)
  90. {
  91. self->build_projection_ortho_rh(width, height, near, far);
  92. }
  93. void mat4_build_projection_ortho_lh(Mat4* self, float width, float height, float near, float far)
  94. {
  95. self->build_projection_ortho_lh(width, height, near, far);
  96. }
  97. void mat4_build_projection_ortho_2d_rh(Mat4* self, float width, float height, float near, float far)
  98. {
  99. self->build_projection_ortho_2d_rh(width, height, near, far);
  100. }
  101. void mat4_build_look_at_rh(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* up)
  102. {
  103. self->build_look_at_rh(*pos, *target, *up);
  104. }
  105. void mat4_build_look_at_lh(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* up)
  106. {
  107. self->build_look_at_lh(*pos, *target, *up);
  108. }
  109. void mat4_build_viewpoint_billboard(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* up)
  110. {
  111. self->build_viewpoint_billboard(*pos, *target, *up);
  112. }
  113. void mat4_build_axis_billboard(Mat4* self, const Vec3* pos, const Vec3* target, const Vec3* axis)
  114. {
  115. self->build_axis_billboard(*pos, *target, *axis);
  116. }
  117. Mat4* mat4_transpose(Mat4* self)
  118. {
  119. self->transpose();
  120. return self;
  121. }
  122. float mat4_determinant(Mat4* self)
  123. {
  124. return self->get_determinant();
  125. }
  126. Mat4* mat4_invert(Mat4* self)
  127. {
  128. self->invert();
  129. return self;
  130. }
  131. void mat4_load_identity(Mat4* self)
  132. {
  133. self->load_identity();
  134. }
  135. Vec3* mat4_get_translation(Mat4* self)
  136. {
  137. return new Vec3(self->get_translation());
  138. }
  139. void mat4_set_translation(Mat4* self, const Vec3* trans)
  140. {
  141. self->set_translation(*trans);
  142. }
  143. Vec3* mat4_get_scale(Mat4* self)
  144. {
  145. return new Vec3(self->get_scale());
  146. }
  147. void mat4_set_scale(Mat4* self, const Vec3* scale)
  148. {
  149. self->set_scale(*scale);
  150. }
  151. void mat4_print(Mat4* self)
  152. {
  153. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self->m[0], self->m[1], self->m[2], self->m[3]);
  154. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self->m[4], self->m[5], self->m[6], self->m[7]);
  155. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self->m[8], self->m[9], self->m[10], self->m[11]);
  156. os::printf("|%.1f|%.1f|%.1f|%.1f|\n", self->m[12], self->m[13], self->m[14], self->m[15]);
  157. }
  158. } //namespace crown