selfsame d83119949b initial commit | 4 jaren geleden | |
---|---|---|
LICENSE | 4 jaren geleden | |
README.md | 4 jaren geleden | |
xform.lua | 4 jaren geleden |
Scenegraph for Lovr
an Xform
is a transform node with position
, scale
and rotation
properties that can be attached to other nodes into a heirarchy of objects. Changing the properties of a node updates any children, making it easy to work with groups of objects.
This creates 2 xforms, parents b
to a
, then rotates a
to demonstrate that the child's local transform is rendered in the parent's space.
require("xform")
a = Xform:new(vec3(0, 0, -3))
b = Xform:new(vec3(0, 1, 0))
b.parent = a
function lovr.draw()
a.rotation = quat(math.cos(lovr.timer.getTime()), 0, 0, 1)
lovr.graphics.cube('line', a.mat4)
lovr.graphics.cube('line', b.mat4)
end
Xform:new(position, scale, rotation_quat)
returns a new Xform
xform.position
, xform.scale
, or xform.rotation
.xform.parent = other_xform
to attach a node, to detach it set xform.parent = nil
xform.children
xform.mat4
is the xform's world transform, lovr.graphics
render functions can take a mat4 as an argument, or you can set lovr.graphics.transform = xform.mat4
xform.position.x += 1
triggers an update?