Scenegraph for LOVR

selfsame d83119949b initial commit 4 years ago
LICENSE 7e0133835c Initial commit 4 years ago
README.md d83119949b initial commit 4 years ago
xform.lua d83119949b initial commit 4 years ago

README.md

xform

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.

Quick start

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

rock

Usage

  • Xform:new(position, scale, rotation_quat) returns a new Xform
  • the scenegraph updates whenever you set 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

TODO

  • optional constructor args (position, scale, rotation)
  • values should be copied into persistant properties
  • allow user data
  • fns to add and remove children from parent
  • prevent DAG cycle in parent/child
  • correct mat4 calc (need to do parent.world * child.local??)
  • ensure children vector is loop/remove safe
  • parenting xform should preserve it's world space in the new parent local?
  • ensure that xform.position.x += 1 triggers an update?
  • stub out all transform fns from Unity
  • write test suite?