diff options
Diffstat (limited to 'honey')
-rw-r--r-- | honey/ecs-systems.lua | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/honey/ecs-systems.lua b/honey/ecs-systems.lua index b468228..1213763 100644 --- a/honey/ecs-systems.lua +++ b/honey/ecs-systems.lua @@ -38,39 +38,39 @@ end --===== transform cascading =====-- -transform = function(params) +node = function(params) return { db = params.db, priority = 2, update = function(self, dt) - local entities = self.db:queryComponent("transform") + local nodes = self.db:queryComponent("node") - -- prepare transforms - for id, transform in pairs(entities) do - transform._visited = false + -- prepare nodes + for id, node in pairs(nodes) do + node._visited = false end -- helper function - local function recursiveTransform(transform) - if transform._visited then - return transform._matrix + local function recursiveTransform(node) + if node._visited then + return node._matrix end - if not transform.parent then - transform._matrix = transform.matrix + if not node.parent then + node._matrix = node.matrix else - local parentTransform = self.db:getComponent(transform.parent, "transform") + local parentTransform = self.db:getComponent(node.parent, "node") local parentMatrix = recursiveTransform(parentTransform) - transform._matrix = parentMatrix * transform.matrix + node._matrix = parentMatrix * node.matrix end - transform._visited = true - return transform._matrix + node._visited = true + return node._matrix end - -- compute transforms - for id, transform in pairs(entities) do - recursiveTransform(transform) + -- compute nodes + for id, node in pairs(nodes) do + recursiveTransform(node) end end, } @@ -120,7 +120,7 @@ function renderCamera(params) update = function(self, dt) for id, camera in pairs(self.db:queryComponent("camera")) do local projection = camera.projection - local cameraTransform = self.db:getComponent(id, "transform") + local cameraTransform = self.db:getComponent(id, "node") local view = Mat4() if cameraTransform then honey.glm.mat4_inv(cameraTransform._matrix.data, view.data) @@ -131,9 +131,9 @@ function renderCamera(params) local entities = self.db:queryComponent("renderMesh") for entity, tbl in pairs(entities) do -- get model - local transform = self.db:getComponent(entity, "transform") + local node = self.db:getComponent(entity, "node") local model = - (transform and transform._matrix) or + (node and node._matrix) or Mat4():identity() -- get shader local shader = honey.shader.loadShader( @@ -237,7 +237,7 @@ physics = function(params) ) end ode.BodySetMass(body, mass) - local m = self.db:getComponent(id, "transform").matrix + local m = self.db:getComponent(id, "node").matrix ode.BodySetPosition( body, m[1][4], m[2][4], m[3][4] @@ -304,13 +304,13 @@ physics = function(params) -- remove all contact joints ode.JointGroupEmpty(self.contactGroup) - -- update entity transforms + -- update entity nodes for id, physics in pairs(query) do local x,y,z = ode.BodyGetPosition(physics._body) local d,a,b,c = ode.BodyGetQuaternion(physics._body) - local transform = self.db:getComponent(id, "transform") + local node = self.db:getComponent(id, "node") local q = Quaternion{a,b,c,d} - transform.matrix + node.matrix :identity() :translate(Vec3{x,y,z}) :mul(Quaternion{a,b,c,d}:toMat4()) @@ -336,9 +336,9 @@ local function createGeom(self, id, collision) elseif collision.class == "capsule" then geom = ode.CreateCapsule(self.space, collision.radius, collision.length) elseif collision.class == "plane" then - local transform = self.db:getComponent(id, "transform") - local m = transform.matrix - local normal = transform.matrix:mulv3(Vec3{0,1,0}):normalize() + local node = self.db:getComponent(id, "node") + local m = node.matrix + local normal = node.matrix:mulv3(Vec3{0,1,0}):normalize() local position = Vec3{m[1][4], m[2][4], m[3][4]} print(position) local d = normal:dot(position) |