diff options
author | sanine <sanine.not@pm.me> | 2023-05-07 21:16:13 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-07 21:16:13 -0500 |
commit | 61f8813b0beb6228f99cf0ea80acee5f4cab063f (patch) | |
tree | c4eca7d64a045b70f0eca34d02162235c1a6acdd /main.lua | |
parent | 445fc5217859a799e3a977c9763141d9a5f6cbb5 (diff) |
correctly implement capsule collisions and camera view matrix
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 61 |
1 files changed, 42 insertions, 19 deletions
@@ -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() |