Initial late commit
This commit is contained in:
53
application/assets/scripts/camera.lua
Normal file
53
application/assets/scripts/camera.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
local velocity = 5
|
||||
|
||||
function HandleMouse(camera, delta_time)
|
||||
local mouse_sensitivity = 0.2
|
||||
local xoffset, yoffset = Input:GetMouseOffset()
|
||||
|
||||
xoffset = xoffset * mouse_sensitivity;
|
||||
yoffset = yoffset * mouse_sensitivity;
|
||||
|
||||
local pitch, yaw = camera:GetPitchYaw()
|
||||
yaw = yaw + xoffset;
|
||||
pitch = pitch + yoffset;
|
||||
|
||||
if pitch > 89.0 then
|
||||
pitch = 89.0;
|
||||
if pitch < -89.0 then
|
||||
pitch = -89.0;
|
||||
end
|
||||
end
|
||||
|
||||
camera:SetPitchYaw(pitch, yaw)
|
||||
|
||||
end
|
||||
|
||||
function Update()
|
||||
local delta_time = Time:DeltaTime();
|
||||
--local inp = Input:GetKeyStatus(GLFW_KEY_W)
|
||||
local transform = Parent:GetTransform()
|
||||
local camera = Parent:GetCamera()
|
||||
local forward = camera:forward()
|
||||
local right = camera:right()
|
||||
local translation
|
||||
|
||||
HandleMouse(camera, delta_time)
|
||||
|
||||
if Input:GetKeyStatus(GLFW_KEY_W) == 1 then
|
||||
translation = normalize(forward * vec3:new(1.0, 0.0, 1.0)) * velocity * delta_time
|
||||
end
|
||||
|
||||
if Input:GetKeyStatus(GLFW_KEY_S) == 1 then
|
||||
translation = normalize(forward * vec3:new(1.0, 0.0, 1.0)) * -velocity * delta_time
|
||||
end
|
||||
|
||||
if Input:GetKeyStatus(GLFW_KEY_A) == 1 then
|
||||
translation = normalize(right * vec3:new(1.0, 0.0, 1.0)) * -velocity * delta_time
|
||||
end
|
||||
|
||||
if Input:GetKeyStatus(GLFW_KEY_D) == 1 then
|
||||
translation = normalize(right * vec3:new(1.0, 0.0, 1.0)) * velocity * delta_time
|
||||
end
|
||||
|
||||
transform:Translate(translation)
|
||||
end
|
||||
28
application/assets/scripts/script.lua
Normal file
28
application/assets/scripts/script.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
io.write("script loaded successfully\n")
|
||||
|
||||
local time_elapsed = 0
|
||||
|
||||
function Start(trans)
|
||||
io.write("lua: Start\n")
|
||||
end
|
||||
|
||||
function Update()
|
||||
time_elapsed = time_elapsed + Time:DeltaTime()
|
||||
local x = math.sin(time_elapsed * 2) * 2
|
||||
local z = math.cos(time_elapsed * 2) * 2
|
||||
|
||||
local transform = Parent:GetTransform()
|
||||
transform.position = vec3:new(x, 1.0, z - 7.0)
|
||||
local light = Parent:GetPointLight()
|
||||
|
||||
local r = 0.5 * (1 + math.sin(time_elapsed * 2.5) * 1.1)
|
||||
local g = 0.5 * (1 + math.cos(time_elapsed * 1.5) * 1.2)
|
||||
local b = 0.5 * (1 + math.sin(time_elapsed * 3.5) * 1.3)
|
||||
r = 1.0
|
||||
g = 1.0
|
||||
b = 1.0
|
||||
light.color = vec3:new(r, g, b)
|
||||
end
|
||||
|
||||
-- Todo: faire bouger le cube
|
||||
-- Get inputs to script
|
||||
Reference in New Issue
Block a user