Löve 3D
Löve3D engine (forked from g3d) simplifies LÖVE's 2D capabilities for 3D games to be as simple to use as possible. We recommend to use Blender (open source software ) to build the 3D models for using inside Löve3D games.
Löve3D has full interoperability with Löve2D source code. You can add pieces of code from Löve2D into Löve3D with no working problems.
Camera movimentation keys: W,A,S,D, Left Shift, Left Control, Space bar and ESC to quit.
Free Lua courses on YouTube
- Steve's teacher
- PohkaDev
- DerekBanas
- Alfred Baudisch / Pardali (Brazilian Portuguese)
- Glider (Brazilian Portuguese)
Free Löve2D courses on YouTube
DownloadBasic Löve3D program
These are the basics, see more about gamestates and conf.lua file.
You can also see the Löve2D's keycodes table.
love3d = require 'love3d'
function love3d.load()
...
end
function love3d.mousemoved(x,y, dx,dy)
...
end
function love3d.update(dt)
...
end
function love3d.draw()
...
end
Getting current screen dimensions
It returns current display/screen dimensions: width (x) and height (y).
local screen_width = love3d.display.width
local screen_height = love3d.display.height
Creating a Timer
It creates a timer passsing dt
argument from love3d.update(dt)
as average speed in physics: V = Δs/Δt
local MyTimer = 0
MyTimer = love3d.engine.newTimer(MyTimer,dt)
Example
love3d = require 'love3d'
local MyTimer = 0
function love3d.load()
...
end
function love3d.mousemoved(x,y, dx,dy)
...
end
function love3d.update(dt)
...
MyTimer = love3d.engine.newTimer(MyTimer,dt)
end
function love3d.draw()
...
end
Creating Entities
Create new entity (object) in the world, it should be modeled in an external software, such as, Blender.
-
BlenderFile
parameter represents the Blender generated object file (.obj) -
PngFile
parameter represents the texture of the Blender generated file (.png) -
WorldCoordinates
parameter represents the location of the entity in the world:{x,y,z}
-
EntityScale
parameter represents the size of the entity at axes:{x,y,z}
default is{1,1,1}
local moon = love3d.newModel(BlenderFile, PngFile, WorldCoordinates, Rotation, EntityScale)
moon:draw()
Example I
local moon = love3d.newModel("assets/sphere.obj", "assets/moon.png", {5,0,4}, nil, {1,1,1})
moon:draw()
Example II
love3d = require 'love3d'
local MyTimer = 0
local moon = love3d.newModel("assets/sphere.obj", "assets/moon.png", {5,0,4}, nil, {1,1,1})
function love3d.load()
end
function love3d.mousemoved(x,y, dx,dy)
end
function love3d.update(dt)
MyTimer = love3d.engine.newTimer(MyTimer,dt)
...
end
function love3d.draw()
moon:draw()
end
Set entity translation
Set created entity translation in the world
moon:setTranslation(x,y,z)
Set entity rotation
Set entity's rotation at its own axis (using Euler angles)
moon:setEulerRotation(x,y,z)
Set entity's rotation at its own axis (using degrees)
moon:setDegreeRotation(x,y,z)
Set entity's rotation at its own axis (using Quartenions)
moon:setQuaternionRotation(x,y,z,w)
Set entity scale in the world
This is the size of the modeled object in the world at axes: {x,y,z}
moon:setScale(x,y,z)
Set entity upside down in the world
Set the modeled object upside down or not in the world: true
(upside down) or false
(normal).
moon:upsideDown(isUpsideDown)
Examples:
moon:upsideDown(true)
moon:upsideDown(false)
Set entities collision field
Detect camera collision into an entity or the entity's collision into another entity, using a 3D implementation of AABB formula.
Parameters (they can be numbers or variables):
-
length
means the radius of collision field/box. -
x,y,z
mean the coordinates of the target collision entity. -
x1,y1,z1
mean the coordinates of the first entity. -
x2,y2,z2
mean the coordinates of the second entity.
-
Detect if the camera collided into entity, it returns: true
(inside collision field) or false
(outside collision field).
love3d.collisions.hasCameraCollided(length, x,y,z)
love3d.collisions.hasCameraCollided(6, 10,0,10)
-
Detect if one entity collided into another entity, it returns: true
(inside collision field) or false
(outside collision field).
love3d.collisions.hasEntityCollided(length, x1,y1,z1, x2,y2,z2)
love3d.collisions.hasEntityCollided(6, 10,0,10, 30,4,20)
Detect if the camera collided into entity, it returns: true
(inside collision field) or false
(outside collision field).
love3d.collisions.hasCameraCollided(length, x,y,z)
love3d.collisions.hasCameraCollided(6, 10,0,10)
Detect if one entity collided into another entity, it returns: true
(inside collision field) or false
(outside collision field).
love3d.collisions.hasEntityCollided(length, x1,y1,z1, x2,y2,z2)
love3d.collisions.hasEntityCollided(6, 10,0,10, 30,4,20)
Inspect tables
Returns the inspected table name.
local MyTable = {0,5,0}
local inspected_table = love3d.inspect.table(MyTable)
1. You can print the inspected table on the console.
print(inspected_table)
2. Or you can also display on the game screen.
love.graphics.print(inspected_table,10,20)
Spectator Camera
1. Get camera position in the world, returns a three value table
local camera_position = love3d.camera.position
-
Get camera X axis in the world, returns a number
local camera_x = love3d.world.getCameraX()
-
Get camera Y axis in the world, returns a number
local camera_y = love3d.world.getCameraY()
-
Get camera Z axis in the world, returns a number
local camera_z = love3d.world.getCameraZ()
2. The point where your camera is looking in the world, returns a three value table.
local looking_world = love3d.camera.target
-
Get where your camera is looking at X axis in the world, returns a number
local looking_x = love3d.world.getLookingX()
-
Get where your camera is looking at Y axis in the world, returns a number
local looking_y = love3d.world.getLookingY()
-
Get where your camera is looking at Z axis in the world, returns a number
local looking_z = love3d.world.getLookingZ()
3. Which way up is, returns a three value table, this is used for matrix math calculations.
local looking_up = love3d.camera.up
-
Get which way up is at X axis in the world, returns a number
local looking_up_x = love3d.world.getLookingUpX()
-
Get which way up is at Y axis in the world, returns a number
local looking_up_y = love3d.world.getLookingUpY()
-
Get which way up is at Z axis in the world, returns a number
local looking_up_z = love3d.world.getLookingUpZ()
Sets the camera at a position, looking towards the target point.
-
The
x
position of the camera. -
The
y
position of the camera. -
The
z
position of the camera.
The x coordinate of the position where the camera look:
xAt
The y coordinate of the position where the camera look:
yAt
The z coordinate of the position where the camera look:
zAt
love3d.camera.lookAt(x, y, z, xAt, yAt, zAt)
Example
Setting the camera coordinates to:
x=10, y=0, z=10And camera looking at coordinates to:
x=10, y=0, z=10
love3d.camera.lookAt(10,0,40, 10,0,40)
Licensed under BSD 2-clause license
Forked from g3d by Gabriel Margarido