1/*******************************************************************************************
2*
3* raylib [models] example - Show the difference between perspective and orthographic projection
4*
5* This program is heavily based on the geometric objects example
6*
7* This example has been created using raylib 2.0 (www.raylib.com)
8* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
9*
10* Example contributed by Max Danielsson (@autious) and reviewed by Ramon Santamaria (@raysan5)
11*
12* Copyright (c) 2018 Max Danielsson (@autious) and Ramon Santamaria (@raysan5)
13*
14********************************************************************************************/
15
16#include "raylib.h"
17
18#define FOVY_PERSPECTIVE 45.0f
19#define WIDTH_ORTHOGRAPHIC 10.0f
20
21int main(void)
22{
23 // Initialization
24 //--------------------------------------------------------------------------------------
25 const int screenWidth = 800;
26 const int screenHeight = 450;
27
28 InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
29
30 // Define the camera to look into our 3d world
31 Camera camera = { { 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE };
32
33 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
34 //--------------------------------------------------------------------------------------
35
36 // Main game loop
37 while (!WindowShouldClose()) // Detect window close button or ESC key
38 {
39 // Update
40 //----------------------------------------------------------------------------------
41 if (IsKeyPressed(KEY_SPACE))
42 {
43 if (camera.type == CAMERA_PERSPECTIVE)
44 {
45 camera.fovy = WIDTH_ORTHOGRAPHIC;
46 camera.type = CAMERA_ORTHOGRAPHIC;
47 }
48 else
49 {
50 camera.fovy = FOVY_PERSPECTIVE;
51 camera.type = CAMERA_PERSPECTIVE;
52 }
53 }
54 //----------------------------------------------------------------------------------
55
56 // Draw
57 //----------------------------------------------------------------------------------
58 BeginDrawing();
59
60 ClearBackground(RAYWHITE);
61
62 BeginMode3D(camera);
63
64 DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
65 DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
66 DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);
67
68 DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
69 DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);
70
71 DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
72 DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
73 DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);
74
75 DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
76 DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);
77
78 DrawGrid(10, 1.0f); // Draw a grid
79
80 EndMode3D();
81
82 DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY);
83
84 if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK);
85 else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK);
86
87 DrawFPS(10, 10);
88
89 EndDrawing();
90 //----------------------------------------------------------------------------------
91 }
92
93 // De-Initialization
94 //--------------------------------------------------------------------------------------
95 CloseWindow(); // Close window and OpenGL context
96 //--------------------------------------------------------------------------------------
97
98 return 0;
99}
100