summaryrefslogtreecommitdiffhomepage
path: root/examples/core_3d_camera_first_person.lua
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2016-08-06 11:32:35 +0200
committerraysan5 <[email protected]>2016-08-06 11:32:35 +0200
commit00c7e54d3c593dbddb036f2185e614e7e4b22a1f (patch)
tree3ef6a46031712ff9551c2711adcc9fa3045a618b /examples/core_3d_camera_first_person.lua
parent5f1b4e94745303ab9df87421cdd9ffb9448fee01 (diff)
downloadraylib-00c7e54d3c593dbddb036f2185e614e7e4b22a1f.tar.gz
raylib-00c7e54d3c593dbddb036f2185e614e7e4b22a1f.zip
Add raylib lua examples
Diffstat (limited to 'examples/core_3d_camera_first_person.lua')
-rw-r--r--examples/core_3d_camera_first_person.lua85
1 files changed, 85 insertions, 0 deletions
diff --git a/examples/core_3d_camera_first_person.lua b/examples/core_3d_camera_first_person.lua
new file mode 100644
index 00000000..800c3c2a
--- /dev/null
+++ b/examples/core_3d_camera_first_person.lua
@@ -0,0 +1,85 @@
+--------------------------------------------------------------------------------------------
+--
+-- raylib [core] example - 3d camera first person
+--
+-- This example has been created using raylib 1.6 (www.raylib.com)
+-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+--
+-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
+--
+--------------------------------------------------------------------------------------------
+
+MAX_COLUMNS = 20
+
+-- Initialization
+-------------------------------------------------------------------------------------------
+local screenWidth = 800
+local screenHeight = 450
+
+InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person")
+
+-- Define the camera to look into our 3d world (position, target, up vector)
+local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 60.0)
+
+-- Generates some random columns
+local heights = {}
+local positions = {}
+local colors = {}
+
+for i = 1, MAX_COLUMNS do
+ heights[i] = GetRandomValue(1, 12)
+ positions[i] = Vector3(GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15))
+ colors[i] = Color(GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255)
+end
+
+local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position
+
+SetCameraMode(CameraMode.FIRST_PERSON) -- Set a first person camera mode
+SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
+
+SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
+-------------------------------------------------------------------------------------------
+
+-- Main game loop
+while not WindowShouldClose() do -- Detect window close button or ESC key
+ -- Update
+ ---------------------------------------------------------------------------------------
+ camera, playerPosition = UpdateCameraPlayer(camera, playerPosition) -- Update camera and player position
+ ---------------------------------------------------------------------------------------
+
+ -- Draw
+ ---------------------------------------------------------------------------------------
+ BeginDrawing()
+
+ ClearBackground(RAYWHITE)
+
+ Begin3dMode(camera)
+
+ DrawPlane(Vector3(0.0, 0.0, 0.0), Vector2(32.0, 32.0), LIGHTGRAY) -- Draw ground
+ DrawCube(Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, BLUE) -- Draw a blue wall
+ DrawCube(Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, LIME) -- Draw a green wall
+ DrawCube(Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, GOLD) -- Draw a yellow wall
+
+ -- Draw some cubes around
+ for i = 1, MAX_COLUMNS do
+ DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i])
+ DrawCubeWires(positions[i], 2.0, heights[i], 2.0, MAROON)
+ end
+
+ End3dMode()
+
+ DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5))
+ DrawRectangleLines( 10, 10, 220, 70, BLUE)
+
+ DrawText("First person camera default controls:", 20, 20, 10, BLACK)
+ DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY)
+ DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY)
+
+ EndDrawing()
+ ---------------------------------------------------------------------------------------
+end
+
+-- De-Initialization
+-------------------------------------------------------------------------------------------
+CloseWindow() -- Close window and OpenGL context
+------------------------------------------------------------------------------------------- \ No newline at end of file