glue.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. Copyright (c) 2015-2019 Bruce A Henderson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice, this
  7. list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  12. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  13. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  14. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  15. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  16. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  17. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  18. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  19. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  20. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. */
  22. #include "bx/math.h"
  23. extern "C" {
  24. void bmx_bx_mtxIdentity(float * result);
  25. void bmx_bx_mtxTranslate(float * result, float tx, float ty, float tz);
  26. void bmx_bx_mtxScale(float * result, float sx, float sy, float sz);
  27. void bmx_bx_mtxQuat(float * result, bx::Quaternion * quat);
  28. void bmx_bx_mtxQuatTranslation(float * result, bx::Quaternion * quat, bx::Vec3 * translation);
  29. void bmx_bx_mtxQuatTranslationHMD(float * result, bx::Quaternion * quat, bx::Vec3 * translation);
  30. void bmx_bx_mtxLookAt(float * result, float * eye, float * at, float * up);
  31. //void bmx_bx_mtxProjXYWH(float * result, float x, float y, float width, float height, float near, float far, int oglNdc);
  32. void bmx_bx_mtxProj(float * result, float ut, float dt, float lt, float rt, float near, float far, int oglNdc);
  33. void bmx_bx_mtxProjFovyAspet(float * result, float fovy, float aspect, float near, float far, int oglNdc);
  34. void bmx_bx_mtxOrtho(float * result, float left, float right, float bottom, float top, float near, float far, float offset, int oglNdc);
  35. void bmx_bx_mtxRotateX(float * result, float ax);
  36. void bmx_bx_mtxRotateY(float * result, float ay);
  37. void bmx_bx_mtxRotateZ(float * result, float az);
  38. void bmx_bx_mtxRotateXY(float * result, float ax, float ay);
  39. void bmx_bx_mtxRotateXYZ(float * result, float ax, float ay, float az);
  40. void bmx_bx_mtxRotateZYX(float * result, float ax, float ay, float az);
  41. void bmx_bx_mtxMul(float * result, float * a, float * b);
  42. void bmx_bx_mtxTranspose(float * result, float * a);
  43. }
  44. void bmx_bx_mtxIdentity(float * result) {
  45. bx::mtxIdentity(result);
  46. }
  47. void bmx_bx_mtxTranslate(float * result, float tx, float ty, float tz) {
  48. bx::mtxTranslate(result, tx, ty, tz);
  49. }
  50. void bmx_bx_mtxScale(float * result, float sx, float sy, float sz) {
  51. bx::mtxScale(result, sx, sy, sz);
  52. }
  53. void bmx_bx_mtxQuat(float * result, bx::Quaternion * quat) {
  54. bx::mtxQuat(result, *quat);
  55. }
  56. void bmx_bx_mtxQuatTranslation(float * result, bx::Quaternion * quat, bx::Vec3 * translation) {
  57. bx::mtxQuatTranslation(result, *quat, *translation);
  58. }
  59. void bmx_bx_mtxQuatTranslationHMD(float * result, bx::Quaternion * quat, bx::Vec3 * translation) {
  60. bx::mtxQuatTranslationHMD(result, *quat, *translation);
  61. }
  62. void bmx_bx_mtxLookAt(float * result, float * eye, float * at, float * up) {
  63. bx::Vec3 vEye;
  64. bx::Vec3 vAt;
  65. bx::Vec3 vUp;
  66. bx::mtxLookAt(result, vEye, vAt, vUp);
  67. eye[0] = vEye.x;
  68. eye[1] = vEye.y;
  69. eye[2] = vEye.z;
  70. at[0] = vAt.x;
  71. at[1] = vAt.y;
  72. at[2] = vAt.z;
  73. if (up) {
  74. up[0] = vUp.x;
  75. up[1] = vUp.y;
  76. up[2] = vUp.z;
  77. }
  78. }
  79. //void bmx_bx_mtxProjXYWH(float * result, float x, float y, float width, float height, float near, float far, int oglNdc) {
  80. // bx::mtxProjXYWH(result, x, y, width, height, near, far, static_cast<bool>(oglNdc));
  81. //}
  82. void bmx_bx_mtxProj(float * result, float ut, float dt, float lt, float rt, float near, float far, int oglNdc) {
  83. bx::mtxProj(result, ut, dt, lt, rt, near, far, static_cast<bool>(oglNdc));
  84. }
  85. void bmx_bx_mtxProjFovyAspet(float * result, float fovy, float aspect, float near, float far, int oglNdc) {
  86. bx::mtxProj(result, fovy, aspect, near, far, static_cast<bool>(oglNdc));
  87. }
  88. void bmx_bx_mtxOrtho(float * result, float left, float right, float bottom, float top, float near, float far, float offset, int oglNdc) {
  89. bx::mtxOrtho(result, left, right, bottom, top, near, far, offset, static_cast<bool>(oglNdc));
  90. }
  91. void bmx_bx_mtxRotateX(float * result, float ax) {
  92. bx::mtxRotateX(result, bx::toRad(ax));
  93. }
  94. void bmx_bx_mtxRotateY(float * result, float ay) {
  95. bx::mtxRotateY(result, bx::toRad(ay));
  96. }
  97. void bmx_bx_mtxRotateZ(float * result, float az) {
  98. bx::mtxRotateZ(result, bx::toRad(az));
  99. }
  100. void bmx_bx_mtxRotateXY(float * result, float ax, float ay) {
  101. bx::mtxRotateXY(result, bx::toRad(ax), bx::toRad(ay));
  102. }
  103. void bmx_bx_mtxRotateXYZ(float * result, float ax, float ay, float az) {
  104. bx::mtxRotateXYZ(result, bx::toRad(ax), bx::toRad(ay), bx::toRad(az));
  105. }
  106. void bmx_bx_mtxRotateZYX(float * result, float ax, float ay, float az) {
  107. bx::mtxRotateZYX(result, bx::toRad(ax), bx::toRad(ay), bx::toRad(az));
  108. }
  109. void bmx_bx_mtxMul(float * result, float * a, float * b) {
  110. bx::mtxMul(result, a, b);
  111. }
  112. void bmx_bx_mtxTranspose(float * result, float * a) {
  113. bx::mtxTranspose(result, a);
  114. }