From 24657ca78938469e77fc765e44dc70537dfe0e1a Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 5 Nov 2017 17:06:50 +0100 Subject: Review textures to be POT Could correct possible issues on OpenGL 1.1 --- examples/models/models_yaw_pitch_roll.c | 14 +++++++------- examples/models/resources/angle_gauge.png | Bin 11761 -> 12919 bytes examples/models/resources/plane.png | Bin 4872 -> 4810 bytes 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'examples/models') diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c index 2bae2bf8..625fc554 100644 --- a/examples/models/models_yaw_pitch_roll.c +++ b/examples/models/models_yaw_pitch_roll.c @@ -119,17 +119,17 @@ int main() BeginBlendMode(BLEND_ALPHA); - DrawTexturePro(texBackground, (Rectangle){0,0,texBackground.width, texBackground.height}, + 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); + (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 }, + 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); + (Vector2){ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); EndBlendMode(); @@ -144,9 +144,9 @@ int main() End3dMode(); // Draw 2D GUI stuff - DrawAngleGauge(texAngleGauge, 80, 80, roll, "roll", RED); - DrawAngleGauge(texAngleGauge, 190, 80, pitch, "pitch", GREEN); - DrawAngleGauge(texAngleGauge, 300, 80, yaw, "yaw", SKYBLUE); + 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)); diff --git a/examples/models/resources/angle_gauge.png b/examples/models/resources/angle_gauge.png index 120f3601..f7871de6 100644 Binary files a/examples/models/resources/angle_gauge.png and b/examples/models/resources/angle_gauge.png differ diff --git a/examples/models/resources/plane.png b/examples/models/resources/plane.png index 9f28ddb0..58951ea3 100644 Binary files a/examples/models/resources/plane.png and b/examples/models/resources/plane.png differ -- cgit v1.2.3 From 6ffc8cb7990fb4ff40f205cb53bec797b10e48a2 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Feb 2018 02:05:00 +0100 Subject: raymath.h: Use C99 inline semantics RAYMATH_EXTERN_INLINE was renamed to RAYMATH_HEADER_ONLY, which user code may define if they want to use it as header-only library. If multiple files in the same project define RAYMATH_HEADER_ONLY, they might each have duplicate out-of-line definitions of the same functions. By default, raymath.h exposes inline definitions, which instructs the compiler _not_ to generate out-of-line definitons, if out-of-line definitions are required, those of the file defined with RAYLIB_IMPLEMENTATION are used instead. There may be only one such file. In C++ mode, the compiler will select only one out-of-line definition automatically, so no need to define a RAYLIB_IMPLEMENTATION. Unfortunately, we have to remove raymath function declaration from raylib.h as those declarations would lead to duplicate out-of-line definitions which would yield linker errors. This problem didn't exist with GNU89 or C++, because there multiple defintions are ok, but in C99 they aren't. --- examples/models/models_skybox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/models') diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 46297e41..9f0d8c17 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -62,7 +62,7 @@ int main() Begin3dMode(camera); - DrawModel(skybox, Vector3Zero(), 1.0f, WHITE); + DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); DrawGrid(10, 1.0f); -- cgit v1.2.3 From a5881fb9ccaf60ea0ff4f6afd7f3925e24330cac Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sat, 24 Feb 2018 15:38:54 +0100 Subject: Revert "raymath.h: Use C99 inline semantics" This reverts commit 6ffc8cb7990fb4ff40f205cb53bec797b10e48a2. and commit e4d7bbec1ef08279495ac41f5f8c4be359c58cf0. which I pushed by mistake... --- examples/models/models_skybox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/models') diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 9f0d8c17..46297e41 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -62,7 +62,7 @@ int main() Begin3dMode(camera); - DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); + DrawModel(skybox, Vector3Zero(), 1.0f, WHITE); DrawGrid(10, 1.0f); -- cgit v1.2.3 From f52d2de582643719814987f7335668b611a4edbd Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 22 Feb 2018 02:05:00 +0100 Subject: raymath.h: Use C99 inline semantics RAYMATH_EXTERN_INLINE was renamed to RAYMATH_HEADER_ONLY, which user code may define if they want to use it as header-only library. If multiple files in the same project define RAYMATH_HEADER_ONLY, they might each have duplicate out-of-line definitions of the same functions. By default, raymath.h exposes inline definitions, which instructs the compiler _not_ to generate out-of-line definitons, if out-of-line definitions are required, those of the file defined with RAYLIB_IMPLEMENTATION are used instead. There may be only one such file. In C++ mode, the compiler will select only one out-of-line definition automatically, so no need to define a RAYLIB_IMPLEMENTATION. Unfortunately, we have to remove raymath function declaration from raylib.h as those declarations would lead to duplicate out-of-line definitions which would yield linker errors. This problem didn't exist with GNU89 or C++, because there multiple defintions are ok, but in C99 they aren't. --- examples/models/models_skybox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/models') diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 46297e41..9f0d8c17 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -62,7 +62,7 @@ int main() Begin3dMode(camera); - DrawModel(skybox, Vector3Zero(), 1.0f, WHITE); + DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); DrawGrid(10, 1.0f); -- cgit v1.2.3 From fd2adbe62ded6cb91ae7684331381afe0675df69 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 26 Feb 2018 12:10:45 +0100 Subject: Renamed CalculateBoundingBox() to MeshBoundingBox() Renamed function for consistency with a possible Mesh manipulation functions (maybe added in a future). Naming follows Image*() manipulation functions. --- examples/models/models_mesh_picking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/models') diff --git a/examples/models/models_mesh_picking.c b/examples/models/models_mesh_picking.c index e150fe92..1cc38b45 100644 --- a/examples/models/models_mesh_picking.c +++ b/examples/models/models_mesh_picking.c @@ -38,7 +38,7 @@ int main() tower.material.maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position - BoundingBox towerBBox = CalculateBoundingBox(tower.mesh); + BoundingBox towerBBox = MeshBoundingBox(tower.mesh); // Get mesh bounding box bool hitMeshBBox = false; bool hitTriangle = false; -- cgit v1.2.3 From 276847eca9290e71baf40c3e9e890efe441aac41 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 4 Mar 2018 23:24:30 +0100 Subject: Correct issue with tangents --- examples/models/resources/shaders/pbr.vs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/models') diff --git a/examples/models/resources/shaders/pbr.vs b/examples/models/resources/shaders/pbr.vs index e852ac1a..885cb199 100644 --- a/examples/models/resources/shaders/pbr.vs +++ b/examples/models/resources/shaders/pbr.vs @@ -12,7 +12,7 @@ in vec3 vertexPosition; in vec2 vertexTexCoord; in vec3 vertexNormal; -in vec3 vertexTangent; +in vec4 vertexTangent; // Input uniform values uniform mat4 mvp; @@ -28,7 +28,7 @@ out vec3 fragBinormal; void main() { // Calculate binormal from vertex normal and tangent - vec3 vertexBinormal = cross(vertexNormal, vertexTangent); + vec3 vertexBinormal = cross(vertexNormal, vec3(vertexTangent)); // Calculate fragment normal based on normal transformations mat3 normalMatrix = transpose(inverse(mat3(mMatrix))); @@ -39,7 +39,7 @@ void main() // Send vertex attributes to fragment shader fragTexCoord = vertexTexCoord; fragNormal = normalize(normalMatrix*vertexNormal); - fragTangent = normalize(normalMatrix*vertexTangent); + fragTangent = normalize(normalMatrix*vec3(vertexTangent)); fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal); fragBinormal = normalize(normalMatrix*vertexBinormal); fragBinormal = cross(fragNormal, fragTangent); -- cgit v1.2.3 From d6c1159fce69c556fefebb945fd857b3c761bfab Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 11 Mar 2018 11:01:58 +0100 Subject: Corrected typo --- examples/models/models_material_pbr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/models') diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index 9f576348..d98d7eac 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -113,7 +113,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) 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_OCCUSION] = GetShaderLocation(mat.shader, "occlusion.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"); -- cgit v1.2.3 From d91179f8ab50b608b2dfc04bccbddbd2cd9b68e5 Mon Sep 17 00:00:00 2001 From: Max Danielsson Date: Sun, 25 Mar 2018 18:49:15 +0200 Subject: Add orthographic projection example --- examples/models/models_orthographic_projection.c | 109 +++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 examples/models/models_orthographic_projection.c (limited to 'examples/models') diff --git a/examples/models/models_orthographic_projection.c b/examples/models/models_orthographic_projection.c new file mode 100644 index 00000000..214fc969 --- /dev/null +++ b/examples/models/models_orthographic_projection.c @@ -0,0 +1,109 @@ +/******************************************************************************************* +* +* 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 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; + bool view_ortho = true; + + InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); + + // Define the camera to look into our 3d world + Camera camera; + + 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 + //---------------------------------------------------------------------------------- + // + + // Input + //---------------------------------------------------------------------------------- + if(IsKeyPressed(KEY_SPACE)) + { + view_ortho = !view_ortho; + } + + + // Draw + //---------------------------------------------------------------------------------- + + if(view_ortho) + { + camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 10.0f, CAMERA_ORTHOGRAPHIC }; + } + else + { + camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, CAMERA_PERSPECTIVE }; + } + + 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); + + DrawText("Press Spacebar to switch camera type", 10, 40, 24, BLACK); + + if(view_ortho) + { + DrawText("Orthographic", 10, 65, 24, BLACK); + } + else + { + DrawText("Perspective", 10, 65, 24, BLACK); + } + + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} -- cgit v1.2.3 From e38d28543a6bcb451a3b1176a159d4fc0ff15326 Mon Sep 17 00:00:00 2001 From: Max Danielsson Date: Tue, 27 Mar 2018 19:58:42 +0200 Subject: Remove state bool in camera projection type example. Changes made based on commentary in pull request 513 --- examples/models/models_orthographic_projection.c | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'examples/models') diff --git a/examples/models/models_orthographic_projection.c b/examples/models/models_orthographic_projection.c index 214fc969..b28aa0ae 100644 --- a/examples/models/models_orthographic_projection.c +++ b/examples/models/models_orthographic_projection.c @@ -19,12 +19,13 @@ int main() //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; - bool view_ortho = true; InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); + const Camera perspective_camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, CAMERA_PERSPECTIVE }; + const Camera orthographic_camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 10.0f, CAMERA_ORTHOGRAPHIC }; // Define the camera to look into our 3d world - Camera camera; + Camera camera = perspective_camera; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -42,21 +43,20 @@ int main() //---------------------------------------------------------------------------------- if(IsKeyPressed(KEY_SPACE)) { - view_ortho = !view_ortho; + if(camera.type == CAMERA_PERSPECTIVE) + { + camera = orthographic_camera; + } + else + { + camera = perspective_camera; + } } // Draw //---------------------------------------------------------------------------------- - if(view_ortho) - { - camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 10.0f, CAMERA_ORTHOGRAPHIC }; - } - else - { - camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, CAMERA_PERSPECTIVE }; - } BeginDrawing(); @@ -86,11 +86,11 @@ int main() DrawText("Press Spacebar to switch camera type", 10, 40, 24, BLACK); - if(view_ortho) + if(camera.type == CAMERA_ORTHOGRAPHIC) { DrawText("Orthographic", 10, 65, 24, BLACK); } - else + else if(camera.type == CAMERA_PERSPECTIVE) { DrawText("Perspective", 10, 65, 24, BLACK); } -- cgit v1.2.3 From 42e64e931b27a27795f471817dc93551f4f752e8 Mon Sep 17 00:00:00 2001 From: Max Danielsson Date: Tue, 27 Mar 2018 21:16:25 +0200 Subject: Simplify camera data switch in orthographic 3d example --- examples/models/models_orthographic_projection.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'examples/models') diff --git a/examples/models/models_orthographic_projection.c b/examples/models/models_orthographic_projection.c index b28aa0ae..2c2a89d1 100644 --- a/examples/models/models_orthographic_projection.c +++ b/examples/models/models_orthographic_projection.c @@ -13,6 +13,9 @@ #include "raylib.h" +#define FOVY_PERSPECTIVE 45.0f +#define WIDTH_ORTHOGRAPHIC 10.0f + int main() { // Initialization @@ -22,10 +25,8 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); - const Camera perspective_camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, CAMERA_PERSPECTIVE }; - const Camera orthographic_camera = (Camera){{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 10.0f, CAMERA_ORTHOGRAPHIC }; // Define the camera to look into our 3d world - Camera camera = perspective_camera; + 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 //-------------------------------------------------------------------------------------- @@ -45,11 +46,13 @@ int main() { if(camera.type == CAMERA_PERSPECTIVE) { - camera = orthographic_camera; + camera.fovy = WIDTH_ORTHOGRAPHIC; + camera.type = CAMERA_ORTHOGRAPHIC; } else { - camera = perspective_camera; + camera.fovy = FOVY_PERSPECTIVE; + camera.type = CAMERA_PERSPECTIVE; } } -- cgit v1.2.3 From df7460747926e3330886af2698994fa05b2595a9 Mon Sep 17 00:00:00 2001 From: "maficccc@gmail.com" Date: Tue, 13 Mar 2018 17:04:49 +0100 Subject: Fix warning: illegal character encoding in string literal --- examples/models/models_yaw_pitch_roll.c | 66 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'examples/models') diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c index 625fc554..4fdbd4d7 100644 --- a/examples/models/models_yaw_pitch_roll.c +++ b/examples/models/models_yaw_pitch_roll.c @@ -5,7 +5,7 @@ * 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 based on Berni work on Raspberry Pi: +* Example based on Berni work on Raspberry Pi: * http://forum.raylib.com/index.php?p=/discussion/124/line-versus-triangle-drawing-order * * Copyright (c) 2017 Ramon Santamaria (@raysan5) @@ -30,25 +30,25 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)"); - Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); + Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); Texture2D texBackground = LoadTexture("resources/background.png"); - Texture2D texPitch = LoadTexture("resources/pitch.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.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture - + GenTextureMipmaps(&model.material.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 - + float pitch = 0.0f; float roll = 0.0f; float yaw = 0.0f; @@ -61,7 +61,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - + // Plane roll (x-axis) controls if (IsKeyDown(KEY_LEFT)) roll += 1.0f; else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f; @@ -70,7 +70,7 @@ int main() 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; @@ -79,7 +79,7 @@ int main() 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; @@ -88,7 +88,7 @@ int main() 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; @@ -96,20 +96,20 @@ int main() 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; @@ -126,11 +126,11 @@ int main() 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 }, + (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, (Vector2){ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); - + EndBlendMode(); EndTextureMode(); @@ -147,7 +147,7 @@ int main() 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); @@ -155,31 +155,31 @@ int main() 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 }, + 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(texAngleGauge); UnloadTexture(texBackground); - UnloadTexture(texPitch); + UnloadTexture(texPitch); UnloadTexture(texPlane); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + return 0; } @@ -192,7 +192,7 @@ void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[ 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); -} \ No newline at end of file + + 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); +} -- cgit v1.2.3 From 7bd0f8b28c4cd576ab5c3e7b696d408f0f8045e4 Mon Sep 17 00:00:00 2001 From: lumaio teon Date: Sat, 7 Apr 2018 04:00:06 -0400 Subject: Fix mesh picking example --- examples/models/models_mesh_picking.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/models') diff --git a/examples/models/models_mesh_picking.c b/examples/models/models_mesh_picking.c index 1cc38b45..e09f9860 100644 --- a/examples/models/models_mesh_picking.c +++ b/examples/models/models_mesh_picking.c @@ -101,8 +101,8 @@ int main() { hitMeshBBox = true; - // Check ray collision against mesh - meshHitInfo = GetCollisionRayMesh(ray, &tower.mesh); + // Check ray collision against model + meshHitInfo = GetCollisionRayModel(ray, &tower); if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance)) { -- cgit v1.2.3 From 4cc12ef2b32f66f160e4e401e5cd76d1740eaf61 Mon Sep 17 00:00:00 2001 From: Ray San Date: Wed, 11 Apr 2018 10:13:00 +0200 Subject: Review camera definition on examples --- examples/models/models_billboard.c | 8 ++++- examples/models/models_box_collisions.c | 2 +- examples/models/models_cubicmap.c | 2 +- examples/models/models_geometric_shapes.c | 7 ++++- examples/models/models_heightmap.c | 2 +- examples/models/models_material_pbr.c | 2 +- examples/models/models_mesh_generation.c | 2 +- examples/models/models_obj_loading.c | 7 ++++- examples/models/models_orthographic_projection.c | 37 +++++++----------------- examples/models/models_skybox.c | 2 +- examples/models/models_yaw_pitch_roll.c | 1 + 11 files changed, 37 insertions(+), 35 deletions(-) (limited to 'examples/models') diff --git a/examples/models/models_billboard.c b/examples/models/models_billboard.c index bca9faf8..3b3efc47 100644 --- a/examples/models/models_billboard.c +++ b/examples/models/models_billboard.c @@ -21,7 +21,13 @@ int main() 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 }; + 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 diff --git a/examples/models/models_box_collisions.c b/examples/models/models_box_collisions.c index 69cec418..eb72c54c 100644 --- a/examples/models/models_box_collisions.c +++ b/examples/models/models_box_collisions.c @@ -21,7 +21,7 @@ int main() 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 }; + 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 }; diff --git a/examples/models/models_cubicmap.c b/examples/models/models_cubicmap.c index d8be9329..47b88748 100644 --- a/examples/models/models_cubicmap.c +++ b/examples/models/models_cubicmap.c @@ -21,7 +21,7 @@ int main() 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 }; + 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) diff --git a/examples/models/models_geometric_shapes.c b/examples/models/models_geometric_shapes.c index a13a1f3b..7a1e7e48 100644 --- a/examples/models/models_geometric_shapes.c +++ b/examples/models/models_geometric_shapes.c @@ -21,7 +21,12 @@ int main() 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 }; + 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 //-------------------------------------------------------------------------------------- diff --git a/examples/models/models_heightmap.c b/examples/models/models_heightmap.c index e476d1b7..55474185 100644 --- a/examples/models/models_heightmap.c +++ b/examples/models/models_heightmap.c @@ -21,7 +21,7 @@ int main() 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 }; + 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) diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index d98d7eac..4ad2c9e7 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -34,7 +34,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material"); // Define the camera to look into our 3d world - Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Load model and PBR material Model model = LoadModel("resources/pbr/trooper.obj"); diff --git a/examples/models/models_mesh_generation.c b/examples/models/models_mesh_generation.c index 72222156..d9c28ac2 100644 --- a/examples/models/models_mesh_generation.c +++ b/examples/models/models_mesh_generation.c @@ -41,7 +41,7 @@ int main() for (int i = 0; i < NUM_MODELS; i++) models[i].material.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 }; + 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 }; diff --git a/examples/models/models_obj_loading.c b/examples/models/models_obj_loading.c index 70f92168..4f89130f 100644 --- a/examples/models/models_obj_loading.c +++ b/examples/models/models_obj_loading.c @@ -21,7 +21,12 @@ int main() 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 }; + Camera camera = { 0 }; + camera.position = (Vector3){ 3.0f, 3.0f, 3.0f }; + camera.target = (Vector3){ 0.0f, 1.5f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture diff --git a/examples/models/models_orthographic_projection.c b/examples/models/models_orthographic_projection.c index 2c2a89d1..cb5ea053 100644 --- a/examples/models/models_orthographic_projection.c +++ b/examples/models/models_orthographic_projection.c @@ -4,17 +4,17 @@ * * This program is heavily based on the geometric objects example * -* This example has been created using raylib 1.0 (www.raylib.com) +* This example has been created using raylib 1.9.7 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2018 Max Danielsson & Ramon Santamaria (@raysan5) * ********************************************************************************************/ #include "raylib.h" -#define FOVY_PERSPECTIVE 45.0f -#define WIDTH_ORTHOGRAPHIC 10.0f +#define FOVY_PERSPECTIVE 45.0f +#define WIDTH_ORTHOGRAPHIC 10.0f int main() { @@ -36,15 +36,9 @@ int main() { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - // - - // Input - //---------------------------------------------------------------------------------- - if(IsKeyPressed(KEY_SPACE)) + if (IsKeyPressed(KEY_SPACE)) { - if(camera.type == CAMERA_PERSPECTIVE) + if (camera.type == CAMERA_PERSPECTIVE) { camera.fovy = WIDTH_ORTHOGRAPHIC; camera.type = CAMERA_ORTHOGRAPHIC; @@ -55,12 +49,10 @@ int main() camera.type = CAMERA_PERSPECTIVE; } } - + //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- - - BeginDrawing(); ClearBackground(RAYWHITE); @@ -85,19 +77,12 @@ int main() End3dMode(); - DrawFPS(10, 10); + DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY); - DrawText("Press Spacebar to switch camera type", 10, 40, 24, BLACK); - - if(camera.type == CAMERA_ORTHOGRAPHIC) - { - DrawText("Orthographic", 10, 65, 24, BLACK); - } - else if(camera.type == CAMERA_PERSPECTIVE) - { - DrawText("Perspective", 10, 65, 24, BLACK); - } + 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(); //---------------------------------------------------------------------------------- diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 9f0d8c17..700824d3 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -21,7 +21,7 @@ int main() 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 }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Load skybox model Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c index 4fdbd4d7..c559e67b 100644 --- a/examples/models/models_yaw_pitch_roll.c +++ b/examples/models/models_yaw_pitch_roll.c @@ -48,6 +48,7 @@ int main() 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; -- cgit v1.2.3