2021-04-21 18:27:30 -05:00
|
|
|
package.path = package.path .. ";../scripts/?.lua"
|
|
|
|
local freecam = require("freecam")
|
|
|
|
local Vector3 = couch.Vector3
|
|
|
|
|
|
|
|
function init()
|
|
|
|
freecam.init_camera()
|
|
|
|
|
|
|
|
local light = couch.DirectionalLight()
|
|
|
|
light:SetDirection(Vector3(1.0, -2.0, -1.0))
|
|
|
|
light:SetColor(Vector3(1.0, 1.0, 1.0))
|
|
|
|
light:SetAmbient(0.2)
|
|
|
|
light:SetDiffuse(1.0)
|
|
|
|
light:SetSpecular(0.1)
|
|
|
|
couch.Node.GetRoot():AddChild(light:Instance())
|
|
|
|
|
2021-05-05 15:23:24 -05:00
|
|
|
local box_mesh = couch.TexturedMesh("../resources/cube.glb", "../resources/paintedwood.jpg")
|
2021-04-21 18:27:30 -05:00
|
|
|
local box = couch.Rigidbody()
|
|
|
|
box:SetCollisionShape(couch.BoxCollisionShape(1, 1, 1))
|
|
|
|
box:AddChild(box_mesh)
|
|
|
|
couch.Node.GetRoot():AddChild(box:Instance())
|
|
|
|
|
|
|
|
local ground = couch.Rigidbody()
|
|
|
|
ground:SetCollisionShape(couch.BoxCollisionShape(100, 0.1, 100))
|
|
|
|
ground:Translate(Vector3(0.0, -1.0, 0.0))
|
|
|
|
ground:SetMass(0.0)
|
|
|
|
couch.Node.GetRoot():AddChild(ground:Instance())
|
|
|
|
end
|
|
|
|
|
|
|
|
function update(delta)
|
|
|
|
freecam.update_camera(delta)
|
|
|
|
end
|
|
|
|
|
|
|
|
function onkey(key, code, action, mod)
|
|
|
|
freecam.onkey(key, code, action, mod)
|
|
|
|
local camera_transform = freecam.camera:GetTransform()
|
|
|
|
if action == couch.ACTION_PRESS and key == couch.KEY_R then
|
|
|
|
local res = couch.World.GetWorld():Raycast(camera_transform.position,
|
|
|
|
camera_transform.position + camera_transform:Forward() * 100.0)
|
|
|
|
if (res.hit) then
|
2021-04-21 21:30:48 -05:00
|
|
|
res.object:ApplyImpulse(camera_transform:Forward() * 100.0)
|
2021-04-21 18:27:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function onmousemotion(_, _, relx, rely)
|
|
|
|
freecam.onmousemotion(relx, rely)
|
|
|
|
end
|
|
|
|
|