1/*******************************************************************************************
2*
3* raylib [core] example - Initialize 3d camera free
4*
5* This example has been created using raylib 1.3 (www.raylib.com)
6* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7*
8* Copyright (c) 2015 Ramon Santamaria (@raysan5)
9*
10********************************************************************************************/
11
12#include "raylib.h"
13
14int main(void)
15{
16 // Initialization
17 //--------------------------------------------------------------------------------------
18 const int screenWidth = 800;
19 const int screenHeight = 450;
20
21 InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
22
23 // Define the camera to look into our 3d world
24 Camera3D camera = { 0 };
25 camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
26 camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
27 camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
28 camera.fovy = 45.0f; // Camera field-of-view Y
29 camera.type = CAMERA_PERSPECTIVE; // Camera mode type
30
31 Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
32
33 SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
34
35 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
36 //--------------------------------------------------------------------------------------
37
38 // Main game loop
39 while (!WindowShouldClose()) // Detect window close button or ESC key
40 {
41 // Update
42 //----------------------------------------------------------------------------------
43 UpdateCamera(&camera); // Update camera
44
45 if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
46 //----------------------------------------------------------------------------------
47
48 // Draw
49 //----------------------------------------------------------------------------------
50 BeginDrawing();
51
52 ClearBackground(RAYWHITE);
53
54 BeginMode3D(camera);
55
56 DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
57 DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
58
59 DrawGrid(10, 1.0f);
60
61 EndMode3D();
62
63 DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f));
64 DrawRectangleLines( 10, 10, 320, 133, BLUE);
65
66 DrawText("Free camera default controls:", 20, 20, 10, BLACK);
67 DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
68 DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY);
69 DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY);
70 DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY);
71 DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
72
73 EndDrawing();
74 //----------------------------------------------------------------------------------
75 }
76
77 // De-Initialization
78 //--------------------------------------------------------------------------------------
79 CloseWindow(); // Close window and OpenGL context
80 //--------------------------------------------------------------------------------------
81
82 return 0;
83}