diff options
| author | Ray <[email protected]> | 2019-05-21 17:03:01 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-05-21 17:03:01 +0200 |
| commit | 6f4a27cc61f12d3789729413bed69e86226911cf (patch) | |
| tree | 92a23884870826e6deaf560743ebbdae8bce94ba /examples/src/models | |
| parent | 2141d7943b6b65fa66f583f0819bb27fee815189 (diff) | |
| download | raylib.com-6f4a27cc61f12d3789729413bed69e86226911cf.tar.gz raylib.com-6f4a27cc61f12d3789729413bed69e86226911cf.zip | |
Remove examples default code
Code is directly fetched form raylib repo, this way we avoid duplicate code!
Diffstat (limited to 'examples/src/models')
| -rw-r--r-- | examples/src/models/models_animation.c | 101 | ||||
| -rw-r--r-- | examples/src/models/models_billboard.c | 75 | ||||
| -rw-r--r-- | examples/src/models/models_box_collisions.c | 121 | ||||
| -rw-r--r-- | examples/src/models/models_cubicmap.c | 87 | ||||
| -rw-r--r-- | examples/src/models/models_first_person_maze.c | 126 | ||||
| -rw-r--r-- | examples/src/models/models_geometric_shapes.c | 80 | ||||
| -rw-r--r-- | examples/src/models/models_heightmap.c | 82 | ||||
| -rw-r--r-- | examples/src/models/models_material_pbr.c | 222 | ||||
| -rw-r--r-- | examples/src/models/models_mesh_generation.c | 126 | ||||
| -rw-r--r-- | examples/src/models/models_mesh_picking.c | 202 | ||||
| -rw-r--r-- | examples/src/models/models_obj_loading.c | 80 | ||||
| -rw-r--r-- | examples/src/models/models_obj_viewer.c | 127 | ||||
| -rw-r--r-- | examples/src/models/models_orthographic_projection.c | 99 | ||||
| -rw-r--r-- | examples/src/models/models_rlgl_solar_system.c | 168 | ||||
| -rw-r--r-- | examples/src/models/models_skybox.c | 98 | ||||
| -rw-r--r-- | examples/src/models/models_yaw_pitch_roll.c | 195 |
16 files changed, 0 insertions, 1989 deletions
diff --git a/examples/src/models/models_animation.c b/examples/src/models/models_animation.c deleted file mode 100644 index 294b07a..0000000 --- a/examples/src/models/models_animation.c +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Load 3d model with animations and play them -* -* 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) and @culacant -* -********************************************************************************************/ - -#include "raylib.h" - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - model animation"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position - camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) - camera.fovy = 45.0f; // Camera field-of-view Y - camera.type = CAMERA_PERSPECTIVE; // Camera mode type - - - Model model = LoadModel("resources/guy/guy.iqm"); // Load the animated model mesh and basic data - Texture2D texture = LoadTexture("resources/guy/guytex.png"); // Load model texture and set material - SetMaterialTexture(&model.materials[0], MAP_DIFFUSE, texture); // Set model material map texture - - Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - - // Load animation data - int animsCount = 0; - ModelAnimation *anims = LoadModelAnimations("resources/guy/guyanim.iqm", &animsCount); - int animFrameCounter = 0; - - SetCameraMode(camera, CAMERA_FREE); // Set free 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); - - // Play animation when spacebar is held down - if (IsKeyDown(KEY_SPACE)) - { - animFrameCounter++; - UpdateModelAnimation(model, anims[0], animFrameCounter); - if (animFrameCounter >= anims[0].frameCount) animFrameCounter = 0; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(camera); - - DrawModelEx(model, position, (Vector3){ 1.0f, 0.0f, 0.0f }, -90.0f, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE); - - for (int i = 0; i < model.boneCount; i++) - { - DrawCube(anims[0].framePoses[animFrameCounter][i].translation, 0.2f, 0.2f, 0.2f, RED); - } - - DrawGrid(10, 1.0f); // Draw a grid - - EndMode3D(); - - DrawText("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, MAROON); - DrawText("(c) Guy IQM 3D model by @culacant", screenWidth - 200, screenHeight - 20, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - // Unload model animations data - for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]); - - UnloadModel(model); // Unload model - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/models/models_billboard.c b/examples/src/models/models_billboard.c deleted file mode 100644 index 597e9a6..0000000 --- a/examples/src/models/models_billboard.c +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************************* -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 5.0f, 4.0f, 5.0f }; - camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - camera.fovy = 45.0f; - camera.type = CAMERA_PERSPECTIVE; - - 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); - - BeginMode3D(camera); - - DrawGrid(10, 1.0f); // Draw a grid - - DrawBillboard(camera, bill, billPosition, 2.0f, WHITE); - - EndMode3D(); - - 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/examples/src/models/models_box_collisions.c b/examples/src/models/models_box_collisions.c deleted file mode 100644 index 0dd0710..0000000 --- a/examples/src/models/models_box_collisions.c +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************************* -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const 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, 0 }; - - 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); - - BeginMode3D(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 - - EndMode3D(); - - 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/examples/src/models/models_cubicmap.c b/examples/src/models/models_cubicmap.c deleted file mode 100644 index f399a56..0000000 --- a/examples/src/models/models_cubicmap.c +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Cubicmap loading and drawing -* -* This example has been created using raylib 1.8 (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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const 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, 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); - - // 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 - - 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); - - BeginMode3D(camera); - - DrawModel(model, mapPosition, 1.0f, WHITE); - - EndMode3D(); - - 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(model); // Unload map model - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/models/models_first_person_maze.c b/examples/src/models/models_first_person_maze.c deleted file mode 100644 index 4236374..0000000 --- a/examples/src/models/models_first_person_maze.c +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************************* -* -* 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" - -#include <stdlib.h> // Required for: free() - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const 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 imMap = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) - Texture2D cubicmap = LoadTextureFromImage(imMap); // Convert image to texture to display (VRAM) - Mesh mesh = GenMeshCubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f }); - Model model = LoadModelFromMesh(mesh); - - // 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 - - // Get map image data to be used for collision detection - Color *mapPixels = GetImageData(imMap); - UnloadImage(imMap); // Unload image from RAM - - 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 - //---------------------------------------------------------------------------------- - Vector3 oldCamPos = camera.position; // Store old camera position - - UpdateCamera(&camera); // Update camera - - // Check player collision (we simplify to 2D collision detection) - Vector2 playerPos = { camera.position.x, camera.position.z }; - float playerRadius = 0.1f; // Collision radius (player is modelled as a cilinder for collision) - - int playerCellX = (int)(playerPos.x - mapPosition.x + 0.5f); - int playerCellY = (int)(playerPos.y - mapPosition.z + 0.5f); - - // Out-of-limits security check - if (playerCellX < 0) playerCellX = 0; - else if (playerCellX >= cubicmap.width) playerCellX = cubicmap.width - 1; - - if (playerCellY < 0) playerCellY = 0; - else if (playerCellY >= cubicmap.height) playerCellY = cubicmap.height - 1; - - // Check map collisions using image data and player position - // TODO: Improvement: Just check player surrounding cells for collision - for (int y = 0; y < cubicmap.height; y++) - { - for (int x = 0; x < cubicmap.width; x++) - { - if ((mapPixels[y*cubicmap.width + x].r == 255) && // Collision: white pixel, only check R channel - (CheckCollisionCircleRec(playerPos, playerRadius, - (Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f }))) - { - // Collision detected, reset camera position - camera.position = oldCamPos; - } - } - } - //---------------------------------------------------------------------------------- - - // 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); - - // Draw player position radar - DrawRectangle(GetScreenWidth() - cubicmap.width*4 - 20 + playerCellX*4, 20 + playerCellY*4, 4, 4, RED); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - free(mapPixels); // Unload color array - - 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/src/models/models_geometric_shapes.c b/examples/src/models/models_geometric_shapes.c deleted file mode 100644 index 3947792..0000000 --- a/examples/src/models/models_geometric_shapes.c +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************************* -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; - camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - camera.fovy = 45.0f; - camera.type = CAMERA_PERSPECTIVE; - - 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); - - BeginMode3D(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 - - EndMode3D(); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/models/models_heightmap.c b/examples/src/models/models_heightmap.c deleted file mode 100644 index e242db1..0000000 --- a/examples/src/models/models_heightmap.c +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Heightmap loading and drawing -* -* This example has been created using raylib 1.8 (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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const 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, 0 }; - - Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) - Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) - - Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM) - Model model = LoadModelFromMesh(mesh); // Load model from generated mesh - - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture - Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Define model position - - 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); - - BeginMode3D(camera); - - DrawModel(model, mapPosition, 1.0f, RED); - - DrawGrid(20, 1.0f); - - EndMode3D(); - - 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(model); // Unload model - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/models/models_material_pbr.c b/examples/src/models/models_material_pbr.c deleted file mode 100644 index 8d51eef..0000000 --- a/examples/src/models/models_material_pbr.c +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - PBR material -* -* This example has been created using raylib 1.8 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2017 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" -#include "raymath.h" - -#include <stdio.h> - -#define RLIGHTS_IMPLEMENTATION -#include "rlights.h" - -#define CUBEMAP_SIZE 512 // Cubemap texture size -#define IRRADIANCE_SIZE 32 // Irradiance texture size -#define PREFILTERED_SIZE 256 // Prefiltered HDR environment texture size -#define BRDF_SIZE 512 // BRDF LUT texture size - -// PBR material loading -static Material LoadMaterialPBR(Color albedo, float metalness, float roughness); - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) - InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position - camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) - camera.fovy = 45.0f; // Camera field-of-view Y - camera.type = CAMERA_PERSPECTIVE; // Camera mode type - - // Load model and PBR material - Model model = LoadModel("resources/pbr/trooper.obj"); - - // Mesh tangents are generated... and uploaded to GPU - // NOTE: New VBO for tangents is generated at default location and also binded to mesh VAO - MeshTangents(&model.meshes[0]); - - model.materials[0] = LoadMaterialPBR((Color){ 255, 255, 255, 255 }, 1.0f, 1.0f); - - // Define lights attributes - // NOTE: Shader is passed to every light on creation to define shader bindings internally - Light lights[MAX_LIGHTS] = { - CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.materials[0].shader), - CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.materials[0].shader), - CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.materials[0].shader), - CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.materials[0].shader) - }; - - 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 - - // Send to material PBR shader camera view position - float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z }; - SetShaderValue(model.materials[0].shader, model.materials[0].shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(camera); - - DrawModel(model, Vector3Zero(), 1.0f, WHITE); - - DrawGrid(10, 1.0f); - - EndMode3D(); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadModel(model); // Unload skybox model - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} - -// Load PBR material (Supports: ALBEDO, NORMAL, METALNESS, ROUGHNESS, AO, EMMISIVE, HEIGHT maps) -// NOTE: PBR shader is loaded inside this function -static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) -{ - Material mat = { 0 }; // NOTE: All maps textures are set to { 0 } - -#if defined(PLATFORM_DESKTOP) - mat.shader = LoadShader("resources/shaders/glsl330/pbr.vs", "resources/shaders/glsl330/pbr.fs"); -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - mat.shader = LoadShader("resources/shaders/glsl100/pbr.vs", "resources/shaders/glsl100/pbr.fs"); -#endif - - // Get required locations points for PBR material - // NOTE: Those location names must be available and used in the shader code - mat.shader.locs[LOC_MAP_ALBEDO] = GetShaderLocation(mat.shader, "albedo.sampler"); - mat.shader.locs[LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler"); - mat.shader.locs[LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler"); - mat.shader.locs[LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler"); - mat.shader.locs[LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler"); - //mat.shader.locs[LOC_MAP_EMISSION] = GetShaderLocation(mat.shader, "emission.sampler"); - //mat.shader.locs[LOC_MAP_HEIGHT] = GetShaderLocation(mat.shader, "height.sampler"); - mat.shader.locs[LOC_MAP_IRRADIANCE] = GetShaderLocation(mat.shader, "irradianceMap"); - mat.shader.locs[LOC_MAP_PREFILTER] = GetShaderLocation(mat.shader, "prefilterMap"); - mat.shader.locs[LOC_MAP_BRDF] = GetShaderLocation(mat.shader, "brdfLUT"); - - // Set view matrix location - mat.shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(mat.shader, "matModel"); - mat.shader.locs[LOC_MATRIX_VIEW] = GetShaderLocation(mat.shader, "view"); - mat.shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(mat.shader, "viewPos"); - - // Set PBR standard maps - mat.maps[MAP_ALBEDO].texture = LoadTexture("resources/pbr/trooper_albedo.png"); - mat.maps[MAP_NORMAL].texture = LoadTexture("resources/pbr/trooper_normals.png"); - mat.maps[MAP_METALNESS].texture = LoadTexture("resources/pbr/trooper_metalness.png"); - mat.maps[MAP_ROUGHNESS].texture = LoadTexture("resources/pbr/trooper_roughness.png"); - mat.maps[MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png"); - - // Load equirectangular to cubemap shader -#if defined(PLATFORM_DESKTOP) - Shader shdrCubemap = LoadShader("resources/shaders/glsl330/cubemap.vs", "resources/shaders/glsl330/cubemap.fs"); -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - Shader shdrCubemap = LoadShader("resources/shaders/glsl100/cubemap.vs", "resources/shaders/glsl100/cubemap.fs"); -#endif - - // Load irradiance (GI) calculation shader -#if defined(PLATFORM_DESKTOP) - Shader shdrIrradiance = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/irradiance.fs"); -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - Shader shdrIrradiance = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/irradiance.fs"); -#endif - - // Load reflection prefilter calculation shader -#if defined(PLATFORM_DESKTOP) - Shader shdrPrefilter = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/prefilter.fs"); -#else - Shader shdrPrefilter = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/prefilter.fs"); -#endif - - // Load bidirectional reflectance distribution function shader -#if defined(PLATFORM_DESKTOP) - Shader shdrBRDF = LoadShader("resources/shaders/glsl330/brdf.vs", "resources/shaders/glsl330/brdf.fs"); -#else - Shader shdrBRDF = LoadShader("resources/shaders/glsl100/brdf.vs", "resources/shaders/glsl100/brdf.fs"); -#endif - - // Setup required shader locations - SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT); - SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT); - SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT); - - Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); - Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE); - mat.maps[MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE); - mat.maps[MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE); - mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, BRDF_SIZE); - UnloadTexture(cubemap); - UnloadTexture(texHDR); - - // Unload already used shaders (to create specific textures) - UnloadShader(shdrCubemap); - UnloadShader(shdrIrradiance); - UnloadShader(shdrPrefilter); - UnloadShader(shdrBRDF); - - // Set textures filtering for better quality - SetTextureFilter(mat.maps[MAP_ALBEDO].texture, FILTER_BILINEAR); - SetTextureFilter(mat.maps[MAP_NORMAL].texture, FILTER_BILINEAR); - SetTextureFilter(mat.maps[MAP_METALNESS].texture, FILTER_BILINEAR); - SetTextureFilter(mat.maps[MAP_ROUGHNESS].texture, FILTER_BILINEAR); - SetTextureFilter(mat.maps[MAP_OCCLUSION].texture, FILTER_BILINEAR); - - // Enable sample usage in shader for assigned textures - SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, UNIFORM_INT); - SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, UNIFORM_INT); - SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, UNIFORM_INT); - SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, UNIFORM_INT); - SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, UNIFORM_INT); - - int renderModeLoc = GetShaderLocation(mat.shader, "renderMode"); - SetShaderValue(mat.shader, renderModeLoc, (int[1]){ 0 }, UNIFORM_INT); - - // Set up material properties color - mat.maps[MAP_ALBEDO].color = albedo; - mat.maps[MAP_NORMAL].color = (Color){ 128, 128, 255, 255 }; - mat.maps[MAP_METALNESS].value = metalness; - mat.maps[MAP_ROUGHNESS].value = roughness; - mat.maps[MAP_OCCLUSION].value = 1.0f; - mat.maps[MAP_EMISSION].value = 0.5f; - mat.maps[MAP_HEIGHT].value = 0.5f; - - return mat; -} diff --git a/examples/src/models/models_mesh_generation.c b/examples/src/models/models_mesh_generation.c deleted file mode 100644 index cfc3bdd..0000000 --- a/examples/src/models/models_mesh_generation.c +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************************* -* -* raylib example - procedural mesh generation -* -* This example has been created using raylib 1.8 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2017 Ramon Santamaria (Ray San) -* -********************************************************************************************/ - -#include "raylib.h" - -#define NUM_MODELS 8 // Parametric 3d shapes to generate - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation"); - - // We generate a checked image for texturing - Image checked = GenImageChecked(2, 2, 1, 1, RED, GREEN); - Texture2D texture = LoadTextureFromImage(checked); - UnloadImage(checked); - - Model models[NUM_MODELS]; - - models[0] = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5)); - models[1] = LoadModelFromMesh(GenMeshCube(2.0f, 1.0f, 2.0f)); - models[2] = LoadModelFromMesh(GenMeshSphere(2, 32, 32)); - models[3] = LoadModelFromMesh(GenMeshHemiSphere(2, 16, 16)); - models[4] = LoadModelFromMesh(GenMeshCylinder(1, 2, 16)); - models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32)); - models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128)); - models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f)); - - // Set checked texture as default diffuse component for all models material - for (int i = 0; i < NUM_MODELS; i++) models[i].materials[0].maps[MAP_DIFFUSE].texture = texture; - - // Define the camera to look into our 3d world - Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; - - // Model drawing position - Vector3 position = { 0.0f, 0.0f, 0.0f }; - - int currentModel = 0; - - SetCameraMode(camera, CAMERA_ORBITAL); // Set a 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 internal camera and our camera - - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures - } - - if (IsKeyPressed(KEY_RIGHT)) - { - currentModel++; - if (currentModel >= NUM_MODELS) currentModel = 0; - } - else if (IsKeyPressed(KEY_LEFT)) - { - currentModel--; - if (currentModel < 0) currentModel = NUM_MODELS - 1; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(camera); - - DrawModel(models[currentModel], position, 1.0f, WHITE); - - DrawGrid(10, 1.0); - - EndMode3D(); - - DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f)); - DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f)); - DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE); - - switch(currentModel) - { - case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE); break; - case 1: DrawText("CUBE", 680, 10, 20, DARKBLUE); break; - case 2: DrawText("SPHERE", 680, 10, 20, DARKBLUE); break; - case 3: DrawText("HEMISPHERE", 640, 10, 20, DARKBLUE); break; - case 4: DrawText("CYLINDER", 680, 10, 20, DARKBLUE); break; - case 5: DrawText("TORUS", 680, 10, 20, DARKBLUE); break; - case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break; - case 7: DrawText("POLY", 680, 10, 20, DARKBLUE); break; - default: break; - } - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - - // Unload models data (GPU VRAM) - for (int i = 0; i < NUM_MODELS; i++) UnloadModel(models[i]); - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/models/models_mesh_picking.c b/examples/src/models/models_mesh_picking.c deleted file mode 100644 index 26d9fa7..0000000 --- a/examples/src/models/models_mesh_picking.c +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Mesh picking in 3d mode, ground plane, triangle, mesh -* -* This example has been created using raylib 1.7 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2015 Ramon Santamaria (@raysan5) -* Example contributed by Joel Davis (@joeld42) -* -********************************************************************************************/ - -#include "raylib.h" -#include "raymath.h" - -#define FLT_MAX 340282346638528859811704183484516925440.0f // Maximum value of a float, from bit pattern 01111111011111111111111111111111 - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 20.0f, 20.0f, 20.0f }; // Camera position - camera.target = (Vector3){ 0.0f, 8.0f, 0.0f }; // Camera looking at point - camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target) - camera.fovy = 45.0f; // Camera field-of-view Y - camera.type = CAMERA_PERSPECTIVE; // Camera mode type - - Ray ray = { 0 }; // Picking ray - - Model tower = LoadModel("resources/models/turret.obj"); // Load OBJ model - Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture - tower.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture - - Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position - BoundingBox towerBBox = MeshBoundingBox(tower.meshes[0]); // Get mesh bounding box - bool hitMeshBBox = false; - bool hitTriangle = false; - - // Test triangle - Vector3 ta = (Vector3){ -25.0, 0.5, 0.0 }; - Vector3 tb = (Vector3){ -4.0, 2.5, 1.0 }; - Vector3 tc = (Vector3){ -8.0, 6.5, 0.0 }; - - Vector3 bary = { 0.0f, 0.0f, 0.0f }; - - SetCameraMode(camera, CAMERA_FREE); // Set a free 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 - - // Display information about closest hit - RayHitInfo nearestHit = { 0 }; - char *hitObjectName = "None"; - nearestHit.distance = FLT_MAX; - nearestHit.hit = false; - Color cursorColor = WHITE; - - // Get ray and test against ground, triangle, and mesh - ray = GetMouseRay(GetMousePosition(), camera); - - // Check ray collision aginst ground plane - RayHitInfo groundHitInfo = GetCollisionRayGround(ray, 0.0f); - - if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance)) - { - nearestHit = groundHitInfo; - cursorColor = GREEN; - hitObjectName = "Ground"; - } - - // Check ray collision against test triangle - RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, ta, tb, tc); - - if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance)) - { - nearestHit = triHitInfo; - cursorColor = PURPLE; - hitObjectName = "Triangle"; - - bary = Vector3Barycenter(nearestHit.position, ta, tb, tc); - hitTriangle = true; - } - else hitTriangle = false; - - RayHitInfo meshHitInfo = { 0 }; - - // Check ray collision against bounding box first, before trying the full ray-mesh test - if (CheckCollisionRayBox(ray, towerBBox)) - { - hitMeshBBox = true; - - // Check ray collision against model - // NOTE: It considers model.transform matrix! - meshHitInfo = GetCollisionRayModel(ray, &tower); - - if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance)) - { - nearestHit = meshHitInfo; - cursorColor = ORANGE; - hitObjectName = "Mesh"; - } - } - - hitMeshBBox = false; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(camera); - - // Draw the tower - // WARNING: If scale is different than 1.0f, - // not considered by GetCollisionRayModel() - DrawModel(tower, towerPos, 1.0f, WHITE); - - // Draw the test triangle - DrawLine3D(ta, tb, PURPLE); - DrawLine3D(tb, tc, PURPLE); - DrawLine3D(tc, ta, PURPLE); - - // Draw the mesh bbox if we hit it - if (hitMeshBBox) DrawBoundingBox(towerBBox, LIME); - - // If we hit something, draw the cursor at the hit point - if (nearestHit.hit) - { - DrawCube(nearestHit.position, 0.3, 0.3, 0.3, cursorColor); - DrawCubeWires(nearestHit.position, 0.3, 0.3, 0.3, RED); - - Vector3 normalEnd; - normalEnd.x = nearestHit.position.x + nearestHit.normal.x; - normalEnd.y = nearestHit.position.y + nearestHit.normal.y; - normalEnd.z = nearestHit.position.z + nearestHit.normal.z; - - DrawLine3D(nearestHit.position, normalEnd, RED); - } - - DrawRay(ray, MAROON); - - DrawGrid(10, 10.0f); - - EndMode3D(); - - // Draw some debug GUI text - DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK); - - if (nearestHit.hit) - { - int ypos = 70; - - DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK); - - DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f", - nearestHit.position.x, - nearestHit.position.y, - nearestHit.position.z), 10, ypos + 15, 10, BLACK); - - DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f", - nearestHit.normal.x, - nearestHit.normal.y, - nearestHit.normal.z), 10, ypos + 30, 10, BLACK); - - if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK); - } - - DrawText("Use Mouse to Move Camera", 10, 430, 10, GRAY); - - DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadModel(tower); // Unload model - UnloadTexture(texture); // Unload texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/models/models_obj_loading.c b/examples/src/models/models_obj_loading.c deleted file mode 100644 index 51578bc..0000000 --- a/examples/src/models/models_obj_loading.c +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************************* -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 8.0f, 8.0f, 8.0f }; // Camera position - camera.target = (Vector3){ 0.0f, 2.5f, 0.0f }; // Camera looking at point - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) - camera.fovy = 45.0f; // Camera field-of-view Y - camera.type = CAMERA_PERSPECTIVE; // Camera mode type - - Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model - Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map 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); - - BeginMode3D(camera); - - DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture - - DrawGrid(10, 1.0f); // Draw a grid - - DrawGizmo(position); // Draw gizmo - - EndMode3D(); - - DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Unload texture - UnloadModel(model); // Unload model - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/models/models_obj_viewer.c b/examples/src/models/models_obj_viewer.c deleted file mode 100644 index dc6787e..0000000 --- a/examples/src/models/models_obj_viewer.c +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - OBJ models viewer -* -* This example has been created using raylib 2.0 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#include <string.h> // Required for: strcpy() - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib example - obj viewer"); - - // Define the camera to look into our 3d world - Camera camera = {{ 30.0f, 30.0f, 30.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; - - Model model = LoadModel("resources/models/turret.obj"); // Load default model obj - Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load default model texture - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model - - Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position - BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds - bool selected = false; // Selected object flag - - SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode - - char objFilename[64] = "turret.obj"; - - 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 - //---------------------------------------------------------------------------------- - if (IsFileDropped()) - { - int count = 0; - char **droppedFiles = GetDroppedFiles(&count); - - if (count == 1) - { - if (IsFileExtension(droppedFiles[0], ".obj")) - { - for (int i = 0; i < model.meshCount; i++) UnloadMesh(&model.meshes[i]); - model.meshes = LoadMeshes(droppedFiles[0], &model.meshCount); - bounds = MeshBoundingBox(model.meshes[0]); - } - else if (IsFileExtension(droppedFiles[0], ".png")) - { - UnloadTexture(texture); - texture = LoadTexture(droppedFiles[0]); - model.materials[0].maps[MAP_DIFFUSE].texture = texture; - } - - strcpy(objFilename, GetFileName(droppedFiles[0])); - } - - ClearDroppedFiles(); // Clear internal buffers - } - - UpdateCamera(&camera); - - // Select model on mouse click - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - // Check collision between ray and box - if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected; - else selected = false; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(camera); - - DrawModel(model, position, 1.0f, WHITE); // Draw 3d model with texture - - DrawGrid(20.0, 10.0); // Draw a grid - - if (selected) DrawBoundingBox(bounds, GREEN); - - EndMode3D(); - - DrawText("Free camera default controls:", 10, 20, 10, DARKGRAY); - DrawText("- Mouse Wheel to Zoom in-out", 20, 40, 10, GRAY); - DrawText("- Mouse Wheel Pressed to Pan", 20, 60, 10, GRAY); - DrawText("- Alt + Mouse Wheel Pressed to Rotate", 20, 80, 10, GRAY); - DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 20, 100, 10, GRAY); - - DrawText("Drag & drop .obj/.png to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY); - DrawText(FormatText("Current file: %s", objFilename), 250, GetScreenHeight() - 20, 10, GRAY); - if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN); - - DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadModel(model); // Unload model - - ClearDroppedFiles(); // Clear internal buffers - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/models/models_orthographic_projection.c b/examples/src/models/models_orthographic_projection.c deleted file mode 100644 index ca9d83c..0000000 --- a/examples/src/models/models_orthographic_projection.c +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Show the difference between perspective and orthographic projection -* -* This program is heavily based on the geometric objects example -* -* This example has been created using raylib 2.0 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by Max Danielsson (@autious) and reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2018 Max Danielsson (@autious) and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#define FOVY_PERSPECTIVE 45.0f -#define WIDTH_ORTHOGRAPHIC 10.0f - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const 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 }, FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE }; - - 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 - //---------------------------------------------------------------------------------- - if (IsKeyPressed(KEY_SPACE)) - { - if (camera.type == CAMERA_PERSPECTIVE) - { - camera.fovy = WIDTH_ORTHOGRAPHIC; - camera.type = CAMERA_ORTHOGRAPHIC; - } - else - { - camera.fovy = FOVY_PERSPECTIVE; - camera.type = CAMERA_PERSPECTIVE; - } - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(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 - - EndMode3D(); - - DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY); - - if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK); - else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/models/models_rlgl_solar_system.c b/examples/src/models/models_rlgl_solar_system.c deleted file mode 100644 index cb9289a..0000000 --- a/examples/src/models/models_rlgl_solar_system.c +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - rlgl module usage with push/pop matrix transformations -* -* This example uses [rlgl] module funtionality (pseudo-OpenGL 1.1 style coding) -* -* This example has been created using raylib 2.2 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2018 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" -#include "rlgl.h" - -//------------------------------------------------------------------------------------ -// Module Functions Declaration -//------------------------------------------------------------------------------------ -void DrawSphereBasic(Color color); // Draw sphere without any matrix transformation - -//------------------------------------------------------------------------------------ -// Program main entry point -//------------------------------------------------------------------------------------ -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - const float sunRadius = 4.0f; - const float earthRadius = 0.6f; - const float earthOrbitRadius = 8.0f; - const float moonRadius = 0.16f; - const float moonOrbitRadius = 1.5f; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - rlgl module usage with push/pop matrix transformations"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 16.0f, 16.0f, 16.0f }; - camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - camera.fovy = 45.0f; - camera.type = CAMERA_PERSPECTIVE; - - SetCameraMode(camera, CAMERA_FREE); - - float rotationSpeed = 0.2f; // General system rotation speed - - float earthRotation = 0.0f; // Rotation of earth around itself (days) in degrees - float earthOrbitRotation = 0.0f; // Rotation of earth around the Sun (years) in degrees - float moonRotation = 0.0f; // Rotation of moon around itself - float moonOrbitRotation = 0.0f; // Rotation of moon around earth in degrees - - 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); - - earthRotation += (5.0f*rotationSpeed); - earthOrbitRotation += (365/360.0f*(5.0f*rotationSpeed)*rotationSpeed); - moonRotation += (2.0f*rotationSpeed); - moonOrbitRotation += (8.0f*rotationSpeed); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(camera); - - rlPushMatrix(); - rlScalef(sunRadius, sunRadius, sunRadius); // Scale Sun - DrawSphereBasic(GOLD); // Draw the Sun - rlPopMatrix(); - - rlPushMatrix(); - rlRotatef(earthOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Earth orbit around Sun - rlTranslatef(earthOrbitRadius, 0.0f, 0.0f); // Translation for Earth orbit - rlRotatef(-earthOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Earth orbit around Sun inverted - - rlPushMatrix(); - rlRotatef(earthRotation, 0.25, 1.0, 0.0); // Rotation for Earth itself - rlScalef(earthRadius, earthRadius, earthRadius);// Scale Earth - - DrawSphereBasic(BLUE); // Draw the Earth - rlPopMatrix(); - - rlRotatef(moonOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Moon orbit around Earth - rlTranslatef(moonOrbitRadius, 0.0f, 0.0f); // Translation for Moon orbit - rlRotatef(-moonOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Moon orbit around Earth inverted - rlRotatef(moonRotation, 0.0f, 1.0f, 0.0f); // Rotation for Moon itself - rlScalef(moonRadius, moonRadius, moonRadius); // Scale Moon - - DrawSphereBasic(LIGHTGRAY); // Draw the Moon - rlPopMatrix(); - - // Some reference elements (not affected by previous matrix transformations) - DrawCircle3D((Vector3){ 0.0f, 0.0f, 0.0f }, earthOrbitRadius, (Vector3){ 1, 0, 0 }, 90.0f, Fade(RED, 0.5f)); - DrawGrid(20, 1.0f); - - EndMode3D(); - - DrawText("EARTH ORBITING AROUND THE SUN!", 400, 10, 20, MAROON); - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} - -//-------------------------------------------------------------------------------------------- -// Module Functions Definitions (local) -//-------------------------------------------------------------------------------------------- - -// Draw sphere without any matrix transformation -// NOTE: Sphere is drawn in world position ( 0, 0, 0 ) with radius 1.0f -void DrawSphereBasic(Color color) -{ - int rings = 16; - int slices = 16; - - rlBegin(RL_TRIANGLES); - rlColor4ub(color.r, color.g, color.b, color.a); - - for (int i = 0; i < (rings + 2); i++) - { - for (int j = 0; j < slices; j++) - { - rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*i))*sinf(DEG2RAD*(j*360/slices)), - sinf(DEG2RAD*(270+(180/(rings + 1))*i)), - cosf(DEG2RAD*(270+(180/(rings + 1))*i))*cosf(DEG2RAD*(j*360/slices))); - rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360/slices)), - sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))), - cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360/slices))); - rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*(j*360/slices)), - sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))), - cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*(j*360/slices))); - - rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*i))*sinf(DEG2RAD*(j*360/slices)), - sinf(DEG2RAD*(270+(180/(rings + 1))*i)), - cosf(DEG2RAD*(270+(180/(rings + 1))*i))*cosf(DEG2RAD*(j*360/slices))); - rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i)))*sinf(DEG2RAD*((j+1)*360/slices)), - sinf(DEG2RAD*(270+(180/(rings + 1))*(i))), - cosf(DEG2RAD*(270+(180/(rings + 1))*(i)))*cosf(DEG2RAD*((j+1)*360/slices))); - rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360/slices)), - sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))), - cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360/slices))); - } - } - rlEnd(); -} diff --git a/examples/src/models/models_skybox.c b/examples/src/models/models_skybox.c deleted file mode 100644 index 1693d9b..0000000 --- a/examples/src/models/models_skybox.c +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Skybox loading and drawing -* -* This example has been created using raylib 1.8 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2017 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing"); - - // Define the camera to look into our 3d world - Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; - - // Load skybox model - Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); - Model skybox = LoadModelFromMesh(cube); - - // Load skybox shader and set required locations - // NOTE: Some locations are automatically set at shader loading -#if defined(PLATFORM_DESKTOP) - skybox.materials[0].shader = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/skybox.fs"); -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - skybox.materials[0].shader = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/skybox.fs"); -#endif - SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT); - - // Load cubemap shader and setup required shader locations -#if defined(PLATFORM_DESKTOP) - Shader shdrCubemap = LoadShader("resources/shaders/glsl330/cubemap.vs", "resources/shaders/glsl330/cubemap.fs"); -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - Shader shdrCubemap = LoadShader("resources/shaders/glsl100/cubemap.vs", "resources/shaders/glsl100/cubemap.fs"); -#endif - SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT); - - // Load HDR panorama (sphere) texture - Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); - - // Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture - // NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping - skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512); - - UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated - UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore - - SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person 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(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); - - DrawGrid(10, 1.0f); - - EndMode3D(); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadModel(skybox); // Unload skybox model (and textures) - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/models/models_yaw_pitch_roll.c b/examples/src/models/models_yaw_pitch_roll.c deleted file mode 100644 index 0931c00..0000000 --- a/examples/src/models/models_yaw_pitch_roll.c +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Plane rotations (yaw, pitch, roll) -* -* This example has been created using raylib 1.8 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2017 Berni (@Berni8k) and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" -#include "raymath.h" - -// Draw angle gauge controls -void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color); - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)"); - - Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); - Texture2D texBackground = LoadTexture("resources/background.png"); - Texture2D texPitch = LoadTexture("resources/pitch.png"); - Texture2D texPlane = LoadTexture("resources/plane.png"); - - RenderTexture2D framebuffer = LoadRenderTexture(192, 192); - - // Model loading - Model model = LoadModel("resources/plane.obj"); // Load OBJ model - model.materials[0].maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture - - GenTextureMipmaps(&model.materials[0].maps[MAP_DIFFUSE].texture); - - Camera camera = { 0 }; - camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective - camera.target = (Vector3){ 0.0f, 12.0f, 0.0f }; // Camera looking at point - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) - camera.fovy = 30.0f; // Camera field-of-view Y - camera.type = CAMERA_PERSPECTIVE; // Camera type - - float pitch = 0.0f; - float roll = 0.0f; - float yaw = 0.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 - //---------------------------------------------------------------------------------- - - // Plane roll (x-axis) controls - if (IsKeyDown(KEY_LEFT)) roll += 1.0f; - else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f; - else - { - if (roll > 0.0f) roll -= 0.5f; - else if (roll < 0.0f) roll += 0.5f; - } - - // Plane yaw (y-axis) controls - if (IsKeyDown(KEY_S)) yaw += 1.0f; - else if (IsKeyDown(KEY_A)) yaw -= 1.0f; - else - { - if (yaw > 0.0f) yaw -= 0.5f; - else if (yaw < 0.0f) yaw += 0.5f; - } - - // Plane pitch (z-axis) controls - if (IsKeyDown(KEY_DOWN)) pitch += 0.6f; - else if (IsKeyDown(KEY_UP)) pitch -= 0.6f; - else - { - if (pitch > 0.3f) pitch -= 0.3f; - else if (pitch < -0.3f) pitch += 0.3f; - } - - // Wraps the phase of an angle to fit between -180 and +180 degrees - int pitchOffset = pitch; - while (pitchOffset > 180) pitchOffset -= 360; - while (pitchOffset < -180) pitchOffset += 360; - pitchOffset *= 10; - - Matrix transform = MatrixIdentity(); - - transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll)); - transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch)); - transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw)); - - model.transform = transform; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // Draw framebuffer texture (Ahrs Display) - int centerX = framebuffer.texture.width/2; - int centerY = framebuffer.texture.height/2; - float scaleFactor = 0.5f; - - BeginTextureMode(framebuffer); - - BeginBlendMode(BLEND_ALPHA); - - DrawTexturePro(texBackground, (Rectangle){ 0, 0, texBackground.width, texBackground.height }, - (Rectangle){ centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor}, - (Vector2){ texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE); - - DrawTexturePro(texPitch, (Rectangle){ 0, 0, texPitch.width, texPitch.height }, - (Rectangle){ centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor }, - (Vector2){ texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE); - - DrawTexturePro(texPlane, (Rectangle){ 0, 0, texPlane.width, texPlane.height }, - (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, - (Vector2){ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); - - EndBlendMode(); - - EndTextureMode(); - - // Draw 3D model (recomended to draw 3D always before 2D) - BeginMode3D(camera); - - DrawModel(model, (Vector3){ 0, 6.0f, 0 }, 1.0f, WHITE); // Draw 3d model with texture - DrawGrid(10, 10.0f); - - EndMode3D(); - - // Draw 2D GUI stuff - DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED); - DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN); - DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE); - - DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f)); - DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f)); - DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY); - DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 390, 10, DARKGRAY); - DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY); - - // Draw framebuffer texture - DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height }, - (Vector2){ screenWidth - framebuffer.texture.width - 20, 20 }, Fade(WHITE, 0.8f)); - - DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - - // Unload all loaded data - UnloadModel(model); - - UnloadRenderTexture(framebuffer); - - UnloadTexture(texAngleGauge); - UnloadTexture(texBackground); - UnloadTexture(texPitch); - UnloadTexture(texPlane); - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} - -// Draw angle gauge controls -void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color) -{ - Rectangle srcRec = { 0, 0, angleGauge.width, angleGauge.height }; - Rectangle dstRec = { x, y, angleGauge.width, angleGauge.height }; - Vector2 origin = { angleGauge.width/2, angleGauge.height/2}; - int textSize = 20; - - DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color); - - DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY); - DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); -} |
