diff options
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 56 |
1 files changed, 55 insertions, 1 deletions
@@ -74,6 +74,18 @@ function setupEntities() class = "plane", }, }) + + local planeMesh = entities:createEntityWithComponents{ + transform = { + parent = plane, + matrix = Mat4():identity():rotateX(0.5*math.pi):scale(Vec3{20,20,20}), + }, + renderMesh = { + textures = { ourTexture={ filename="assets/green+grass-1024x1024.jpg" } }, + shader = { vertex="vertex.glsl", fragment="fragment.glsl" }, + mesh = { filename="builtin.quad", index=1 }, + }, + } @@ -170,12 +182,17 @@ function setupEntities() yaw = 0, }, onCursorPos = { script = "cameraCursorPos" }, + script = { script = "capsuleMove" }, } package.loaded["cameraCursorPos"] = (function() - local prevx, prevy = 0, 0 + local prevx, prevy return function(entities, id, data) + if not prevx then + prevx, prevy = data.xpos, data.ypos + end local dx = data.xpos - prevx local dy = data.ypos - prevy + print(dx,dy) prevx, prevy = data.xpos, data.ypos local transform = entities:getComponent(id, "transform") @@ -192,6 +209,43 @@ function setupEntities() end end)() + package.loaded["capsuleMove"] = function(entities, id, dt) + 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 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} + + if pressed(glfw.KEY_W) then + vel = vel + forward + end + if pressed(glfw.KEY_A) then + vel = vel + left + end + if pressed(glfw.KEY_S) then + vel = vel - forward + end + if pressed(glfw.KEY_D) then + vel = vel - left + end + + vel = 10000 * vel:normalize() + + x, y, z = ode.BodyGetLinearVel(capsule._body) + if Vec3{x,y,z}:norm2() < 500 then + ode.BodyAddForce(capsule._body, vel[1], vel[2], vel[3]) + end + end + local capcam = entities:createEntityWithComponents{ camera = { |