Quaternion.js 3.6 KB

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