Add examples;

This commit is contained in:
bjorn 2016-12-05 01:16:24 -08:00
parent a3d25e472a
commit fd204c3edc
3 changed files with 65 additions and 0 deletions

20
examples/bounds/main.lua Normal file
View 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

View 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
View 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