summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2019-04-23 23:28:11 +0200
committerRay <[email protected]>2019-04-23 23:28:11 +0200
commit600cdb61a306cd1d5dd78679c0acceb91287b193 (patch)
tree012e6074f450d7e048690bf37c734c65b582fc82
parentcc1dd6b410ca8c6ba2b9dd1a923c7740034cd1d9 (diff)
downloadraylib-600cdb61a306cd1d5dd78679c0acceb91287b193.tar.gz
raylib-600cdb61a306cd1d5dd78679c0acceb91287b193.zip
new example: models_first_person_maze -WIP-
-rw-r--r--examples/models/models_first_person_maze.c84
-rw-r--r--examples/models/models_first_person_maze.pngbin0 -> 327996 bytes
2 files changed, 84 insertions, 0 deletions
diff --git a/examples/models/models_first_person_maze.c b/examples/models/models_first_person_maze.c
new file mode 100644
index 00000000..4342b178
--- /dev/null
+++ b/examples/models/models_first_person_maze.c
@@ -0,0 +1,84 @@
+/*******************************************************************************************
+*
+* raylib [models] example - first person maze
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - first person maze");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 0.2f, 0.4f, 0.2f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
+
+ Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
+ Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
+ Mesh mesh = GenMeshCubicmap(image, (Vector3){ 1.0f, 1.0f, 1.0f });
+ Model model = LoadModelFromMesh(mesh);
+ UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
+
+ // NOTE: By default each cube is mapped to one part of texture atlas
+ Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
+
+ Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
+ Vector3 playerPosition = camera.position; // Set player position
+
+ SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set camera mode
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ UpdateCamera(&camera); // Update camera
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ DrawModel(model, mapPosition, 1.0f, WHITE); // Draw maze map
+ //DrawCubeV(playerPosition, (Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player
+
+ EndMode3D();
+
+ DrawTextureEx(cubicmap, (Vector2){ GetScreenWidth() - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
+ DrawRectangleLines(GetScreenWidth() - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(cubicmap); // Unload cubicmap texture
+ UnloadTexture(texture); // Unload map texture
+ UnloadModel(model); // Unload map model
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/models/models_first_person_maze.png b/examples/models/models_first_person_maze.png
new file mode 100644
index 00000000..ed6047e1
--- /dev/null
+++ b/examples/models/models_first_person_maze.png
Binary files differ