-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.lua
More file actions
35 lines (27 loc) · 854 Bytes
/
Copy pathtransform.lua
File metadata and controls
35 lines (27 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local Mat4 = require("mat4")
local Transform = {}
Transform.__index = Transform
function Transform.new(opts)
opts = opts or {}
local self = setmetatable({}, Transform)
self.x, self.y, self.z = opts.x or 0, opts.y or 0, opts.z or 0
self.rotX, self.rotY = opts.rotX or 0, opts.rotY or 0 -- radyan
self.scale = opts.scale or 1.0
return self
end
function Transform:getMatrix()
local rotation = Mat4.rotateXY(self.rotX, self.rotY)
local translation = Mat4.translate(self.x, self.y, self.z)
if self.scale ~= 1.0 then
local s = self.scale
local scaleM = {
s, 0, 0, 0,
0, s, 0, 0,
0, 0, s, 0,
0, 0, 0, 1,
}
return Mat4.mul(translation, Mat4.mul(rotation, scaleM))
end
return Mat4.mul(translation, rotation)
end
return Transform