Quaternion.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. class "Quaternion"
  2. function Quaternion:__index__(name)
  3. if name == "x" then
  4. return Polycore.Quaternion_get_x(self.__ptr)
  5. elseif name == "y" then
  6. return Polycore.Quaternion_get_y(self.__ptr)
  7. elseif name == "z" then
  8. return Polycore.Quaternion_get_z(self.__ptr)
  9. elseif name == "w" then
  10. return Polycore.Quaternion_get_w(self.__ptr)
  11. end
  12. end
  13. function Quaternion:__set_callback(name,value)
  14. if name == "x" then
  15. Polycore.Quaternion_set_x(self.__ptr, value)
  16. return true
  17. elseif name == "y" then
  18. Polycore.Quaternion_set_y(self.__ptr, value)
  19. return true
  20. elseif name == "z" then
  21. Polycore.Quaternion_set_z(self.__ptr, value)
  22. return true
  23. elseif name == "w" then
  24. Polycore.Quaternion_set_w(self.__ptr, value)
  25. return true
  26. end
  27. return false
  28. end
  29. function Quaternion:Quaternion(...)
  30. for k,v in pairs(arg) do
  31. if type(v) == "table" then
  32. if v.__ptr ~= nil then
  33. arg[k] = v.__ptr
  34. end
  35. end
  36. end
  37. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  38. self.__ptr = Polycore.Quaternion(unpack(arg))
  39. end
  40. end
  41. function Quaternion:setFromMatrix(kRot)
  42. local retVal = Polycore.Quaternion_setFromMatrix(self.__ptr, kRot.__ptr)
  43. end
  44. function Quaternion:Slerp(fT, rkP, rkQ, shortestPath)
  45. local retVal = Polycore.Quaternion_Slerp(fT, rkP.__ptr, rkQ.__ptr, shortestPath)
  46. if Polycore.__ptr_lookup[retVal] ~= nil then
  47. return Polycore.__ptr_lookup[retVal]
  48. else
  49. Polycore.__ptr_lookup[retVal] = Quaternion("__skip_ptr__")
  50. Polycore.__ptr_lookup[retVal].__ptr = retVal
  51. return Polycore.__ptr_lookup[retVal]
  52. end
  53. end
  54. function Quaternion:Dot(rkQ)
  55. local retVal = Polycore.Quaternion_Dot(self.__ptr, rkQ.__ptr)
  56. return retVal
  57. end
  58. function Quaternion:Log()
  59. local retVal = Polycore.Quaternion_Log(self.__ptr)
  60. if Polycore.__ptr_lookup[retVal] ~= nil then
  61. return Polycore.__ptr_lookup[retVal]
  62. else
  63. Polycore.__ptr_lookup[retVal] = Quaternion("__skip_ptr__")
  64. Polycore.__ptr_lookup[retVal].__ptr = retVal
  65. return Polycore.__ptr_lookup[retVal]
  66. end
  67. end
  68. function Quaternion:Exp()
  69. local retVal = Polycore.Quaternion_Exp(self.__ptr)
  70. if Polycore.__ptr_lookup[retVal] ~= nil then
  71. return Polycore.__ptr_lookup[retVal]
  72. else
  73. Polycore.__ptr_lookup[retVal] = Quaternion("__skip_ptr__")
  74. Polycore.__ptr_lookup[retVal].__ptr = retVal
  75. return Polycore.__ptr_lookup[retVal]
  76. end
  77. end
  78. function Quaternion:Norm()
  79. local retVal = Polycore.Quaternion_Norm(self.__ptr)
  80. return retVal
  81. end
  82. function Quaternion:normalise()
  83. local retVal = Polycore.Quaternion_normalise(self.__ptr)
  84. return retVal
  85. end
  86. function Quaternion:lookAt(D, upVector)
  87. local retVal = Polycore.Quaternion_lookAt(self.__ptr, D.__ptr, upVector.__ptr)
  88. end
  89. function Quaternion:createFromMatrix(matrix)
  90. local retVal = Polycore.Quaternion_createFromMatrix(self.__ptr, matrix.__ptr)
  91. end
  92. function Quaternion:Squad(fT, rkP, rkA, rkB, rkQ, shortestPath)
  93. local retVal = Polycore.Quaternion_Squad(fT, rkP.__ptr, rkA.__ptr, rkB.__ptr, rkQ.__ptr, shortestPath)
  94. if Polycore.__ptr_lookup[retVal] ~= nil then
  95. return Polycore.__ptr_lookup[retVal]
  96. else
  97. Polycore.__ptr_lookup[retVal] = Quaternion("__skip_ptr__")
  98. Polycore.__ptr_lookup[retVal].__ptr = retVal
  99. return Polycore.__ptr_lookup[retVal]
  100. end
  101. end
  102. function Quaternion:Inverse()
  103. local retVal = Polycore.Quaternion_Inverse(self.__ptr)
  104. if Polycore.__ptr_lookup[retVal] ~= nil then
  105. return Polycore.__ptr_lookup[retVal]
  106. else
  107. Polycore.__ptr_lookup[retVal] = Quaternion("__skip_ptr__")
  108. Polycore.__ptr_lookup[retVal].__ptr = retVal
  109. return Polycore.__ptr_lookup[retVal]
  110. end
  111. end
  112. function Quaternion:set(w, x, y, z)
  113. local retVal = Polycore.Quaternion_set(self.__ptr, w, x, y, z)
  114. end
  115. function Quaternion:inverse()
  116. local retVal = Polycore.Quaternion_inverse(self.__ptr)
  117. if Polycore.__ptr_lookup[retVal] ~= nil then
  118. return Polycore.__ptr_lookup[retVal]
  119. else
  120. Polycore.__ptr_lookup[retVal] = Quaternion("__skip_ptr__")
  121. Polycore.__ptr_lookup[retVal].__ptr = retVal
  122. return Polycore.__ptr_lookup[retVal]
  123. end
  124. end
  125. function Quaternion:InvSqrt(x)
  126. local retVal = Polycore.Quaternion_InvSqrt(self.__ptr, x)
  127. return retVal
  128. end
  129. function Quaternion:fromAxes(az, ay, ax)
  130. local retVal = Polycore.Quaternion_fromAxes(self.__ptr, az, ay, ax)
  131. end
  132. function Quaternion:FromAngleAxis(rfAngle, rkAxis)
  133. local retVal = Polycore.Quaternion_FromAngleAxis(self.__ptr, rfAngle.__ptr, rkAxis.__ptr)
  134. end
  135. function Quaternion:ToAngleAxis(rfAngle, rkAxis)
  136. local retVal = Polycore.Quaternion_ToAngleAxis(self.__ptr, rfAngle.__ptr, rkAxis.__ptr)
  137. end
  138. function Quaternion:createFromAxisAngle(x, y, z, degrees)
  139. local retVal = Polycore.Quaternion_createFromAxisAngle(self.__ptr, x, y, z, degrees)
  140. end
  141. function Quaternion:createMatrix()
  142. local retVal = Polycore.Quaternion_createMatrix(self.__ptr)
  143. if Polycore.__ptr_lookup[retVal] ~= nil then
  144. return Polycore.__ptr_lookup[retVal]
  145. else
  146. Polycore.__ptr_lookup[retVal] = Matrix4("__skip_ptr__")
  147. Polycore.__ptr_lookup[retVal].__ptr = retVal
  148. return Polycore.__ptr_lookup[retVal]
  149. end
  150. end