summaryrefslogtreecommitdiff
path: root/examples/resources/lib/quaternion.lua
diff options
context:
space:
mode:
authorjussi2024-04-18 13:33:58 +0300
committerjussi2024-04-18 13:33:58 +0300
commitbdd660be01f3742befe15dff26929a77eeefe61d (patch)
tree93fd6de2ea48f9137e0c899db0c7f73d34f5ea87 /examples/resources/lib/quaternion.lua
parent70b40f67824b3d612235c382aa83821c054fa51e (diff)
downloadreilua-enhanced-bdd660be01f3742befe15dff26929a77eeefe61d.tar.gz
reilua-enhanced-bdd660be01f3742befe15dff26929a77eeefe61d.tar.bz2
reilua-enhanced-bdd660be01f3742befe15dff26929a77eeefe61d.zip
New creation methods for object libs.
Diffstat (limited to 'examples/resources/lib/quaternion.lua')
-rw-r--r--examples/resources/lib/quaternion.lua38
1 files changed, 36 insertions, 2 deletions
diff --git a/examples/resources/lib/quaternion.lua b/examples/resources/lib/quaternion.lua
index e95102e..47d6ee1 100644
--- a/examples/resources/lib/quaternion.lua
+++ b/examples/resources/lib/quaternion.lua
@@ -57,6 +57,17 @@ function Quaternion:newT( t )
return object
end
+function Quaternion:newQ( q )
+ local object = setmetatable( {}, metatable )
+
+ object.x = q.x
+ object.y = q.y
+ object.z = q.z
+ object.w = q.w
+
+ return object
+end
+
function Quaternion:set( x, y, z, w )
self.x = x or 0
self.y = y or 0
@@ -68,6 +79,13 @@ function Quaternion:setT( t )
self.x, self.y, self.z, self.w = table.unpack( t )
end
+function Quaternion:setQ( q )
+ self.x = q.x
+ self.y = q.y
+ self.z = q.z
+ self.w = q.w
+end
+
function Quaternion:arr()
return { self.x, self.y, self.z, self.w }
end
@@ -153,6 +171,8 @@ function Quaternion:transform( mat )
return Quaternion:newT( RL.QuaternionTransform( self, mat ) )
end
+-- Temp pre generated objects to avoid "slow" table generation.
+
local TEMP_COUNT = 100
local tempPool = {}
local curTemp = 1
@@ -161,7 +181,6 @@ for _ = 1, TEMP_COUNT do
table.insert( tempPool, Quaternion:new( 0, 0, 0, 1 ) )
end
--- Uses pre generated objects to avoid "slow" table generation.
function Quaternion:temp( x, y, z, w )
local object = tempPool[ curTemp ]
curTemp = curTemp + 1
@@ -178,7 +197,6 @@ function Quaternion:temp( x, y, z, w )
return object
end
--- Uses pre generated objects to avoid "slow" table generation.
function Quaternion:tempT( t )
local object = tempPool[ curTemp ]
curTemp = curTemp + 1
@@ -192,6 +210,22 @@ function Quaternion:tempT( t )
return object
end
+function Quaternion:tempQ( q )
+ local object = tempPool[ curTemp ]
+ curTemp = curTemp + 1
+
+ if TEMP_COUNT < curTemp then
+ curTemp = 1
+ end
+
+ object.x = q.x
+ object.y = q.y
+ object.z = q.z
+ object.w = q.w
+
+ return object
+end
+
function Quaternion:getTempId()
return curTemp
end