mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-03 04:53:35 +00:00
Add examples;
This commit is contained in:
parent
a3d25e472a
commit
fd204c3edc
20
examples/bounds/main.lua
Normal file
20
examples/bounds/main.lua
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
-- Draws a rectangle on the floor, coloring it red
|
||||||
|
-- when the player is close to the virtual boundary.
|
||||||
|
|
||||||
|
function lovr.load()
|
||||||
|
if not lovr.headset.isPresent() then
|
||||||
|
error('This example needs a headset')
|
||||||
|
end
|
||||||
|
|
||||||
|
bounds = lovr.graphics.newBuffer(lovr.headset.getBounds())
|
||||||
|
end
|
||||||
|
|
||||||
|
function lovr.draw()
|
||||||
|
if lovr.headset.isBoundsVisible() then
|
||||||
|
lovr.graphics.setColor(255, 0, 0)
|
||||||
|
else
|
||||||
|
lovr.graphics.setColor(255, 255, 255)
|
||||||
|
end
|
||||||
|
|
||||||
|
bounds:draw()
|
||||||
|
end
|
37
examples/controllers/main.lua
Normal file
37
examples/controllers/main.lua
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
-- Vibrates controllers when their triggers are pressed, draws 3D
|
||||||
|
-- models for each controller, and keeps track of controllers when
|
||||||
|
-- they are connected and disconnected.
|
||||||
|
|
||||||
|
local controllerModels = {}
|
||||||
|
|
||||||
|
function lovr.load()
|
||||||
|
print('There are ' .. lovr.headset.getControllerCount() .. ' controllers.')
|
||||||
|
end
|
||||||
|
|
||||||
|
function lovr.update(dt)
|
||||||
|
local controllers = lovr.headset.getControllers()
|
||||||
|
|
||||||
|
for i, controller in ipairs(controllers) do
|
||||||
|
if controller:getAxis('trigger') > .5 then
|
||||||
|
controller:vibrate(.0035)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function lovr.draw()
|
||||||
|
for controller, model in pairs(controllerModels) do
|
||||||
|
local x, y, z = controller:getPosition()
|
||||||
|
local angle, axisX, axisY, axisZ = controller:getOrientation()
|
||||||
|
model:draw(x, y, z, 1, -angle, axisX, axisY, axisZ)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function lovr.controlleradded(controller)
|
||||||
|
print('A controller was connected!')
|
||||||
|
controllerModels[controller] = controller:newModel()
|
||||||
|
end
|
||||||
|
|
||||||
|
function lovr.controllerremoved(controller)
|
||||||
|
print('A controller was disconnected!')
|
||||||
|
controllerModels[controller] = nil
|
||||||
|
end
|
8
examples/cube/main.lua
Normal file
8
examples/cube/main.lua
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
-- Draws a spinning cube
|
||||||
|
|
||||||
|
function lovr.draw()
|
||||||
|
local x, y, z = 0, 0, -1
|
||||||
|
local size = .5
|
||||||
|
local angle = lovr.timer.getTime()
|
||||||
|
lovr.graphics.cube('line', x, y, z, size, angle)
|
||||||
|
end
|
Loading…
Reference in a new issue