Quaternion.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. function Quaternion(w,x,y,z) {
  2. if(arguments[0] != "__skip_ptr__") {
  3. this.__ptr = Polycode.Quaternion(w,x,y,z)
  4. }
  5. Object.defineProperties(this, {
  6. 'x': { enumerable: true, configurable: true, get: Quaternion.prototype.__get_x, set: Quaternion.prototype.__set_x},
  7. 'y': { enumerable: true, configurable: true, get: Quaternion.prototype.__get_y, set: Quaternion.prototype.__set_y},
  8. 'z': { enumerable: true, configurable: true, get: Quaternion.prototype.__get_z, set: Quaternion.prototype.__set_z},
  9. 'w': { enumerable: true, configurable: true, get: Quaternion.prototype.__get_w, set: Quaternion.prototype.__set_w}
  10. })
  11. }
  12. Quaternion.prototype.__get_x = function() {
  13. return Polycode.Quaternion__get_x(this.__ptr)
  14. }
  15. Quaternion.prototype.__set_x = function(val) {
  16. Polycode.Quaternion__set_x(this.__ptr, val)
  17. }
  18. Quaternion.prototype.__get_y = function() {
  19. return Polycode.Quaternion__get_y(this.__ptr)
  20. }
  21. Quaternion.prototype.__set_y = function(val) {
  22. Polycode.Quaternion__set_y(this.__ptr, val)
  23. }
  24. Quaternion.prototype.__get_z = function() {
  25. return Polycode.Quaternion__get_z(this.__ptr)
  26. }
  27. Quaternion.prototype.__set_z = function(val) {
  28. Polycode.Quaternion__set_z(this.__ptr, val)
  29. }
  30. Quaternion.prototype.__get_w = function() {
  31. return Polycode.Quaternion__get_w(this.__ptr)
  32. }
  33. Quaternion.prototype.__set_w = function(val) {
  34. Polycode.Quaternion__set_w(this.__ptr, val)
  35. }
  36. Duktape.fin(Quaternion.prototype, function (x) {
  37. if (x === Quaternion.prototype) {
  38. return;
  39. }
  40. Polycode.Quaternion__delete(x.__ptr)
  41. })
  42. Quaternion.prototype.setFromMatrix = function(_mat) {
  43. Polycode.Quaternion_setFromMatrix(this.__ptr, _mat)
  44. }
  45. Quaternion.prototype.Slerp = function(fT,rkP,rkQ,shortestPath) {
  46. var retVal = new Quaternion()
  47. retVal.__ptr = Polycode.Quaternion_Slerp(fT, rkP, rkQ, shortestPath)
  48. return retVal
  49. }
  50. Quaternion.prototype.Dot = function(rkQ) {
  51. return Polycode.Quaternion_Dot(this.__ptr, rkQ)
  52. }
  53. Quaternion.prototype.Log = function() {
  54. var retVal = new Quaternion()
  55. retVal.__ptr = Polycode.Quaternion_Log(this.__ptr)
  56. return retVal
  57. }
  58. Quaternion.prototype.Exp = function() {
  59. var retVal = new Quaternion()
  60. retVal.__ptr = Polycode.Quaternion_Exp(this.__ptr)
  61. return retVal
  62. }
  63. Quaternion.prototype.Norm = function() {
  64. return Polycode.Quaternion_Norm(this.__ptr)
  65. }
  66. Quaternion.prototype.Normalize = function() {
  67. return Polycode.Quaternion_Normalize(this.__ptr)
  68. }
  69. Quaternion.prototype.lookAt = function(D,upVector) {
  70. Polycode.Quaternion_lookAt(this.__ptr, D, upVector)
  71. }
  72. Quaternion.prototype.createFromMatrix = function(matrix) {
  73. Polycode.Quaternion_createFromMatrix(this.__ptr, matrix)
  74. }
  75. Quaternion.prototype.Squad = function(fT,rkP,rkA,rkB,rkQ,shortestPath) {
  76. var retVal = new Quaternion()
  77. retVal.__ptr = Polycode.Quaternion_Squad(fT, rkP, rkA, rkB, rkQ, shortestPath)
  78. return retVal
  79. }
  80. Quaternion.prototype.Inverse = function() {
  81. var retVal = new Quaternion()
  82. retVal.__ptr = Polycode.Quaternion_Inverse(this.__ptr)
  83. return retVal
  84. }
  85. Quaternion.prototype.set = function(w,x,y,z) {
  86. Polycode.Quaternion_set(this.__ptr, w, x, y, z)
  87. }
  88. Quaternion.prototype.InvSqrt = function(x) {
  89. return Polycode.Quaternion_InvSqrt(this.__ptr, x)
  90. }
  91. Quaternion.prototype.fromAxes = function(az,ay,ax) {
  92. Polycode.Quaternion_fromAxes(this.__ptr, az, ay, ax)
  93. }
  94. Quaternion.prototype.fromAngleAxis = function(rfAngle,rkAxis) {
  95. Polycode.Quaternion_fromAngleAxis(this.__ptr, rfAngle, rkAxis)
  96. }
  97. Quaternion.prototype.toEulerAngles = function() {
  98. var retVal = new Vector3()
  99. retVal.__ptr = Polycode.Quaternion_toEulerAngles(this.__ptr)
  100. return retVal
  101. }
  102. Quaternion.prototype.toAngleAxis = function(rfAngle,rkAxis) {
  103. Polycode.Quaternion_toAngleAxis(this.__ptr, rfAngle, rkAxis)
  104. }
  105. Quaternion.prototype.createFromAxisAngle = function(x,y,z,degrees) {
  106. Polycode.Quaternion_createFromAxisAngle(this.__ptr, x, y, z, degrees)
  107. }
  108. Quaternion.prototype.createMatrix = function() {
  109. var retVal = new Matrix4()
  110. retVal.__ptr = Polycode.Quaternion_createMatrix(this.__ptr)
  111. return retVal
  112. }
  113. Quaternion.prototype.applyTo = function(v) {
  114. var retVal = new Vector3()
  115. retVal.__ptr = Polycode.Quaternion_applyTo(this.__ptr, v)
  116. return retVal
  117. }