diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-09 14:46:08 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-09 14:46:08 -0500 |
commit | 9c9690ab5e4ecb484ee130c21f1767785908bd10 (patch) | |
tree | 847d7868a25936b1e632caac2b581b2c90d0eee0 /main.lua | |
parent | fe6564d8c31662d4d2c2606c62ba6d4416c6b6a6 (diff) |
fix texture loading
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 73 |
1 files changed, 21 insertions, 52 deletions
@@ -51,14 +51,6 @@ package.loaded['cameraRotationScript'] = function(entities, id, dt) :identity() :translate(Vec3{0, 0, z.value + math.sin(math.pi * glfw.GetTime())}) end -package.loaded['cameraKeyHandler'] = function(entities, id, data) - local z = entities:getComponent(id, "z") - if data.key == glfw.KEY_W then - z.value = z.value + 1 - elseif data.key == glfw.KEY_S then - z.value = z.value - 1 - end -end function setupEntities() @@ -239,7 +231,7 @@ function setupEntities() vel = vel - left end - vel = 10000 * vel:normalize() + vel = 1000 * vel:normalize() x, y, z = ode.BodyGetLinearVel(self.physics._body) if Vec3{x,y,z}:norm2() < 500 then @@ -257,21 +249,25 @@ function setupEntities() parent = capcamPivot, matrix = Mat4():identity():translate(Vec3{0,0,10}), }, - onWindowResize = { script = "cameraHandleResize" }, + onWindowResize = { script = "scripts.cameraHandleResize" }, } local skybox = entities:createEntityWithComponents{ node = { parent = capsule, - matrix = Mat4():identity():scale(Vec3{2,2,2}), + matrix = Mat4():identity():scale(Vec3{2,2,2}):rotateX(math.rad(90)) }, renderMesh = { - mesh = { filename="assets/skybox.obj", index=1 }, + mesh = { + filename="assets/skybox.obj", + index=1, + }, shader = { vertex="vertex.glsl", fragment="fragment.glsl" }, textures = { ourTexture = { filename = "assets/skyboxsun5deg2_tn.jpg" + --filename = "assets/skybox.png" } }, }, @@ -281,55 +277,28 @@ function setupEntities() local camera = entities:createEntity() entities:addComponents(camera, { ccamera={ - projection=Mat4():perspective(math.rad(45), 640/480, 0.1, 1000), + projection=Mat4():perspective(math.rad(90), 640/480, 0.1, 1000), render="screen", }, node={ - matrix=Mat4():identity():rotateX(math.rad(-20)):translate(Vec3{0, 5, 30}), - }, - z = {value=-60}, - onKey = { - script="cameraKeyHandler", + matrix=Mat4() + :identity() + :rotateX(math.rad(90)) + :translate(Vec3{0, 10, 0}), }, - onWindowResize = { script = "cameraHandleResize" }, + onFramebufferSize = { script = "scripts.cameraHandleResize" }, }) + + local misc = entities:createEntityWithComponents{ + onKey = { script = "scripts.loadSaveQuit" }, + onFramebufferSize = { script = "scripts.viewportResize" }, + } end setupEntities() - --- close window on ESCAPE key -window:setKeyCallback(function(_, key, scancode, action) - script.dispatch(entities, "onKey", {key=key, scancode=scancode, action=action}) - if action == glfw.PRESS then - if key == glfw.KEY_ESCAPE then - window:setShouldClose(true) - elseif key == glfw.KEY_SPACE then - entities:save("save") - elseif key == glfw.KEY_L then - entities:load("save") - end - end -end) - - -window:setCursorPosCallback(function(_, xpos, ypos) - script.dispatch(entities, "onCursorPos", {xpos=xpos, ypos=ypos}) -end) - --- resize window correctly -window:setFramebufferSizeCallback(function(_, width, height) - gl.Viewport(0, 0, width, height) - vw, vh = width, height - script.dispatch(entities, "onWindowResize", { width=width, height=height }) -end) - -package.loaded["cameraHandleResize"] = function(entities, id, data) - local camera = entities:getComponent(id, "camera") - if not camera then return end - camera.projection:perspectiveResize(data.width/data.height) -end - +-- connect event handler scripts +window:bindEvents(entities) --entities:load("save") |