mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 03:57:29 +00:00
ported example 3d camera free (#162)
This commit is contained in:
parent
a2397363aa
commit
a6f94ce655
@ -231,6 +231,11 @@ pub fn build(b: *std.Build) !void {
|
||||
.path = "examples/core/3d_camera_first_person.zig",
|
||||
.desc = "Simple first person demo",
|
||||
},
|
||||
.{
|
||||
.name = "3d_camera_free",
|
||||
.path = "examples/core/3d_camera_free.zig",
|
||||
.desc = "Shows basic 3d camera initialization",
|
||||
},
|
||||
.{
|
||||
.name = "2d_camera_mouse_zoom",
|
||||
.path = "examples/core/2d_camera_mouse_zoom.zig",
|
||||
|
69
examples/core/3d_camera_free.zig
Normal file
69
examples/core/3d_camera_free.zig
Normal file
@ -0,0 +1,69 @@
|
||||
// A raylib port of https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_free.c
|
||||
|
||||
const rl = @import("raylib");
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
pub fn main() anyerror!void {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
||||
defer rl.closeWindow(); // Close window and OpenGL context
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
var camera = rl.Camera{
|
||||
.position = rl.Vector3.init(10, 10, 10),
|
||||
.target = rl.Vector3.init(0, 0, 0),
|
||||
.up = rl.Vector3.init(0, 1, 0),
|
||||
.fovy = 45,
|
||||
.projection = rl.CameraProjection.camera_perspective,
|
||||
};
|
||||
|
||||
const cubePosition = rl.Vector3.init(0, 0, 0);
|
||||
|
||||
rl.disableCursor(); // Limit cursor to relative movement inside the window
|
||||
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
|
||||
// Update
|
||||
//-----------------------------------------------------------------------------
|
||||
camera.update(rl.CameraMode.camera_free);
|
||||
|
||||
if (rl.isKeyPressed(rl.KeyboardKey.key_z)) {
|
||||
camera.target = rl.Vector3.init(0, 0, 0);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//-----------------------------------------------------------------------------
|
||||
rl.beginDrawing();
|
||||
defer rl.endDrawing();
|
||||
|
||||
rl.clearBackground(rl.Color.ray_white);
|
||||
|
||||
{
|
||||
camera.begin();
|
||||
defer camera.end();
|
||||
|
||||
rl.drawCube(cubePosition, 2, 2, 2, rl.Color.red);
|
||||
rl.drawCubeWires(cubePosition, 2, 2, 2, rl.Color.maroon);
|
||||
|
||||
rl.drawGrid(10, 1);
|
||||
}
|
||||
|
||||
rl.drawRectangle(10, 10, 320, 93, rl.Color.fade(rl.Color.sky_blue, 0.5));
|
||||
rl.drawRectangleLines(10, 10, 320, 93, rl.Color.blue);
|
||||
|
||||
rl.drawText("Free camera default controls:", 20, 20, 10, rl.Color.black);
|
||||
rl.drawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.Color.dark_gray);
|
||||
rl.drawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.Color.dark_gray);
|
||||
rl.drawText("- Z to zoom to (0, 0, 0)", 40, 80, 10, rl.Color.dark_gray);
|
||||
//-----------------------------------------------------------------------------
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user