Compare commits

..

No commits in common. "02c4525b87067c355e5af9f2d7656b40435e5d37" and "53bfd04a04634da4d7efa64f3b60a6c4546ecde4" have entirely different histories.

3 changed files with 50 additions and 9 deletions

1
.gitignore vendored
View File

@ -4,4 +4,3 @@ libgame.so
libtownengine.so
lua
CMakeLists.txt
quack

View File

@ -1,13 +1,22 @@
-- called every frame, with constant delta time
local capture = false
local Vector3 = require "vector3"
local trig = require "trig"
local Vector3l = require "vector3"
local function Vector3(x, y, z)
if y == nil then
return {x = x, y = x, z = x}
end
return {x = x, y = y, z = z}
end
local rot = 0
local rot_spd = 0.05
local spd = 0.07
local pos = Vector3()
local pos = Vector3(0)
local function Vector2(x, y)
if y == nil then
@ -39,7 +48,6 @@ function game_tick()
if ctx.initialization_needed then
-- ctx.udata persists on reload
ctx.udata = {}
print(Vector3(5, 0, 0))
end
ctx.mouse_capture = capture
input_action{name="quit", control="SPACE"}
@ -56,16 +64,15 @@ function game_tick()
capture = false
end
end
local dir = Vector3(draw_camera_from_principal_axes{position = pos, yaw = rot}.direction)
local dir = draw_camera_from_principal_axes{position = pos, yaw = rot}.direction
dir.y = 0
dir = dir:normalized()
dir = trig.v3_normalized(dir)
local rot_d = b2n(input_action_pressed{name = "right"}) - b2n(input_action_pressed{name = "left"})
rot = rot + rot_d * rot_spd
local mov_d = b2n(input_action_pressed{name = "forward"}) - b2n(input_action_pressed{name = "back"})
-- pos = trig.v3_add(pos, trig.v3_mult(dir, spd * mov_d))
pos = pos + dir * spd * mov_d
pos = trig.v3_add(pos, trig.v3_mult(dir, spd * mov_d))
draw_billboard{position = Vector3(5, 0, 0), size = Vector2(1, 1), texture = "images/duck.png"}
end

View File

@ -1,3 +1,38 @@
local M = {}
function M.v3_length_squared(v)
local x2 = v.x * v.x
local y2 = v.y * v.y
local z2 = v.z * v.z
return x2 + y2 + z2
end
function M.v3_normalized(v)
local length = math.sqrt(M.v3_length_squared(v))
local new_vec = {
x = v.x / length,
y = v.y / length,
z = v.z / length,
}
return new_vec
end
function M.v3_mult(v, f)
return {
x = v.x * f,
y = v.y * f,
z = v.z * f,
}
end
function M.v3_add(v1, v2)
return {
x = v1.x + v2.x,
y = v1.y + v2.y,
z = v1.z + v2.z,
}
end
return M