forked from kevinw/raylib-jai
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore_3d_camera_first_person.jai
91 lines (74 loc) · 3.49 KB
/
core_3d_camera_first_person.jai
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
*
* raylib [core] example - 3d camera first person
*
* This example has been created using raylib 1.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#import "raylib";
#import "Math";
MAX_COLUMNS :: 20;
main :: ()
{
// Initialization
//--------------------------------------------------------------------------------------
screenWidth :: 800;
screenHeight :: 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
defer CloseWindow();
// Define the camera to look into our 3d world (position, target, up vector)
camera: Camera = .{
position = .{ 4.0, 2.0, 4.0 },
target = .{ 0.0, 1.8, 0.0 },
up = .{ 0.0, 1.0, 0.0 },
fovy = 60.0,
projection = CameraProjection.CAMERA_PERSPECTIVE,
};
// Generates some random columns
heights: [MAX_COLUMNS]float;
positions: [MAX_COLUMNS]Vector3;
colors: [MAX_COLUMNS]Color;
for i: 0..MAX_COLUMNS - 1 {
heights[i] = cast(float)GetRandomValue(1, 12);
positions[i] = make_vector3( cast(float)GetRandomValue(-15, 15), heights[i]/2.0, cast(float)GetRandomValue(-15, 15) );
colors[i] = make_Color( GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 );
}
SetCameraMode(camera, .CAMERA_FIRST_PERSON); // Set a first person camera mode
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
//----------------------------------------------------------------------------------
UpdateCamera(*camera); // Update camera
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
defer EndDrawing();
ClearBackground(RAYWHITE);
{
BeginMode3D(camera);
defer EndMode3D();
DrawPlane(Vector3.{ 0.0, 0.0, 0.0 }, Vector2.{ 32.0, 32.0 }, LIGHTGRAY); // Draw ground
DrawCube(Vector3.{ -16.0, 2.5, 0.0 }, 1.0, 5.0, 32.0, BLUE); // Draw a blue wall
DrawCube(Vector3.{ 16.0, 2.5, 0.0 }, 1.0, 5.0, 32.0, LIME); // Draw a green wall
DrawCube(Vector3.{ 0.0, 2.5, 16.0 }, 32.0, 5.0, 1.0, GOLD); // Draw a yellow wall
// Draw some cubes around
for i: 0..MAX_COLUMNS - 1 {
DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i]);
DrawCubeWires(positions[i], 2.0, heights[i], 2.0, MAROON);
}
}
DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5));
DrawRectangleLines( 10, 10, 220, 70, BLUE);
DrawText("First person camera default controls:", 20, 20, 10, BLACK);
DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY);
//----------------------------------------------------------------------------------
}
}