Updated examples to ReiLua 0.9.0.

This commit is contained in:
jussi
2024-11-21 18:02:06 +02:00
parent 3d5eeac3d7
commit d96e33bb17
5 changed files with 35 additions and 20 deletions

View File

@@ -40,7 +40,7 @@ end
function RL.update( delta ) function RL.update( delta )
if RL.IsMouseButtonPressed( 0 ) then if RL.IsMouseButtonPressed( 0 ) then
ray = RL.GetMouseRay( RL.GetMousePosition(), camera ) ray = RL.GetScreenToWorldRay( RL.GetMousePosition(), camera )
ray_collision() ray_collision()
end end
end end

View File

@@ -61,7 +61,7 @@ function RL.update( delta )
-- Raycast. -- Raycast.
if not guiMouseHover and RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then if not guiMouseHover and RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then
ray = RL.GetMouseRay( RL.GetMousePosition(), camera.camera ) ray = RL.GetScreenToWorldRay( RL.GetMousePosition(), camera.camera )
rayCol = box:getRayCollisionMAS( ray ) rayCol = box:getRayCollisionMAS( ray )
cells, exitPoint = RL.GetRayBoxCells( ray, box:maxToPos(), cellSize ) cells, exitPoint = RL.GetRayBoxCells( ray, box:maxToPos(), cellSize )

View File

@@ -92,8 +92,6 @@ function Camera3D:getUpward()
end end
function Camera3D:update( delta ) function Camera3D:update( delta )
delta = 1 / 60 -- Hack for framerate independance.
if self.mode == self.MODES.FREE then if self.mode == self.MODES.FREE then
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then
local mouseDelta = Vector2:newT( RL.GetMouseDelta() ) local mouseDelta = Vector2:newT( RL.GetMouseDelta() )
@@ -109,7 +107,7 @@ function Camera3D:update( delta )
mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta ) mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta )
RL.Camera3DYaw( self.camera, -mouseDelta.x, true ) RL.Camera3DYaw( self.camera, -mouseDelta.x, true )
RL.Camera3DPitch( self.camera, -mouseDelta.y, false, true, false ) RL.Camera3DPitch( self.camera, -mouseDelta.y, true, true, false )
end end
end end
@@ -124,7 +122,7 @@ function Camera3D:update( delta )
mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta ) mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta )
RL.Camera3DYaw( self.camera, -mouseDelta.x, false ) RL.Camera3DYaw( self.camera, -mouseDelta.x, false )
RL.Camera3DPitch( self.camera, -mouseDelta.y, false, false, false ) RL.Camera3DPitch( self.camera, -mouseDelta.y, true, false, false )
RL.SetMousePosition( Vector2:newT( RL.GetScreenSize() ):scale( 0.5 ) ) RL.SetMousePosition( Vector2:newT( RL.GetScreenSize() ):scale( 0.5 ) )
local distance = self.KEYBOARD_MOVE_SPEED * delta local distance = self.KEYBOARD_MOVE_SPEED * delta

View File

@@ -147,14 +147,6 @@ function utillib.printt( t )
print( "}" ) print( "}" )
end end
function utillib.colorLerp( a, b, f )
return {
utillib.round( utillib.lerp( a[1], b[1], f ) ),
utillib.round( utillib.lerp( a[2], b[2], f ) ),
utillib.round( utillib.lerp( a[3], b[3], f ) )
}
end
-- Move secuence of elements inside table. -- Move secuence of elements inside table.
function utillib.tableMove( t, src, len, dest ) function utillib.tableMove( t, src, len, dest )
local copy = table.move( t, src, src + len - 1, 1, {} ) local copy = table.move( t, src, src + len - 1, 1, {} )
@@ -168,6 +160,12 @@ function utillib.tableMove( t, src, len, dest )
table.move( copy, 1, len, dest, t ) table.move( copy, 1, len, dest, t )
end end
function utillib.reverseTable( t )
for i = 1, math.floor( #t / 2 ), 1 do
t[i], t[ #t - i + 1 ] = t[ #t - i + 1 ], t[i]
end
end
function utillib.randomFloat( min, max ) function utillib.randomFloat( min, max )
return min + math.random() * ( max - min ); return min + math.random() * ( max - min );
end end
@@ -183,4 +181,24 @@ function utillib.printBin( v )
print() print()
end end
function utillib.capitalize( str )
return string.format( "%s%s", str:sub( 1, 1 ):upper(), str:sub( 2, -1 ) )
end
function utillib.doString( str )
local func, err = load( str )
if func then
local success, result = pcall( func )
if success then
return result
else
RL.TraceLog( RL.LOG_WARNING, "Execution error: "..result )
end
else
RL.TraceLog( RL.LOG_WARNING, "Compilation error: "..err )
end
end
return utillib return utillib

View File

@@ -7,7 +7,6 @@ local res = Vector2:new( 1024, 720 )
local winScale = 1 local winScale = 1
local winSize = res:scale( winScale ) local winSize = res:scale( winScale )
local monitor = 0 local monitor = 0
local null = RL.LoadBuffer( {}, RL.BUFFER_UNSIGNED_CHAR );
local triangle = { local triangle = {
texture = { texture = {
@@ -97,7 +96,7 @@ local function createTriangle()
RL.BUFFER_FLOAT RL.BUFFER_FLOAT
) )
triangle.vbos.positions = RL.rlLoadVertexBuffer( vertexBuffer, false ) triangle.vbos.positions = RL.rlLoadVertexBuffer( vertexBuffer, false )
RL.rlSetVertexAttribute( 0, 3, RL.RL_FLOAT, false, 0, null ) RL.rlSetVertexAttribute( 0, 3, RL.RL_FLOAT, false, 0, 0 )
RL.rlEnableVertexAttribute( 0 ) RL.rlEnableVertexAttribute( 0 )
-- Colors. -- Colors.
@@ -110,7 +109,7 @@ local function createTriangle()
RL.BUFFER_FLOAT RL.BUFFER_FLOAT
) )
triangle.vbos.colors = RL.rlLoadVertexBuffer( colors, false ) triangle.vbos.colors = RL.rlLoadVertexBuffer( colors, false )
RL.rlSetVertexAttribute( 1, 4, RL.RL_FLOAT, false, 0, null ) RL.rlSetVertexAttribute( 1, 4, RL.RL_FLOAT, false, 0, 0 )
RL.rlEnableVertexAttribute( 1 ) RL.rlEnableVertexAttribute( 1 )
-- Texcoords. -- Texcoords.
@@ -123,7 +122,7 @@ local function createTriangle()
RL.BUFFER_FLOAT RL.BUFFER_FLOAT
) )
triangle.vbos.texcoors = RL.rlLoadVertexBuffer( texcoors, false ) triangle.vbos.texcoors = RL.rlLoadVertexBuffer( texcoors, false )
RL.rlSetVertexAttribute( 2, 2, RL.RL_FLOAT, false, 0, null ) RL.rlSetVertexAttribute( 2, 2, RL.RL_FLOAT, false, 0, 0 )
RL.rlEnableVertexAttribute( 2 ) RL.rlEnableVertexAttribute( 2 )
-- Disable. -- Disable.