summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua71
1 files changed, 11 insertions, 60 deletions
diff --git a/main.lua b/main.lua
index 12cca05..1381c64 100644
--- a/main.lua
+++ b/main.lua
@@ -1,18 +1,7 @@
require 'honey.std'
-local glfw = honey.glfw
-local gl = honey.gl
-local Vec3 = honey.Vec3
-local Mat4 = honey.Mat4
-local Quaternion = honey.Quaternion
-local ecs = honey.ecs
-local sys = honey.standardSystems
-local ode = honey.ode
-local nvg = honey.nvg
-
-
-- initialize honey
-local window = honey.init()
+window = honey.init()
window:setInputMode(glfw.CURSOR, glfw.CURSOR_DISABLED)
-- setup vector graphics
@@ -32,14 +21,14 @@ end)
-- setup ecs
-local entities = ecs.EntityDb()
-local systems = ecs.SystemDb(entities)
-local script = ecs.script
-systems:addSystem(ecs.node.system)
-systems:addSystem(ecs.render.system)
-systems:addSystem(ecs.script.system)
-systems:addSystem(ecs.collision.system, {space=space})
-systems:addSystem(ecs.physics.system, {space=space, world=world})
+local entities = honey.ecs.EntityDb()
+local systems = honey.ecs.SystemDb(entities)
+local script = honey.ecs.script
+systems:addSystem(honey.ecs.node.system)
+systems:addSystem(honey.ecs.render.system)
+systems:addSystem(honey.ecs.script.system)
+systems:addSystem(honey.ecs.collision.system, {space=space})
+systems:addSystem(honey.ecs.physics.system, {space=space, world=world})
package.loaded['baseRotationScript'] = function(entities, id, dt)
local node = entities:getComponent(id, "node")
node.matrix:rotateZ(math.pi * dt)
@@ -152,7 +141,7 @@ function setupEntities()
mesh = { filename="assets/capsule.obj", index=1 },
shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
},
- script = { script = "capsuleMove" },
+ script = { script = "scripts.capsuleMove" },
}
@@ -201,44 +190,6 @@ function setupEntities()
end
end)()
- package.loaded["capsuleMove"] = function(entities, id, dt)
- local self = ecs.Accessor(entities, id)
- local pressed = function(key)
- return glfw.GetKey(window.win, key) == glfw.PRESS
- end
-
- local yaw = math.rad(
- self.node._child.p
- .node._child.pivot
- .pitchyaw.yaw)
- local forward = Vec3{-math.sin(yaw), 0, -math.cos(yaw)}
- local left = Vec3{-math.cos(yaw), 0, math.sin(yaw)}
-
- 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 = 1000 * vel:normalize()
-
- x, y, z = ode.BodyGetLinearVel(self.physics._body)
- if Vec3{x,y,z}:norm2() < 500 then
- ode.BodyAddForce(self.physics._body, vel[1], vel[2], vel[3])
- end
- end
-
local capcam = entities:createEntityWithComponents{
camera = {
@@ -247,7 +198,7 @@ function setupEntities()
},
node = {
parent = capcamPivot,
- matrix = Mat4():identity():translate(Vec3{0,0,10}),
+ matrix = Mat4():identity():translate(Vec3{0,0,20}),
},
onWindowResize = { script = "scripts.cameraHandleResize" },
}