summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--honey/std.lua11
-rw-r--r--main.lua71
-rw-r--r--save23
-rw-r--r--scripts/capsuleMove.lua37
4 files changed, 68 insertions, 74 deletions
diff --git a/honey/std.lua b/honey/std.lua
index b0b6a15..d609844 100644
--- a/honey/std.lua
+++ b/honey/std.lua
@@ -4,6 +4,11 @@ honey.init = init.init
honey.loop = init.loop
honey.terminate = init.terminate
+nvg = honey.nvg
+ode = honey.ode
+gl = honey.gl
+glfw = honey.glfw
+
honey.ecs = require 'honey.ecs'
honey.mesh = require 'honey.mesh'
honey.shader = require 'honey.shader'
@@ -18,6 +23,6 @@ end
local glm = require 'honey.glm'
-honey.Vec3 = glm.Vec3
-honey.Mat4 = glm.Mat4
-honey.Quaternion = glm.Quaternion
+Vec3 = glm.Vec3
+Mat4 = glm.Mat4
+Quaternion = glm.Quaternion
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" },
}
diff --git a/save b/save
index d0d30da..d46ce82 100644
--- a/save
+++ b/save
@@ -1,11 +1,12 @@
-Entity("5a2dca34-7b2c-4ae7-b679-03dd70edd9f0", {renderMesh={textures={ourTexture={filename="assets/skyboxsun5deg2_tn.jpg"}},shader={fragment="fragment.glsl",vertex="vertex.glsl"},mesh={filename="assets/skybox.obj",index=1}},transform={parent="8b4531ce-1c7e-4a67-a4b3-32ea7506d4fb",matrix=Mat4{2.0000, 0.0000, 0.0000, 0.0000, 0.0000, 2.0000, 0.0000, 0.0000, 0.0000, 0.0000, 2.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}}})
-Entity("0519548e-ac06-4297-98aa-4de8c49e75ec", {onKey={script="cameraKeyHandler"},onWindowResize={script="cameraHandleResize"},transform={matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.9397, 0.3420, 14.9591, 0.0000, -0.3420, 0.9397, 26.4807, 0.0000, 0.0000, 0.0000, 1.0000}},z={value=164},ccamera={render="screen",projection=Mat4{1.8107, 0.0000, 0.0000, 0.0000, 0.0000, 2.4142, 0.0000, 0.0000, 0.0000, 0.0000, -1.0002, -0.2000, 0.0000, 0.0000, -1.0000, 0.0000}}})
-Entity("ddbbdaf1-a51f-4f3e-b2b2-68af145b84c5", {collision={class="plane"},transform={matrix=Mat4{0.9962, -0.0872, 0.0000, 0.0000, 0.0872, 0.9962, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}}})
-Entity("8cc83273-41e0-433d-8b7a-04270cfb682c", {renderMesh={shader={fragment="fragment.glsl",vertex="vertex.glsl"},textures={ourTexture={filename="assets/green+grass-1024x1024.jpg"}},mesh={filename="builtin.quad",index=1}},transform={parent="ddbbdaf1-a51f-4f3e-b2b2-68af145b84c5",matrix=Mat4{20.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.0000, -20.0000, 0.0000, 0.0000, 20.0000, -0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}}})
-Entity("35cc6706-1bfa-45a6-ad54-e2853b6ef024", {transform={matrix=Mat4{-0.2487, -0.9686, -0.0000, -600.4154, 0.9686, -0.2487, -0.0000, -51.5291, 0.0000, -0.0000, 1.0000, -0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={shader={fragment="fragment.glsl",vertex="vertex.glsl"},textures={ourTexture={filename="77155.png"}},mesh={filename="assets/icosahedron.obj",index=1}},physics={velocity=Vec3{-27.3316, -2.3912, -0.0000},angularVelocity=Vec3{-0.0000, -0.0000, 27.4360},mass={class="sphere",radius=1,density=1}},collision={class="sphere",radius=1}})
-Entity("912b0e87-2147-4eb6-a60a-88cedf26b4e4", {renderMesh={shader={fragment="fragment.glsl",vertex="vertex.glsl"},mesh={filename="builtin.quad",index=1}},transform={parent="35cc6706-1bfa-45a6-ad54-e2853b6ef024",matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 2.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}}})
-Entity("26b36992-5357-494b-a68b-1fdcbf8fb692", {renderQuad={shader={fragment="fragment.glsl",vertex="vertex.glsl"},textures={ourTexture={filename="44d9a0ec1c18e6126a5e9d9d9317f5ac.png"}}}})
-Entity("8b4531ce-1c7e-4a67-a4b3-32ea7506d4fb", {transform={matrix=Mat4{1.0000, 0.0000, 0.0000, 5.9029, 0.0000, 0.0000, -1.0000, 2.5230, 0.0000, 1.0000, 0.0000, 6.5042, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={shader={fragment="fragment.glsl",vertex="vertex.glsl"},mesh={filename="assets/capsule.obj",index=1}},physics={velocity=Vec3{-7.9325, -0.5654, -1.4695},maxAngularSpeed=0,mass={class="capsule",length=2,radius=1,direction=3,density=1},angularVelocity=Vec3{0.0000, 0.0000, 0.0000}},collision={class="capsule",radius=1,length=2}})
-Entity("65f318b4-323c-4374-985a-219a4bd6dce4", {transform={parent="8b4531ce-1c7e-4a67-a4b3-32ea7506d4fb",matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.0000, 1.0000, 0.0000, 0.0000, -1.0000, -0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}}})
-Entity("7b27ecd5-ab8c-4d4b-af77-4be73c736260", {onCursorPos={script="cameraCursorPos"},transform={parent="65f318b4-323c-4374-985a-219a4bd6dce4",matrix=Mat4{0.3584, -0.6113, 0.7057, 0.0000, 0.0000, 0.7559, 0.6547, 0.0000, -0.9336, -0.2346, 0.2709, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},script={script="capsuleMove"},pitchyaw={pitch=-40.9,yaw=-651}})
-Entity("5dcfccc8-6acb-4484-aa17-33b5d50f2cf7", {transform={parent="7b27ecd5-ab8c-4d4b-af77-4be73c736260",matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 10.0000, 0.0000, 0.0000, 0.0000, 1.0000}},onWindowResize={script="cameraHandleResize"},camera={render="screen",projection=Mat4{1.3573, 0.0000, 0.0000, 0.0000, 0.0000, 2.4142, 0.0000, 0.0000, 0.0000, 0.0000, -1.0002, -0.2000, 0.0000, 0.0000, -1.0000, 0.0000}}})
+Entity("d4e23dec-aaf4-40fa-a26a-e69a8d37d698", {node={parent="f12474d1-7f6a-4417-9961-31dc12c3b2ae",matrix=Mat4{0.0872, -0.3243, 0.9419, 0.0000, 0.0000, 0.9455, 0.3256, 0.0000, -0.9962, -0.0284, 0.0824, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000},name="pivot"},onCursorPos={script="cameraCursorPos"},pitchyaw={yaw=85,pitch=-19}})
+Entity("ba792e78-0dcd-4b06-9c38-284c949bac85", {node={parent="d4e23dec-aaf4-40fa-a26a-e69a8d37d698",matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 20.0000, 0.0000, 0.0000, 0.0000, 1.0000}},camera={projection=Mat4{1.8107, 0.0000, 0.0000, 0.0000, 0.0000, 2.4142, 0.0000, 0.0000, 0.0000, 0.0000, -1.0002, -0.2000, 0.0000, 0.0000, -1.0000, 0.0000},render="screen"},onWindowResize={script="scripts.cameraHandleResize"}})
+Entity("6f875858-6cae-42e6-a6ba-91f1bda03e02", {node={parent="e007393d-a45e-4666-9a9a-4f7f1d34a201",matrix=Mat4{2.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.0000, -2.0000, 0.0000, 0.0000, 2.0000, -0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={mesh={index=1,filename="assets/skybox.obj"},textures={ourTexture={filename="assets/skyboxsun5deg2_tn.jpg"}},shader={vertex="vertex.glsl",fragment="fragment.glsl"}}})
+Entity("84711390-7b69-4b26-adb1-5a2531f9eceb", {node={matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.0000, -1.0000, -0.0000, 0.0000, 1.0000, -0.0000, 10.0000, 0.0000, 0.0000, 0.0000, 1.0000}},ccamera={projection=Mat4{0.7500, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, -1.0002, -0.2000, 0.0000, 0.0000, -1.0000, 0.0000},render="screen"},onFramebufferSize={script="scripts.cameraHandleResize"}})
+Entity("12354901-ac00-480f-9c58-ae4537113e24", {onKey={script="scripts.loadSaveQuit"},onFramebufferSize={script="scripts.viewportResize"}})
+Entity("9c6a3bb3-fd5e-4cf2-b9aa-d7917ce70d07", {node={matrix=Mat4{0.9962, -0.0872, 0.0000, 0.0000, 0.0872, 0.9962, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},collision={class="plane"}})
+Entity("a693ee99-ca8d-41db-ba62-2bc9f1ddfac6", {node={parent="9c6a3bb3-fd5e-4cf2-b9aa-d7917ce70d07",matrix=Mat4{20.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.0000, -20.0000, 0.0000, 0.0000, 20.0000, -0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={mesh={index=1,filename="builtin.quad"},textures={ourTexture={filename="assets/green+grass-1024x1024.jpg"}},shader={vertex="vertex.glsl",fragment="fragment.glsl"}}})
+Entity("744004be-b572-4bb2-8f45-10bcd9dc5363", {node={matrix=Mat4{-0.9713, -0.2377, 0.0040, 320.2245, -0.1047, 0.4425, 0.8906, 29.0165, -0.2135, 0.8647, -0.4547, -133.0247, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={mesh={index=1,filename="assets/icosahedron.obj"},textures={ourTexture={filename="77155.png"}},shader={vertex="vertex.glsl",fragment="fragment.glsl"}},collision={class="sphere",radius=1},physics={mass={density=1,class="sphere",radius=1},velocity=Vec3{-2.1659, -0.1895, -19.4739},angularVelocity=Vec3{-18.9198, -7.1841, 2.1742}}})
+Entity("41ce559d-445f-44ed-8966-4d08485d6f8d", {node={parent="744004be-b572-4bb2-8f45-10bcd9dc5363",matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 2.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={mesh={index=1,filename="builtin.quad"},shader={vertex="vertex.glsl",fragment="fragment.glsl"}}})
+Entity("32118ff8-d697-41bf-bb7d-f0235bb18bc5", {renderQuad={textures={ourTexture={filename="44d9a0ec1c18e6126a5e9d9d9317f5ac.png"}},shader={vertex="vertex.glsl",fragment="fragment.glsl"}}})
+Entity("e007393d-a45e-4666-9a9a-4f7f1d34a201", {node={matrix=Mat4{1.0000, 0.0000, 0.0000, 262.8474, 0.0000, 0.0000, -1.0000, 26.1377, 0.0000, 1.0000, 0.0000, -65.3207, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={mesh={index=1,filename="assets/capsule.obj"},shader={vertex="vertex.glsl",fragment="fragment.glsl"}},collision={radius=1,length=2,class="capsule"},physics={mass={radius=1,density=1,class="capsule",length=2,direction=3},velocity=Vec3{-52.5918, -5.6735, -4.3262},maxAngularSpeed=0,angularVelocity=Vec3{0.0000, 0.0000, 0.0000}},script={script="scripts.capsuleMove"}})
+Entity("f12474d1-7f6a-4417-9961-31dc12c3b2ae", {node={parent="e007393d-a45e-4666-9a9a-4f7f1d34a201",matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.0000, 1.0000, 0.0000, 0.0000, -1.0000, -0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000},name="p"}})
diff --git a/scripts/capsuleMove.lua b/scripts/capsuleMove.lua
new file mode 100644
index 0000000..e454b06
--- /dev/null
+++ b/scripts/capsuleMove.lua
@@ -0,0 +1,37 @@
+require 'honey.std'
+
+return function(entities, id, dt)
+ local self = honey.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 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