From 61f8813b0beb6228f99cf0ea80acee5f4cab063f Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 7 May 2023 21:16:13 -0500 Subject: correctly implement capsule collisions and camera view matrix --- main.lua | 61 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 19 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index ff746c7..c06b80c 100644 --- a/main.lua +++ b/main.lua @@ -61,25 +61,6 @@ package.loaded['cameraKeyHandler'] = function(entities, id, data) end function setupEntities() - local camera = entities:createEntity() - entities:addComponents(camera, { - camera={ - projection=Mat4():perspective(math.rad(45), 640/480, 0.1, 100), - render="screen", - }, - transform={ - matrix=Mat4():identity():translate(Vec3{0, 0, -6}), - }, - z = {value=-60}, - script={ - script="cameraRotationScript", - }, - onKey = { - script="cameraKeyHandler", - }, - onWindowResize = { script = "cameraHandleResize" }, - }) - local plane = entities:createEntity() entities:addComponents(plane, { @@ -143,6 +124,47 @@ function setupEntities() textures = { ourTexture = { filename = "44d9a0ec1c18e6126a5e9d9d9317f5ac.png" } }, }, }) + + local capsule = entities:createEntityWithComponents{ + transform = { + matrix = Mat4():identity():translate(Vec3{0,10,0}) + }, + collision = { + class = "capsule", + radius = 1, + length = 2, + }, + physics = { + mass = { + class = "capsule", + density = 1, + direction = 3, + radius = 1, + length = 2, + }, + }, + renderMesh = { + mesh = { filename="assets/capsule.obj", index=1 }, + shader = { vertex="vertex.glsl", fragment="fragment.glsl" }, + }, + } + + + local camera = entities:createEntity() + entities:addComponents(camera, { + camera={ + projection=Mat4():perspective(math.rad(45), 640/480, 0.1, 100), + render="screen", + }, + transform={ + matrix=Mat4():identity():rotateX(math.rad(-20)):translate(Vec3{0, 10, 30}), + }, + z = {value=-60}, + onKey = { + script="cameraKeyHandler", + }, + onWindowResize = { script = "cameraHandleResize" }, + }) end setupEntities() @@ -200,5 +222,6 @@ honey.loop(window, function(dt) nvg.EndFrame(vg) end) + -- clean up honey.terminate() -- cgit v1.2.1