Browse Source

Remove state bool in camera projection type example.

Changes made based on commentary in pull request 513
Max Danielsson 7 years ago
parent
commit
e38d28543a
1 changed files with 13 additions and 13 deletions
  1. 13 13
      examples/models/models_orthographic_projection.c

+ 13 - 13
examples/models/models_orthographic_projection.c

@@ -19,12 +19,13 @@ int main()
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
     int screenWidth = 800;
     int screenWidth = 800;
     int screenHeight = 450;
     int screenHeight = 450;
-    bool view_ortho = true;
 
 
     InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
     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
     // 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
     SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
@@ -42,21 +43,20 @@ int main()
         //----------------------------------------------------------------------------------
         //----------------------------------------------------------------------------------
         if(IsKeyPressed(KEY_SPACE)) 
         if(IsKeyPressed(KEY_SPACE)) 
         {
         {
-            view_ortho = !view_ortho;
+            if(camera.type == CAMERA_PERSPECTIVE) 
+            {
+                camera = orthographic_camera;
+            } 
+            else 
+            {
+                camera = perspective_camera;
+            }
         }
         }
 
 
 
 
         // Draw
         // 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();
         BeginDrawing();
 
 
@@ -86,11 +86,11 @@ int main()
 
 
             DrawText("Press Spacebar to switch camera type", 10, 40, 24, BLACK);
             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);
                 DrawText("Orthographic", 10, 65, 24, BLACK);
             }
             }
-            else
+            else if(camera.type == CAMERA_PERSPECTIVE)
             {
             {
                 DrawText("Perspective", 10, 65, 24, BLACK);
                 DrawText("Perspective", 10, 65, 24, BLACK);
             }
             }