Compare commits
No commits in common. "35b06ec9dbf20cfc70a636049c3270891228ccb6" and "02c4525b87067c355e5af9f2d7656b40435e5d37" have entirely different histories.
35b06ec9db
...
02c4525b87
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,6 +5,3 @@ libtownengine.so
|
|||||||
lua
|
lua
|
||||||
CMakeLists.txt
|
CMakeLists.txt
|
||||||
quack
|
quack
|
||||||
|
|
||||||
# i was told binary files are bad for git ¯\_(ツ)_/¯
|
|
||||||
data/fonts
|
|
@ -1,17 +1,13 @@
|
|||||||
local FONT = "fonts/Lunchtype21_Regular.ttf"
|
-- called every frame, with constant delta time
|
||||||
|
|
||||||
local Vector3 = require "vector3"
|
|
||||||
local capture = false
|
local capture = false
|
||||||
|
local Vector3 = require "vector3"
|
||||||
|
|
||||||
local head_rotation = 0
|
local rot = 0
|
||||||
local rotate_speed = 0.05
|
local rot_spd = 0.05
|
||||||
|
|
||||||
local mouse_sensitivity = 0.01
|
|
||||||
|
|
||||||
local spd = 0.07
|
local spd = 0.07
|
||||||
|
|
||||||
local position = Vector3()
|
local pos = Vector3()
|
||||||
local velocity = Vector3()
|
|
||||||
|
|
||||||
local function Vector2(x, y)
|
local function Vector2(x, y)
|
||||||
if y == nil then
|
if y == nil then
|
||||||
@ -43,40 +39,33 @@ function game_tick()
|
|||||||
if ctx.initialization_needed then
|
if ctx.initialization_needed then
|
||||||
-- ctx.udata persists on reload
|
-- ctx.udata persists on reload
|
||||||
ctx.udata = {}
|
ctx.udata = {}
|
||||||
|
print(Vector3(5, 0, 0))
|
||||||
end
|
end
|
||||||
ctx.mouse_capture = capture
|
ctx.mouse_capture = capture
|
||||||
input_action{name="toggle_mouse", control="ESCAPE"}
|
input_action{name="quit", control="SPACE"}
|
||||||
|
|
||||||
input_action{name = "left", control = "A"}
|
input_action{name = "left", control = "A"}
|
||||||
input_action{name = "right", control = "D"}
|
input_action{name = "right", control = "D"}
|
||||||
input_action{name = "forward", control = "W"}
|
input_action{name = "forward", control = "W"}
|
||||||
input_action{name = "back", control = "S"}
|
input_action{name = "back", control = "S"}
|
||||||
|
|
||||||
if input_action_just_pressed{name = "toggle_mouse"} then
|
if input_action_just_pressed{name = "quit"} then
|
||||||
if not capture then
|
if not capture then
|
||||||
capture = true
|
capture = true
|
||||||
else
|
else
|
||||||
capture = false
|
capture = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local dir = Vector3(draw_camera_from_principal_axes{position = pos, yaw = rot}.direction)
|
||||||
local dir = Vector3(draw_camera_from_principal_axes{position = position, yaw = head_rotation}.direction)
|
|
||||||
dir.y = 0
|
dir.y = 0
|
||||||
dir = dir:normalized()
|
dir = dir:normalized()
|
||||||
|
|
||||||
if not capture then
|
local rot_d = b2n(input_action_pressed{name = "right"}) - b2n(input_action_pressed{name = "left"})
|
||||||
local rot_d = b2n(input_action_pressed{name = "right"}) - b2n(input_action_pressed{name = "left"})
|
rot = rot + rot_d * rot_spd
|
||||||
head_rotation = head_rotation + rot_d * rotate_speed
|
|
||||||
else
|
|
||||||
head_rotation = head_rotation + mouse_sensitivity * ctx.mouse_movement.x
|
|
||||||
end
|
|
||||||
|
|
||||||
local mov_d = b2n(input_action_pressed{name = "forward"}) - b2n(input_action_pressed{name = "back"})
|
local mov_d = b2n(input_action_pressed{name = "forward"}) - b2n(input_action_pressed{name = "back"})
|
||||||
velocity = dir * spd * mov_d
|
-- pos = trig.v3_add(pos, trig.v3_mult(dir, spd * mov_d))
|
||||||
|
pos = pos + dir * spd * mov_d
|
||||||
position = position + velocity
|
|
||||||
|
|
||||||
draw_billboard{position = Vector3(5, 0, 0), size = Vector2(1, 1), texture = "images/duck.png"}
|
draw_billboard{position = Vector3(5, 0, 0), size = Vector2(1, 1), texture = "images/duck.png"}
|
||||||
|
|
||||||
draw_text{position = Vector2(0), string = "vel: " .. tostring(velocity), font = FONT}
|
|
||||||
end
|
end
|
||||||
|
@ -129,10 +129,6 @@ function Vector3:length_squared()
|
|||||||
return x2 + y2 + z2
|
return x2 + y2 + z2
|
||||||
end
|
end
|
||||||
|
|
||||||
function Vector3:length()
|
|
||||||
return math.sqrt(self:length_squared())
|
|
||||||
end
|
|
||||||
|
|
||||||
function Vector3:normalized()
|
function Vector3:normalized()
|
||||||
local length = math.sqrt(self:length_squared())
|
local length = math.sqrt(self:length_squared())
|
||||||
return Vector3(self.x / length, self.y / length, self.z / length)
|
return Vector3(self.x / length, self.y / length, self.z / length)
|
||||||
|
Reference in New Issue
Block a user