From 02c6f822e2cca41d5d28afd9f3a05211316587fd Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 15 Apr 2023 20:04:57 -0500 Subject: add collision system --- main.lua | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index fe97123..0f46f70 100644 --- a/main.lua +++ b/main.lua @@ -38,6 +38,7 @@ local systems = ecs.SystemDb(entities) systems:addSystem(sys.transform) systems:addSystem(sys.renderCamera) systems:addSystem(sys.script) +systems:addSystem(sys.collision, {space=space}) systems:addSystem(sys.physics, {space=space, world=world}) package.loaded['baseRotationScript'] = function(entities, id, dt) local transform = entities:getComponent(id, "transform") @@ -77,6 +78,19 @@ function setupEntities() }, onWindowResize = { script = "cameraHandleResize" }, }) + + + local plane = entities:createEntity() + entities:addComponents(plane, { + transform = { + matrix = Mat4() + :identity() + :rotateZ(math.rad(5)) + }, + collision = { + class = "plane", + }, + }) @@ -88,7 +102,14 @@ function setupEntities() mesh = { filename="assets/icosahedron.obj", index=1 }, }, transform = { - matrix = Mat4():identity():rotateZ(math.rad(45)), + matrix = Mat4() + :identity() + :translate(Vec3{0,1,0}) + :rotateZ(math.rad(45)), + }, + collision = { + class = "sphere", + radius = 1, }, physics = { mass = { @@ -96,8 +117,8 @@ function setupEntities() density = 1, radius = 1, }, - velocity = Vec3{ 0, 10, 0 }, - angularVelocity = Vec3{ 0, 1, 0 }, + velocity = Vec3{ 0, 0, 0 }, + angularVelocity = Vec3{ 0, 0, 0 }, }, }) -- cgit v1.2.1