Quaternion.lua 4.3 KB

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