summaryrefslogtreecommitdiff
path: root/examples/ray
diff options
context:
space:
mode:
authorjussi2022-02-18 18:27:10 +0200
committerjussi2022-02-18 18:27:10 +0200
commit6e4fdd3b3ae4e4656e151f098c40cfe551a36e8c (patch)
tree37e30d371ebd44dfc8bab0d33c26f0294bda5ae4 /examples/ray
parent345cc1d5aa3b3c97e2cce453dc65a62c3e05427b (diff)
downloadreilua-enhanced-6e4fdd3b3ae4e4656e151f098c40cfe551a36e8c.tar.gz
reilua-enhanced-6e4fdd3b3ae4e4656e151f098c40cfe551a36e8c.tar.bz2
reilua-enhanced-6e4fdd3b3ae4e4656e151f098c40cfe551a36e8c.zip
Added initial files.
Diffstat (limited to 'examples/ray')
-rw-r--r--examples/ray/main.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/ray/main.lua b/examples/ray/main.lua
new file mode 100644
index 0000000..f0f5c2f
--- /dev/null
+++ b/examples/ray/main.lua
@@ -0,0 +1,47 @@
+local camera = -1
+local sphereMesh = -1
+local ray = { { 0.5, 0, 4 }, { 0.1, 0, -1 } }
+
+local function setupWindow()
+ local monitor = 0
+ local mPos = RL_GetMonitorPosition( monitor )
+ local mSize = RL_GetMonitorSize( monitor )
+ local winSize = RL_GetWindowSize()
+
+ RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
+ RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
+end
+
+function init()
+ setupWindow()
+
+ camera = RL_CreateCamera3D()
+ RL_SetCamera3DPosition( camera, { 0, 2, 4 } )
+ RL_SetCamera3DTarget( camera, { 0, 0, 0 } )
+ RL_SetCamera3DUp( camera, { 0, 2, 0 } )
+ RL_SetCamera3DMode( camera, CAMERA_FREE )
+
+ sphereMesh = RL_GenMeshSphere( 1.0, 8, 10 )
+
+ -- local rayCol = RL_GetRayCollisionSphere( { { 0.5, 0, 4 }, { 0, 0, -1 } }, { 0, 0, 0 }, 1.0 )
+ local rayCol = RL_GetRayCollisionMesh( ray, sphereMesh, RL_MatrixIdentity() )
+
+ if rayCol ~= nil and rayCol.hit then
+ print( "hit", rayCol.hit )
+ print( "distance", rayCol.distance )
+ print( "point", rayCol.point[1], rayCol.point[2], rayCol.point[3] )
+ print( "normal", rayCol.normal[1], rayCol.normal[2], rayCol.normal[3] )
+ end
+end
+
+function draw()
+ RL_ClearBackground( { 100, 150, 100 } )
+ RL_UpdateCamera3D( camera )
+
+ RL_BeginMode3D( camera )
+ RL_DrawGrid( 8, 1 )
+ RL_DrawRay( ray, { 255, 100, 100 } )
+
+ RL_DrawMesh( sphereMesh, 0, RL_MatrixIdentity() )
+ RL_EndMode3D()
+end