diff options
| author | jussi | 2023-04-06 12:31:37 +0300 |
|---|---|---|
| committer | jussi | 2023-04-06 12:31:37 +0300 |
| commit | 2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a (patch) | |
| tree | 825775577403d9341045571adb266173513c4bbd /examples/point_triangle_collision/main.lua | |
| parent | 198a74c0aa27389c062c47bc29187c58a9d6c4a1 (diff) | |
| download | reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.tar.gz reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.tar.bz2 reilua-enhanced-2526c9732e7ea35bc9ed3e43a4db77b7e6364c5a.zip | |
All global variables and functions are not in global RL table. doc_parser creates also ReiLua_API.lua.
Diffstat (limited to 'examples/point_triangle_collision/main.lua')
| -rw-r--r-- | examples/point_triangle_collision/main.lua | 85 |
1 files changed, 41 insertions, 44 deletions
diff --git a/examples/point_triangle_collision/main.lua b/examples/point_triangle_collision/main.lua index 3c16e5e..a855dd8 100644 --- a/examples/point_triangle_collision/main.lua +++ b/examples/point_triangle_collision/main.lua @@ -1,4 +1,4 @@ -package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" util = require "utillib" Vec2 = require "vector2" @@ -8,7 +8,6 @@ local MOVE_SPEED = 0.5 local monitor = 0 local camera = -1 -local texture = -1 local tri = { a = Vec3:new( 0, 0, 0 ), -- a = Vec3:new( 0, 1, 0 ), @@ -26,27 +25,25 @@ local point = { local debugText = "" local function calcNormal( tri ) - tri.normal = Vec3:new( RL_Vector3Normalize( RL_Vector3CrossProduct( tri.b - tri.a, tri.c - tri.a ) ) ) + tri.normal = Vec3:new( RL.Vector3Normalize( RL.Vector3CrossProduct( tri.b - tri.a, tri.c - tri.a ) ) ) end -function init() - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) +function RL.init() + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) local winSize = { 1920, 1080 } - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - RL_SetWindowSize( winSize ) - camera = RL_CreateCamera3D() - RL_SetCamera3DPosition( camera, { 0, 1, 2 } ) - RL_SetCamera3DTarget( camera, { 0, 0, 0 } ) - RL_SetCamera3DUp( camera, { 0, 1, 0 } ) - RL_SetCameraMode( camera, CAMERA_FREE ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + RL.SetWindowSize( winSize ) + camera = RL.CreateCamera3D() + RL.SetCamera3DPosition( camera, { 0, 1, 2 } ) + RL.SetCamera3DTarget( camera, { 0, 0, 0 } ) + RL.SetCamera3DUp( camera, { 0, 1, 0 } ) + RL.SetCameraMode( camera, RL.CAMERA_FREE ) calcNormal( tri ) - - texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tile.png" ) end local function checkCollisionPointTriangle( p, a, b, c, n ) @@ -78,48 +75,48 @@ local function checkCollisionPointTriangle( p, a, b, c, n ) return 0.0 < result.x and 0.0 < result.y and 0.0 < result.z and distance < 0.0, distance end -function process( delta ) +function RL.process( delta ) debugText = "" - if RL_IsKeyDown( string.byte( "D" ) ) then + if RL.IsKeyDown( string.byte( "D" ) ) then point.pos.x = point.pos.x + MOVE_SPEED * delta - elseif RL_IsKeyDown( string.byte( "A" ) ) then + elseif RL.IsKeyDown( string.byte( "A" ) ) then point.pos.x = point.pos.x - MOVE_SPEED * delta end - if RL_IsKeyDown( string.byte( "S" ) ) then + if RL.IsKeyDown( string.byte( "S" ) ) then point.pos.z = point.pos.z + MOVE_SPEED * delta - elseif RL_IsKeyDown( string.byte( "W" ) ) then + elseif RL.IsKeyDown( string.byte( "W" ) ) then point.pos.z = point.pos.z - MOVE_SPEED * delta end - if RL_IsKeyDown( string.byte( "R" ) ) then + if RL.IsKeyDown( string.byte( "R" ) ) then point.pos.y = point.pos.y + MOVE_SPEED * delta - elseif RL_IsKeyDown( string.byte( "F" ) ) then + elseif RL.IsKeyDown( string.byte( "F" ) ) then point.pos.y = point.pos.y - MOVE_SPEED * delta end if checkCollisionPointTriangle( point.pos, tri.a, tri.b, tri.c, tri.normal ) then - point.color = RED + point.color = RL.RED else - point.color = GREEN + point.color = RL.GREEN end end -function draw() - RL_ClearBackground( { 100, 150, 100 } ) - RL_UpdateCamera3D( camera ) - - RL_BeginMode3D( camera ) - RL_DrawGrid( 8, 1 ) - RL_DrawTriangle3D( tri.a, tri.b, tri.c, { 200, 100, 100 } ) - - RL_DrawLine3D( { point.pos.x - point.lineLen, point.pos.y, point.pos.z }, - { point.pos.x + point.lineLen, point.pos.y, point.pos.z }, BLUE ) - RL_DrawLine3D( { point.pos.x, point.pos.y - point.lineLen, point.pos.z }, - { point.pos.x, point.pos.y + point.lineLen, point.pos.z }, BLUE ) - RL_DrawLine3D( { point.pos.x, point.pos.y, point.pos.z - point.lineLen }, - { point.pos.x, point.pos.y, point.pos.z + point.lineLen }, BLUE ) - RL_DrawSphereWires( point.pos, point.radius, 3, 8, point.color ) - RL_EndMode3D() - - RL_DrawText( 0, debugText, { 10, 10 }, 30, 4, WHITE ) +function RL.draw() + RL.ClearBackground( { 100, 150, 100 } ) + RL.UpdateCamera3D( camera ) + + RL.BeginMode3D( camera ) + RL.DrawGrid( 8, 1 ) + RL.DrawTriangle3D( tri.a, tri.b, tri.c, { 200, 100, 100 } ) + + RL.DrawLine3D( { point.pos.x - point.lineLen, point.pos.y, point.pos.z }, + { point.pos.x + point.lineLen, point.pos.y, point.pos.z }, RL.BLUE ) + RL.DrawLine3D( { point.pos.x, point.pos.y - point.lineLen, point.pos.z }, + { point.pos.x, point.pos.y + point.lineLen, point.pos.z }, RL.BLUE ) + RL.DrawLine3D( { point.pos.x, point.pos.y, point.pos.z - point.lineLen }, + { point.pos.x, point.pos.y, point.pos.z + point.lineLen }, RL.BLUE ) + RL.DrawSphereWires( point.pos, point.radius, 3, 8, point.color ) + RL.EndMode3D() + + RL.DrawText( 0, debugText, { 10, 10 }, 30, 4, RL.WHITE ) end |
