summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-09 12:24:28 -0500
committersanine-a <sanine.not@pm.me>2023-05-09 12:24:28 -0500
commit02247e743b83669e2d799111fc10a4772de66dfc (patch)
treef6b8e29897897f1af5b03bc6f57693624292bd21 /main.lua
parent02389173aa65bb27379eb910a71a395e161c5b87 (diff)
add ecs.Accessor helper and node _child hierarchy
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua18
1 files changed, 10 insertions, 8 deletions
diff --git a/main.lua b/main.lua
index efee1a2..4984355 100644
--- a/main.lua
+++ b/main.lua
@@ -160,11 +160,13 @@ function setupEntities()
mesh = { filename="assets/capsule.obj", index=1 },
shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
},
+ script = { script = "capsuleMove" },
}
local pivotPivot = entities:createEntityWithComponents{
node = {
+ name = "p",
parent = capsule,
matrix = Mat4():identity():rotateX(-0.5*math.pi),
},
@@ -173,6 +175,7 @@ function setupEntities()
local capcamPivot = entities:createEntityWithComponents{
node = {
+ name = "pivot",
parent = pivotPivot,
matrix = Mat4():identity(),
},
@@ -181,7 +184,6 @@ function setupEntities()
yaw = 0,
},
onCursorPos = { script = "cameraCursorPos" },
- script = { script = "capsuleMove" },
}
package.loaded["cameraCursorPos"] = (function()
local prevx, prevy
@@ -191,7 +193,6 @@ function setupEntities()
end
local dx = data.xpos - prevx
local dy = data.ypos - prevy
- print(dx,dy)
prevx, prevy = data.xpos, data.ypos
local node = entities:getComponent(id, "node")
@@ -209,17 +210,18 @@ function setupEntities()
end)()
package.loaded["capsuleMove"] = function(entities, id, dt)
+ local self = ecs.Accessor(entities, id)
local pressed = function(key)
return glfw.GetKey(window.win, key) == glfw.PRESS
end
- local py = entities:getComponent(id, "pitchyaw")
- local yaw = math.rad(py.yaw)
+ local yaw = math.rad(
+ self.node._child.p
+ .node._child.pivot
+ .pitchyaw.yaw)
local forward = Vec3{-math.sin(yaw), 0, -math.cos(yaw)}
local left = Vec3{-math.cos(yaw), 0, math.sin(yaw)}
- print(forward, left)
-
local capsule = entities:getComponent(capsule, "physics")
local vel = Vec3{0,0,0}
@@ -239,9 +241,9 @@ function setupEntities()
vel = 10000 * vel:normalize()
- x, y, z = ode.BodyGetLinearVel(capsule._body)
+ x, y, z = ode.BodyGetLinearVel(self.physics._body)
if Vec3{x,y,z}:norm2() < 500 then
- ode.BodyAddForce(capsule._body, vel[1], vel[2], vel[3])
+ ode.BodyAddForce(self.physics._body, vel[1], vel[2], vel[3])
end
end