Documentation. waving_cubes example and RL_DrawFPS and RL_ColorFromHSV.

This commit is contained in:
jussi
2022-02-21 19:05:05 +02:00
parent 8182a5f1b6
commit 612ede6da4
15 changed files with 184 additions and 71 deletions

View File

@@ -10,7 +10,6 @@ local winScale = 5
local framebuffer = -1
local TILE_SIZE = 32
local COLOR_WHITE = { 255, 255, 255 }
local FLOOR = 1
local CEILING = 2
@@ -61,7 +60,7 @@ function drawSprites()
for _, sprite in ipairs( sprites ) do
RL_DrawBillboardRec( camera, texture, { sprite.tile[1] * TILE_SIZE, sprite.tile[2] * TILE_SIZE, TILE_SIZE, TILE_SIZE },
{ sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, COLOR_WHITE )
{ sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, WHITE )
end
end
@@ -69,9 +68,8 @@ function init()
local monitor = 0
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
-- RL_SetWindowSize( { 1920, 1080 } )
winSize = { res[1] * winScale, res[2] * winScale }
-- winSize = { 1920, 1080 }
RL_SetWindowSize( winSize )
RL_SetExitKey( KEY_ESCAPE )
-- framebuffer = RL_LoadRenderTexture( res )
@@ -85,7 +83,6 @@ function init()
RL_SetCamera3DTarget( camera, { 0, 0, 0 } )
RL_SetCamera3DUp( camera, { 0, 1, 0 } )
RL_SetCamera3DMode( camera, CAMERA_FIRST_PERSON )
-- RL_SetCamera3DMode( camera, CAMERA_ORBITAL )
-- for x = 0, 3 do
-- for y = 0, 9 do
@@ -93,20 +90,10 @@ function init()
-- end
-- end
table.insert( sprites, { pos = { 2.5, 2.5 }, tile = { 1, 1 }, dis = 0, size = 0.8 } )
-- for x = 0, 1 do
-- for y = 0, 1 do
-- table.insert( sprites, { pos = { 1.25 + x * 0.5, 2.25 + y * 0.5 }, tile = { 3, 0 }, dis = 0, size = 0.6 } )
-- end
-- end
table.insert( sprites, { pos = { 1.5, 3.5 }, tile = { 3, 1 }, dis = 0, size = 0.5 } )
table.insert( sprites, { pos = { 0.5, 3.5 }, tile = { 3, 0 }, dis = 0, size = 0.7 } )
end
function process( delta )
-- RL_SetCamera3DPosition( camera, pos )
end
function draw()
RL_UpdateCamera3D( camera )
pos = RL_GetCamera3DPosition( camera )
@@ -119,22 +106,22 @@ function draw()
-- Floor and ceiling.
for x = 0, 3 do
for y = 0, 10 do
RL_DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), WHITE )
end
end
-- Walls.
RL_DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), WHITE )
for x = 0, 3 do
RL_DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), WHITE )
end
for y = 0, 10 do
RL_DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), WHITE )
end
drawSprites()
@@ -142,6 +129,6 @@ function draw()
-- RL_EndTextureMode()
-- RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
-- RL_DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, COLOR_WHITE )
-- RL_DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE )
-- RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE )
end

View File

@@ -0,0 +1,67 @@
--[[
Contributed by Codecat (@codecat)
Reviewed by Ramon Santamaria (@raysan5)
Modified by Teddy Astie (@TSnake41) for Lua binding.
Modified by Jussi Viitala (@nullstare) for ReiLua style.
]]
local winSize = RL_GetWindowSize()
local camera = -1
local num_blocks = 15
function init()
local monitor = 0
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
local winSize = RL_GetWindowSize()
RL_SetWindowTitle( "Waving cubes" )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
camera = RL_CreateCamera3D()
RL_SetCamera3DPosition( camera, { 30, 20, 30 } )
RL_SetCamera3DTarget( camera, { 0, 0, 0 } )
RL_SetCamera3DUp( camera, { 0, 1, 0 } )
end
function draw()
local t = RL_GetTime()
local scale = (2.0 + math.sin(t)) * 0.7
local camera_time = t * 0.3
local camera_pos = RL_GetCamera3DPosition( camera )
camera_pos[1] = math.cos(camera_time) * 40.0
camera_pos[3] = math.sin(camera_time) * 40.0
RL_SetCamera3DPosition( camera, camera_pos )
RL_ClearBackground( RAYWHITE )
RL_BeginMode3D( camera )
RL_DrawGrid( 10, 5.0 )
for x = 0,num_blocks - 1 do
for y = 0,num_blocks - 1 do
for z = 0,num_blocks - 1 do
local block_scale = (x + y + z) / 30
local scatter = math.sin(block_scale * 20.0 + t * 4.0)
local cube_pos = {
(x - num_blocks / 2) * (scale * 3.0) + scatter,
(y - num_blocks / 2) * (scale * 2.0) + scatter,
(z - num_blocks / 2) * (scale * 3.0) + scatter
}
local cube_color = RL_ColorFromHSV( (((x + y + z) * 18) % 360), 0.75, 0.9 )
local cube_size = (2.4 - scale) * block_scale
RL_DrawCube( cube_pos, { cube_size, cube_size, cube_size }, cube_color )
end
end
end
RL_EndMode3D()
RL_DrawFPS( { 10, 10 } )
end

View File

@@ -18,6 +18,6 @@ function process( delta )
end
function draw()
RL_ClearBackground( RAYWHITE );
RL_DrawText( 0, "Congrats! You created your first window!", textPos, 20, 2, textColor );
RL_ClearBackground( RAYWHITE )
RL_DrawText( 0, "Congrats! You created your first window!", textPos, 20, 2, textColor )
end