summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.lua38
-rw-r--r--save24
-rw-r--r--scripts/cameraHandleResize.lua1
-rw-r--r--scripts/cameraPivot.lua21
4 files changed, 36 insertions, 48 deletions
diff --git a/main.lua b/main.lua
index 1381c64..d35872c 100644
--- a/main.lua
+++ b/main.lua
@@ -29,17 +29,6 @@ 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)
-end
-package.loaded['cameraRotationScript'] = function(entities, id, dt)
- local node = entities:getComponent(id, "node")
- local z = entities:getComponent(id, "z")
- node.matrix
- :identity()
- :translate(Vec3{0, 0, z.value + math.sin(math.pi * glfw.GetTime())})
-end
function setupEntities()
@@ -164,31 +153,8 @@ function setupEntities()
pitch = 0,
yaw = 0,
},
- onCursorPos = { script = "cameraCursorPos" },
+ onCursorPos = { script = "scripts.cameraPivot" },
}
- package.loaded["cameraCursorPos"] = (function()
- local prevx, prevy
- return function(entities, id, data)
- if not prevx then
- prevx, prevy = data.xpos, data.ypos
- end
- local dx = data.xpos - prevx
- local dy = data.ypos - prevy
- prevx, prevy = data.xpos, data.ypos
-
- local node = entities:getComponent(id, "node")
- local py = entities:getComponent(id, "pitchyaw")
- py.pitch = py.pitch - dy
- py.yaw = py.yaw - dx
- if py.pitch > 89.9 then py.pitch = 89.9 end
- if py.pitch < -89.9 then py.pitch = -89.9 end
-
- node.matrix
- :identity()
- :rotateY(math.rad(py.yaw))
- :rotateX(math.rad(py.pitch))
- end
- end)()
local capcam = entities:createEntityWithComponents{
@@ -200,7 +166,7 @@ function setupEntities()
parent = capcamPivot,
matrix = Mat4():identity():translate(Vec3{0,0,20}),
},
- onWindowResize = { script = "scripts.cameraHandleResize" },
+ onFramebufferSize = { script = "scripts.cameraHandleResize" },
}
diff --git a/save b/save
index 5e27ad1..788c570 100644
--- a/save
+++ b/save
@@ -1,12 +1,12 @@
-Entity("e95489ac-116c-49ca-981a-df5550eae1f5", {renderQuad={shader={fragment="fragment.glsl",vertex="vertex.glsl"},textures={ourTexture={filename="44d9a0ec1c18e6126a5e9d9d9317f5ac.png"}}}})
-Entity("069ecd42-7047-4b64-90f8-316bfe32fd67", {node={matrix=Mat4{1.0000, 0.0000, 0.0000, 4.0833, 0.0000, 0.0000, -1.0000, 2.3528, 0.0000, 1.0000, 0.0000, -0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={shader={fragment="fragment.glsl",vertex="vertex.glsl"},mesh={filename="assets/capsule.obj",index=1}},collision={radius=1,length=2,class="capsule"},physics={angularVelocity=Vec3{0.0000, 0.0000, 0.0000},mass={radius=1,length=2,density=1,direction=3,class="capsule"},velocity=Vec3{-0.0229, -0.0020, 0.0000},maxAngularSpeed=0},script={script="scripts.capsuleMove"}})
-Entity("4b19c122-9ca7-4cfa-941a-01a22624dbab", {node={parent="069ecd42-7047-4b64-90f8-316bfe32fd67",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"}})
-Entity("a57cc635-fe17-42a2-9f96-0edf92e59aee", {node={parent="4b19c122-9ca7-4cfa-941a-01a22624dbab",matrix=Mat4{-0.9063, -0.2596, 0.3335, 0.0000, 0.0000, 0.7891, 0.6143, 0.0000, -0.4226, 0.5567, -0.7152, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000},name="pivot"},pitchyaw={yaw=-205,pitch=-37.9},onCursorPos={script="cameraCursorPos"}})
-Entity("b768e8d7-39b4-4414-b98b-fac4fbbaa516", {onWindowResize={script="scripts.cameraHandleResize"},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"},node={parent="a57cc635-fe17-42a2-9f96-0edf92e59aee",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}}})
-Entity("73d66887-4a79-4265-969d-1b9720e521fc", {node={parent="069ecd42-7047-4b64-90f8-316bfe32fd67",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={shader={fragment="fragment.glsl",vertex="vertex.glsl"},mesh={filename="assets/skybox.obj",index=1},textures={ourTexture={filename="assets/skyboxsun5deg2_tn.jpg"}}}})
-Entity("526d5532-aa4e-4263-b701-a5743cb77cd1", {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"},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}}})
-Entity("c2cb5cb0-d0fb-49a6-9226-9a47e22e568f", {onKey={script="scripts.loadSaveQuit"},onFramebufferSize={script="scripts.viewportResize"}})
-Entity("969e4aea-ffef-4e60-8d83-6307c7d6480a", {collision={class="plane"},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}}})
-Entity("5910b165-cd58-430d-8f55-726df47baaf8", {node={parent="969e4aea-ffef-4e60-8d83-6307c7d6480a",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={textures={ourTexture={filename="assets/green+grass-1024x1024.jpg"}},mesh={filename="builtin.quad",index=1},shader={fragment="fragment.glsl",vertex="vertex.glsl"}}})
-Entity("5bb55536-bbf8-47b6-b8c6-f00594fffcca", {node={matrix=Mat4{0.7256, 0.6882, 0.0000, 1.5353, -0.6882, 0.7256, 0.0000, 1.1348, 0.0000, -0.0000, 1.0000, -0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},renderMesh={textures={ourTexture={filename="77155.png"}},mesh={filename="assets/icosahedron.obj",index=1},shader={fragment="fragment.glsl",vertex="vertex.glsl"}},collision={class="sphere",radius=1},physics={mass={density=1,class="sphere",radius=1},velocity=Vec3{-0.8081, -0.0707, -0.0000},angularVelocity=Vec3{-0.0000, -0.0000, 0.8112}}})
-Entity("127cb719-4960-463b-baaf-641316baabc2", {node={parent="5bb55536-bbf8-47b6-b8c6-f00594fffcca",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={shader={fragment="fragment.glsl",vertex="vertex.glsl"},mesh={filename="builtin.quad",index=1}}})
+Entity("da572a27-909f-4e33-9b2b-d26a46e0b99c", {node={name="p",parent="ea9b0c92-30d2-47a0-9d80-060a61f4b01b",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("c9b1e77d-b5c7-4208-8fbd-0761d6fb1da8", {onFramebufferSize={script="scripts.viewportResize"},onKey={script="scripts.loadSaveQuit"}})
+Entity("7e203ab5-abd0-421b-8694-003a4d77039d", {onFramebufferSize={script="scripts.cameraHandleResize"},camera={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},render="screen"},node={parent="9e81e64c-3fe8-456d-9815-c181d222662a",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}}})
+Entity("17b94ee1-b8e3-4ee3-b2ec-c7a274158cad", {renderMesh={shader={vertex="vertex.glsl",fragment="fragment.glsl"},textures={ourTexture={filename="assets/skyboxsun5deg2_tn.jpg"}},mesh={filename="assets/skybox.obj",index=1}},node={parent="ea9b0c92-30d2-47a0-9d80-060a61f4b01b",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}}})
+Entity("528c3418-64dc-404b-b40e-7cf457d7aa70", {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("06ba239b-62da-4340-a1d5-134458fb1005", {collision={radius=1,class="sphere"},renderMesh={textures={ourTexture={filename="77155.png"}},shader={vertex="vertex.glsl",fragment="fragment.glsl"},mesh={filename="assets/icosahedron.obj",index=1}},physics={mass={density=1,radius=1,class="sphere"},velocity=Vec3{-2.3798, -0.2083, 3.0820},angularVelocity=Vec3{3.7957, -8.0179, 2.3889}},node={matrix=Mat4{-0.7850, 0.3990, 0.4738, -22.8622, 0.6096, 0.6337, 0.4762, -1.0007, -0.1103, 0.6627, -0.7407, 40.5313, 0.0000, 0.0000, 0.0000, 1.0000}}})
+Entity("9e81e64c-3fe8-456d-9815-c181d222662a", {onCursorPos={script="scripts.cameraPivot"},node={name="pivot",parent="da572a27-909f-4e33-9b2b-d26a46e0b99c",matrix=Mat4{-0.9135, -0.2560, 0.3161, 0.0000, 0.0000, 0.7771, 0.6293, 0.0000, -0.4067, 0.5749, -0.7100, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}},pitchyaw={pitch=-39,yaw=-1284}})
+Entity("ea9b0c92-30d2-47a0-9d80-060a61f4b01b", {renderMesh={shader={vertex="vertex.glsl",fragment="fragment.glsl"},mesh={filename="assets/capsule.obj",index=1}},physics={mass={radius=1,class="capsule",density=1,direction=3,length=2},angularVelocity=Vec3{0.0000, 0.0000, 0.0000},velocity=Vec3{-3.3700, -0.3634, 7.5619},maxAngularSpeed=0},script={script="scripts.capsuleMove"},collision={radius=1,class="capsule",length=2},node={matrix=Mat4{1.0000, 0.0000, 0.0000, 5.8502, 0.0000, 0.0000, -1.0000, 2.5154, 0.0000, 1.0000, 0.0000, 9.9416, 0.0000, 0.0000, 0.0000, 1.0000}}})
+Entity("e94dddfb-57ea-4c7c-8b27-c1dae3df1f8d", {onFramebufferSize={script="scripts.cameraHandleResize"},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"},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}}})
+Entity("377d9441-2c63-4e36-a5fc-5ac1b6939126", {renderMesh={textures={ourTexture={filename="assets/green+grass-1024x1024.jpg"}},shader={vertex="vertex.glsl",fragment="fragment.glsl"},mesh={filename="builtin.quad",index=1}},node={parent="528c3418-64dc-404b-b40e-7cf457d7aa70",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("51daa068-1bbc-427b-b145-d63390f329dc", {renderMesh={shader={vertex="vertex.glsl",fragment="fragment.glsl"},mesh={filename="builtin.quad",index=1}},node={parent="06ba239b-62da-4340-a1d5-134458fb1005",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("2e5a45ec-e72c-445f-aa16-e92670f31b5a", {renderQuad={shader={vertex="vertex.glsl",fragment="fragment.glsl"},textures={ourTexture={filename="44d9a0ec1c18e6126a5e9d9d9317f5ac.png"}}}})
diff --git a/scripts/cameraHandleResize.lua b/scripts/cameraHandleResize.lua
index 7d1713d..97974f5 100644
--- a/scripts/cameraHandleResize.lua
+++ b/scripts/cameraHandleResize.lua
@@ -1,6 +1,7 @@
return function(entities, id, data)
local camera = entities:getComponent(id, "camera")
if camera then
+ print("resize camera!")
camera.projection:perspectiveResize(data.width/data.height)
end
end
diff --git a/scripts/cameraPivot.lua b/scripts/cameraPivot.lua
new file mode 100644
index 0000000..d2fad59
--- /dev/null
+++ b/scripts/cameraPivot.lua
@@ -0,0 +1,21 @@
+local prevx, prevy
+return function(entities, id, data)
+ if not prevx then
+ prevx, prevy = data.xpos, data.ypos
+ end
+ local dx = data.xpos - prevx
+ local dy = data.ypos - prevy
+ prevx, prevy = data.xpos, data.ypos
+
+ local node = entities:getComponent(id, "node")
+ local py = entities:getComponent(id, "pitchyaw")
+ py.pitch = py.pitch - dy
+ py.yaw = py.yaw - dx
+ if py.pitch > 89.9 then py.pitch = 89.9 end
+ if py.pitch < -89.9 then py.pitch = -89.9 end
+
+ node.matrix
+ :identity()
+ :rotateY(math.rad(py.yaw))
+ :rotateX(math.rad(py.pitch))
+end