raylib/ports/core/core_3d_camera_free
Licence This example has its own licence, rather than Odin's: raylib/ports/LICENSE
These are ported Raylib examples, and as such, they are subject to Raylib's license.
Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
The rest of the licence
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.
Code
core_3d_camera_free.odin ¶89 linesSource
1/*******************************************************************************************
2*
3* raylib [core] example - 3d camera free
4*
5* Example complexity rating: [★☆☆☆] 1/4
6*
7* Example originally created with raylib 1.3, last time updated with raylib 1.3
8*
9* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
10* BSD-like license that allows static linking with closed source software
11*
12* Copyright (c) 2015-2025 Ramon Santamaria (@raysan5)
13*
14********************************************************************************************/
15
16package raylib_examples
17
18import rl "vendor:raylib"
19
20//------------------------------------------------------------------------------------
21// Program main entry point
22//------------------------------------------------------------------------------------
23main :: proc() {
24 // Initialization
25 //--------------------------------------------------------------------------------------
26 SCREEN_WIDTH :: 800
27 SCREEN_HEIGHT :: 450
28
29 rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - 3d camera free")
30
31 // Define the camera to look into our 3d world
32 camera := rl.Camera3D {
33 position = {10, 10, 10}, // Camera position
34 //target = {0, 0, 0}, // Camera looking at point
35 up = {0, 1, 0}, // Camera up vector (rotation towards target)
36 fovy = 45, // Camera field-of-view Y
37 projection = .PERSPECTIVE, // Camera projection type
38 }
39
40 cube_position: rl.Vector3
41
42 rl.DisableCursor() // Limit cursor to relative movement inside the window
43
44 rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
45 //--------------------------------------------------------------------------------------
46
47 // Main game loop
48 for !rl.WindowShouldClose() { // Detect window close button or ESC key
49 // Update
50 //----------------------------------------------------------------------------------
51 rl.UpdateCamera(&camera, .FREE)
52
53 if rl.IsKeyPressed(.Z) {
54 camera.target = {0, 0, 0}
55 }
56 //----------------------------------------------------------------------------------
57
58 // Draw
59 //----------------------------------------------------------------------------------
60 rl.BeginDrawing()
61
62 rl.ClearBackground(rl.RAYWHITE)
63
64 rl.BeginMode3D(camera)
65
66 rl.DrawCube(cube_position, 2, 2, 2, rl.RED)
67 rl.DrawCubeWires(cube_position, 2, 2, 2, rl.MAROON)
68
69 rl.DrawGrid(10, 1)
70
71 rl.EndMode3D()
72
73 rl.DrawRectangle(10, 10, 320, 93, rl.Fade(rl.SKYBLUE, 0.5))
74 rl.DrawRectangleLines(10, 10, 320, 93, rl.BLUE)
75
76 rl.DrawText("Free camera default controls:", 20, 20, 10, rl.BLACK)
77 rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DARKGRAY)
78 rl.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DARKGRAY)
79 rl.DrawText("- Z to zoom to (0, 0, 0)", 40, 80, 10, rl.DARKGRAY)
80
81 rl.EndDrawing()
82 //----------------------------------------------------------------------------------
83 }
84
85 // De-Initialization
86 //--------------------------------------------------------------------------------------
87 rl.CloseWindow() // Close window and OpenGL context
88 //--------------------------------------------------------------------------------------
89}
Declarations Used 28
- vendor:raylib BeginDrawing · BeginMode3D · BLACK · BLUE · Camera3D · ClearBackground · CloseWindow · DARKGRAY · DisableCursor · DrawCube · DrawCubeWires · DrawGrid · DrawRectangle · DrawRectangleLines · DrawText · EndDrawing · EndMode3D · Fade · InitWindow · IsKeyPressed · MAROON · RAYWHITE · RED · SetTargetFPS · SKYBLUE · UpdateCamera · Vector3 · WindowShouldClose