2021-01-15 20:33:25 -06:00
|
|
|
local min = math.min
|
|
|
|
local max = math.max
|
2021-01-13 16:47:16 -06:00
|
|
|
local ball
|
2021-01-14 11:52:01 -06:00
|
|
|
local ball1
|
2021-01-13 16:47:16 -06:00
|
|
|
local camera
|
|
|
|
|
2021-01-13 18:51:58 -06:00
|
|
|
local LEFT = 263
|
|
|
|
local RIGHT = 262
|
|
|
|
local UP = 265
|
|
|
|
local DOWN = 264
|
2021-01-13 20:50:08 -06:00
|
|
|
local Q = 81
|
2021-01-13 18:51:58 -06:00
|
|
|
|
|
|
|
local vx = 0.0
|
|
|
|
local vz = 0.0
|
|
|
|
|
|
|
|
local ballvy = -1.0
|
|
|
|
|
2021-01-13 20:50:08 -06:00
|
|
|
local cam_rot_x = 0.0
|
2021-01-13 22:50:01 -06:00
|
|
|
local cam_rot_y = 0.0
|
2021-01-13 20:50:08 -06:00
|
|
|
|
2021-01-15 20:33:25 -06:00
|
|
|
local SPEED = 30
|
|
|
|
|
2021-01-17 14:36:38 -06:00
|
|
|
local RED = couch.Color(1.0, 0.0, 0.0)
|
|
|
|
local BLUE = couch.Color(0.0, 0.0, 1.0)
|
|
|
|
|
2021-01-13 16:47:16 -06:00
|
|
|
function init()
|
2021-01-20 14:54:54 -06:00
|
|
|
local material
|
|
|
|
|
2021-01-13 16:47:16 -06:00
|
|
|
camera = couch.Camera()
|
|
|
|
camera:MakeCurrent()
|
2021-01-13 20:08:39 -06:00
|
|
|
camera.transform:Translate(0.0, 0.0, 10.0)
|
2021-01-13 16:47:16 -06:00
|
|
|
ball = couch.Ball()
|
|
|
|
ball:SetupMesh()
|
2021-01-20 15:16:44 -06:00
|
|
|
material = couch.Material()
|
2021-01-20 14:54:54 -06:00
|
|
|
material.color = RED
|
|
|
|
material.usesColor = true
|
|
|
|
ball:SetMaterial(0, material)
|
2021-01-14 11:52:01 -06:00
|
|
|
couch.Node.GetRoot().children:Append(ball)
|
2021-01-13 18:51:58 -06:00
|
|
|
ball1 = couch.Ball()
|
|
|
|
ball1:SetupMesh()
|
2021-01-20 15:16:44 -06:00
|
|
|
material = couch.Material()
|
2021-01-20 14:54:54 -06:00
|
|
|
material.tex = couch.Texture.FromFile("container.png")
|
|
|
|
material.usesTex = true
|
|
|
|
ball1:SetMaterial(0, material)
|
2021-01-14 11:52:01 -06:00
|
|
|
couch.Node.GetRoot().children:Append(ball1)
|
2021-01-13 18:51:58 -06:00
|
|
|
|
|
|
|
ball1.transform:Translate(0.0, 3.0, 0.0)
|
2021-01-18 18:25:47 -06:00
|
|
|
|
2021-01-18 19:06:37 -06:00
|
|
|
trough = couch.Mesh.FromFile("trough.glb")
|
|
|
|
trough:SetupMesh()
|
2021-01-20 15:16:44 -06:00
|
|
|
material = couch.Material()
|
2021-01-20 14:54:54 -06:00
|
|
|
material.tex = couch.Texture.FromFile("wood_lowres.png")
|
|
|
|
material.usesTex = true
|
|
|
|
trough:SetMaterial(0, material)
|
2021-01-18 19:06:37 -06:00
|
|
|
couch.Node.GetRoot().children:Append(trough)
|
|
|
|
trough.transform:Translate(10.0, 0.0, 0.0)
|
2021-01-20 12:50:59 -06:00
|
|
|
|
|
|
|
scaffold = couch.Mesh.FromFile("scaffold.glb")
|
|
|
|
scaffold:SetupMesh()
|
2021-01-20 15:16:44 -06:00
|
|
|
material = couch.Material()
|
2021-01-20 14:54:54 -06:00
|
|
|
material.tex = couch.Texture.FromFile("grate_floor_lowres.png")
|
|
|
|
material.usesTex = true
|
|
|
|
scaffold:SetMaterial(0, material)
|
2021-01-20 15:16:44 -06:00
|
|
|
material = couch.Material()
|
2021-01-20 14:54:54 -06:00
|
|
|
material.tex = couch.Texture.FromFile("railing.png")
|
|
|
|
material.usesTex = true
|
|
|
|
scaffold:SetMaterial(1, material)
|
2021-01-20 12:50:59 -06:00
|
|
|
couch.Node.GetRoot().children:Append(scaffold)
|
|
|
|
scaffold.transform:Translate(-10.0, 0.0, 0.0)
|
2021-01-13 16:47:16 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function update(delta)
|
2021-01-15 17:51:19 -06:00
|
|
|
local cam_forwards = camera.transform:Forward()
|
2021-01-15 20:33:25 -06:00
|
|
|
|
|
|
|
local move_vec = couch.Vector3()
|
|
|
|
move_vec = camera.transform.position + cam_forwards * delta * vz * SPEED
|
|
|
|
camera.transform.position = move_vec
|
|
|
|
|
2021-01-13 22:50:01 -06:00
|
|
|
camera.transform.rotation.y = camera.transform.rotation.y - cam_rot_x * delta
|
|
|
|
cam_rot_x = 0.0
|
|
|
|
camera.transform.rotation.x = camera.transform.rotation.x - cam_rot_y * delta
|
2021-01-15 20:33:25 -06:00
|
|
|
camera.transform.rotation.x = min(max(camera.transform.rotation.x, -3.14), 3.14)
|
2021-01-13 22:50:01 -06:00
|
|
|
cam_rot_y = 0.0
|
2021-01-13 18:51:58 -06:00
|
|
|
|
|
|
|
local loc = ball1.transform.position
|
|
|
|
if loc.y > 4.0 then
|
|
|
|
ballvy = -1.0
|
|
|
|
elseif loc.y < 2.0 then
|
|
|
|
ballvy = 1.0
|
|
|
|
end
|
2021-01-13 20:08:39 -06:00
|
|
|
ball1.transform.position.y = ball1.transform.position.y + ballvy * delta
|
|
|
|
|
|
|
|
ball.transform.rotation.z = ball.transform.rotation.z + 1.0 * delta;
|
2021-01-13 20:50:08 -06:00
|
|
|
ball.transform.rotation.y = ball.transform.rotation.y + 1.0 * delta;
|
2021-01-13 20:08:39 -06:00
|
|
|
ball.transform.rotation.x = ball.transform.rotation.x + 1.0 * delta;
|
2021-01-13 18:51:58 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function onkey(key, code, action, mod)
|
|
|
|
if key == LEFT and action == 1 then
|
|
|
|
vx = -1.0
|
|
|
|
elseif key == RIGHT and action == 1 then
|
|
|
|
vx = 1.0
|
|
|
|
elseif (key == LEFT or key == RIGHT) and action == 0 then
|
|
|
|
vx = 0.0
|
|
|
|
end
|
|
|
|
|
|
|
|
if key == UP and action == 1 then
|
|
|
|
vz = 1.0
|
2021-01-15 20:33:25 -06:00
|
|
|
elseif key == DOWN and action == 1 then
|
|
|
|
vz = -1.0
|
2021-01-13 18:51:58 -06:00
|
|
|
elseif (key == DOWN or key == UP) and action == 0 then
|
|
|
|
vz = 0.0
|
|
|
|
end
|
2021-01-13 20:50:08 -06:00
|
|
|
|
|
|
|
if key == Q then
|
|
|
|
if action == 1 then
|
|
|
|
cam_rot_x = 1.0
|
2021-01-13 21:23:22 -06:00
|
|
|
elseif action == 0 then
|
2021-01-13 20:50:08 -06:00
|
|
|
cam_rot_x = 0.0
|
|
|
|
end
|
|
|
|
end
|
2021-01-13 16:47:16 -06:00
|
|
|
end
|
2021-01-13 22:50:01 -06:00
|
|
|
|
|
|
|
function onmousemotion(_, _, relx, rely)
|
|
|
|
cam_rot_x = relx
|
|
|
|
cam_rot_y = rely
|
|
|
|
end
|