summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/attribution.txt1
-rw-r--r--assets/green+grass-1024x1024.jpgbin0 -> 465227 bytes
-rw-r--r--main.lua56
-rw-r--r--save17
4 files changed, 67 insertions, 7 deletions
diff --git a/assets/attribution.txt b/assets/attribution.txt
index 9755abb..29cfc2c 100644
--- a/assets/attribution.txt
+++ b/assets/attribution.txt
@@ -1 +1,2 @@
skyboxsun5deg2_tn.jpg: https://reije081.home.xs4all.nl/skyboxes/
+green grass.jpg: https://www.the3rdsequence.com/texturedb/texture/1/green+grass/
diff --git a/assets/green+grass-1024x1024.jpg b/assets/green+grass-1024x1024.jpg
new file mode 100644
index 0000000..4269ae9
--- /dev/null
+++ b/assets/green+grass-1024x1024.jpg
Binary files differ
diff --git a/main.lua b/main.lua
index 4372a03..62f0422 100644
--- a/main.lua
+++ b/main.lua
@@ -74,6 +74,18 @@ function setupEntities()
class = "plane",
},
})
+
+ local planeMesh = entities:createEntityWithComponents{
+ transform = {
+ parent = plane,
+ matrix = Mat4():identity():rotateX(0.5*math.pi):scale(Vec3{20,20,20}),
+ },
+ renderMesh = {
+ textures = { ourTexture={ filename="assets/green+grass-1024x1024.jpg" } },
+ shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
+ mesh = { filename="builtin.quad", index=1 },
+ },
+ }
@@ -170,12 +182,17 @@ function setupEntities()
yaw = 0,
},
onCursorPos = { script = "cameraCursorPos" },
+ script = { script = "capsuleMove" },
}
package.loaded["cameraCursorPos"] = (function()
- local prevx, prevy = 0, 0
+ 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
+ print(dx,dy)
prevx, prevy = data.xpos, data.ypos
local transform = entities:getComponent(id, "transform")
@@ -192,6 +209,43 @@ function setupEntities()
end
end)()
+ package.loaded["capsuleMove"] = function(entities, id, dt)
+ local pressed = function(key)
+ return glfw.GetKey(window.win, key) == glfw.PRESS
+ end
+
+ local py = entities:getComponent(id, "pitchyaw")
+ local yaw = math.rad(py.yaw)
+ local forward = Vec3{-math.sin(yaw), 0, -math.cos(yaw)}
+ local left = Vec3{-math.cos(yaw), 0, math.sin(yaw)}
+
+ print(forward, left)
+
+ 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 = 10000 * vel:normalize()
+
+ x, y, z = ode.BodyGetLinearVel(capsule._body)
+ if Vec3{x,y,z}:norm2() < 500 then
+ ode.BodyAddForce(capsule._body, vel[1], vel[2], vel[3])
+ end
+ end
+
local capcam = entities:createEntityWithComponents{
camera = {
diff --git a/save b/save
index a5e128c..d0d30da 100644
--- a/save
+++ b/save
@@ -1,6 +1,11 @@
-Entity("4ed429ea-a611-4b0e-9cab-fe2abdb86b9c", {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("c632332d-2283-49cf-9aa6-9cf45d369bd9", {physics={velocity=Vec3{-0.6251, -0.0547, 0.0000},angularVelocity=Vec3{0.0000, 0.0000, 0.6275},mass={density=1,class="sphere",radius=1}},collision={class="sphere",radius=1},renderMesh={textures={ourTexture={filename="77155.png"}},mesh={index=1,filename="assets/icosahedron.obj"},shader={vertex="vertex.glsl",fragment="fragment.glsl"}},transform={matrix=Mat4{0.4476, -0.8942, 0.0000, -0.3201, 0.8942, 0.4476, 0.0000, 0.9725, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}}})
-Entity("c0e68906-f2f0-4455-918b-75fc2666d58b", {renderMesh={mesh={index=1,filename="builtin.quad"},shader={vertex="vertex.glsl",fragment="fragment.glsl"}},transform={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},parent="c632332d-2283-49cf-9aa6-9cf45d369bd9"}})
-Entity("ad305b40-a3d8-4c61-95c6-654bd161b559", {renderQuad={textures={ourTexture={filename="44d9a0ec1c18e6126a5e9d9d9317f5ac.png"}},shader={vertex="vertex.glsl",fragment="fragment.glsl"}}})
-Entity("fb6a418d-d5b7-46fb-9dba-a86a6e214933", {physics={velocity=Vec3{0.0000, -10.0800, 0.0000},angularVelocity=Vec3{0.0000, 0.0000, 0.0000},mass={density=1,class="capsule",length=2,direction=3,radius=1}},collision={class="capsule",length=2,radius=1},renderMesh={mesh={index=1,filename="assets/capsule.obj"},shader={vertex="vertex.glsl",fragment="fragment.glsl"}},transform={matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 4.8390, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000}}})
-Entity("19855b55-d756-4471-a65d-641270f2b4e3", {onKey={script="cameraKeyHandler"},onWindowResize={script="cameraHandleResize"},transform={matrix=Mat4{1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.9397, 0.3420, 19.6575, 0.0000, -0.3420, 0.9397, 24.7706, 0.0000, 0.0000, 0.0000, 1.0000}},camera={render="screen",projection=Mat4{3.9434, 0.0000, 0.0000, 0.0000, 0.0000, 2.4142, 0.0000, 0.0000, 0.0000, 0.0000, -1.0020, -0.2002, 0.0000, 0.0000, -1.0000, 0.0000}},z={value=-60}})
+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}}})