aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/src/models')
-rw-r--r--docs/examples/src/models/models_billboard.c70
-rw-r--r--docs/examples/src/models/models_box_collisions.c121
-rw-r--r--docs/examples/src/models/models_cubicmap.c85
-rw-r--r--docs/examples/src/models/models_geometric_shapes.c75
-rw-r--r--docs/examples/src/models/models_heightmap.c80
-rw-r--r--docs/examples/src/models/models_obj_loading.c75
6 files changed, 506 insertions, 0 deletions
diff --git a/docs/examples/src/models/models_billboard.c b/docs/examples/src/models/models_billboard.c
new file mode 100644
index 00000000..bca9faf8
--- /dev/null
+++ b/docs/examples/src/models/models_billboard.c
@@ -0,0 +1,70 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Drawing billboards
+*
+* This example has been created using raylib 1.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+
+ Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
+ Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
+
+ SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital 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);
+
+ Begin3dMode(camera);
+
+ DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
+
+ DrawGrid(10, 1.0f); // Draw a grid
+
+ End3dMode();
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(bill); // Unload texture
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/docs/examples/src/models/models_box_collisions.c b/docs/examples/src/models/models_box_collisions.c
new file mode 100644
index 00000000..69cec418
--- /dev/null
+++ b/docs/examples/src/models/models_box_collisions.c
@@ -0,0 +1,121 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Detect basic 3d collisions (box vs sphere vs box)
+*
+* This example has been created using raylib 1.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+
+ Vector3 playerPosition = { 0.0f, 1.0f, 2.0f };
+ Vector3 playerSize = { 1.0f, 2.0f, 1.0f };
+ Color playerColor = GREEN;
+
+ Vector3 enemyBoxPos = { -4.0f, 1.0f, 0.0f };
+ Vector3 enemyBoxSize = { 2.0f, 2.0f, 2.0f };
+
+ Vector3 enemySpherePos = { 4.0f, 0.0f, 0.0f };
+ float enemySphereSize = 1.5f;
+
+ bool collision = false;
+
+ 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
+ //----------------------------------------------------------------------------------
+
+ // Move player
+ if (IsKeyDown(KEY_RIGHT)) playerPosition.x += 0.2f;
+ else if (IsKeyDown(KEY_LEFT)) playerPosition.x -= 0.2f;
+ else if (IsKeyDown(KEY_DOWN)) playerPosition.z += 0.2f;
+ else if (IsKeyDown(KEY_UP)) playerPosition.z -= 0.2f;
+
+ collision = false;
+
+ // Check collisions player vs enemy-box
+ if (CheckCollisionBoxes(
+ (BoundingBox){(Vector3){ playerPosition.x - playerSize.x/2,
+ playerPosition.y - playerSize.y/2,
+ playerPosition.z - playerSize.z/2 },
+ (Vector3){ playerPosition.x + playerSize.x/2,
+ playerPosition.y + playerSize.y/2,
+ playerPosition.z + playerSize.z/2 }},
+ (BoundingBox){(Vector3){ enemyBoxPos.x - enemyBoxSize.x/2,
+ enemyBoxPos.y - enemyBoxSize.y/2,
+ enemyBoxPos.z - enemyBoxSize.z/2 },
+ (Vector3){ enemyBoxPos.x + enemyBoxSize.x/2,
+ enemyBoxPos.y + enemyBoxSize.y/2,
+ enemyBoxPos.z + enemyBoxSize.z/2 }})) collision = true;
+
+ // Check collisions player vs enemy-sphere
+ if (CheckCollisionBoxSphere(
+ (BoundingBox){(Vector3){ playerPosition.x - playerSize.x/2,
+ playerPosition.y - playerSize.y/2,
+ playerPosition.z - playerSize.z/2 },
+ (Vector3){ playerPosition.x + playerSize.x/2,
+ playerPosition.y + playerSize.y/2,
+ playerPosition.z + playerSize.z/2 }},
+ enemySpherePos, enemySphereSize)) collision = true;
+
+ if (collision) playerColor = RED;
+ else playerColor = GREEN;
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ Begin3dMode(camera);
+
+ // Draw enemy-box
+ DrawCube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY);
+ DrawCubeWires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, DARKGRAY);
+
+ // Draw enemy-sphere
+ DrawSphere(enemySpherePos, enemySphereSize, GRAY);
+ DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, DARKGRAY);
+
+ // Draw player
+ DrawCubeV(playerPosition, playerSize, playerColor);
+
+ DrawGrid(10, 1.0f); // Draw a grid
+
+ End3dMode();
+
+ DrawText("Move player with cursors to collide", 220, 40, 20, GRAY);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/docs/examples/src/models/models_cubicmap.c b/docs/examples/src/models/models_cubicmap.c
new file mode 100644
index 00000000..0e613029
--- /dev/null
+++ b/docs/examples/src/models/models_cubicmap.c
@@ -0,0 +1,85 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Cubicmap loading and drawing
+*
+* This example has been created using raylib 1.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+
+ Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
+ Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
+ Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image)
+
+ // NOTE: By default each cube is mapped to one part of texture atlas
+ Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
+ map.material.texDiffuse = texture; // Set map diffuse texture
+
+ Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
+
+ UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
+
+ SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital 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);
+
+ Begin3dMode(camera);
+
+ DrawModel(map, mapPosition, 1.0f, WHITE);
+
+ End3dMode();
+
+ DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
+ DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
+
+ DrawText("cubicmap image used to", 658, 90, 10, GRAY);
+ DrawText("generate map 3d model", 658, 104, 10, GRAY);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(cubicmap); // Unload cubicmap texture
+ UnloadTexture(texture); // Unload map texture
+ UnloadModel(map); // Unload map model
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/docs/examples/src/models/models_geometric_shapes.c b/docs/examples/src/models/models_geometric_shapes.c
new file mode 100644
index 00000000..a13a1f3b
--- /dev/null
+++ b/docs/examples/src/models/models_geometric_shapes.c
@@ -0,0 +1,75 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Draw some basic geometric shapes (cube, sphere, cylinder...)
+*
+* This example has been created using raylib 1.0 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+
+ 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
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ Begin3dMode(camera);
+
+ DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
+ DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
+ DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);
+
+ DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
+ DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);
+
+ DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
+ DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
+ DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);
+
+ DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
+ DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);
+
+ DrawGrid(10, 1.0f); // Draw a grid
+
+ End3dMode();
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/docs/examples/src/models/models_heightmap.c b/docs/examples/src/models/models_heightmap.c
new file mode 100644
index 00000000..10069e03
--- /dev/null
+++ b/docs/examples/src/models/models_heightmap.c
@@ -0,0 +1,80 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Heightmap loading and drawing
+*
+* This example has been created using raylib 1.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
+
+ // Define our custom camera to look into our 3d world
+ Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+
+ Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
+ Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
+ Model map = LoadHeightmap(image, (Vector3){ 16, 8, 16 }); // Load heightmap model with defined size
+ map.material.texDiffuse = texture; // Set map diffuse texture
+ Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
+
+ UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
+
+ SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital 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);
+
+ Begin3dMode(camera);
+
+ // NOTE: Model is scaled to 1/4 of its original size (128x128 units)
+ DrawModel(map, mapPosition, 1.0f, RED);
+
+ DrawGrid(20, 1.0f);
+
+ End3dMode();
+
+ DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
+ DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Unload texture
+ UnloadModel(map); // Unload model
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/docs/examples/src/models/models_obj_loading.c b/docs/examples/src/models/models_obj_loading.c
new file mode 100644
index 00000000..50d42d2e
--- /dev/null
+++ b/docs/examples/src/models/models_obj_loading.c
@@ -0,0 +1,75 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Load and draw a 3d model (OBJ)
+*
+* This example has been created using raylib 1.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+
+ Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
+ Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
+ dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture
+ Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
+
+ 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
+ //----------------------------------------------------------------------------------
+ //...
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ Begin3dMode(camera);
+
+ DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
+
+ DrawGrid(10, 1.0f); // Draw a grid
+
+ DrawGizmo(position); // Draw gizmo
+
+ End3dMode();
+
+ DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Unload texture
+ UnloadModel(dwarf); // Unload model
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file