#include "cam.h" #include CameraInfo main_cam = {0}; void cam_init(void) { rlSetClipPlanes(0.3, 5000); main_cam.cam = (Camera3D) { .position = { 0, 10, -10 }, .target = { 0, 1, 0 }, .up = { 0, 1, 0}, .fovy = 70.0f, .projection = CAMERA_PERSPECTIVE, }; main_cam.update = false; main_cam.mv_speed = 10; main_cam.mv_scale = 1; main_cam.lk_speed = 0.2; } void cam_ctrl_editor(void) { if (!main_cam.update) { return; } Vec3 input_dir = {0}; f32 mv_speed = main_cam.mv_speed; f32 lk_speed = main_cam.lk_speed; if (IsKeyDown(KEY_W)) { input_dir.z += 1; } if (IsKeyDown(KEY_A)) { input_dir.x -= 1; } if (IsKeyDown(KEY_S)) { input_dir.z -= 1; } if (IsKeyDown(KEY_D)) { input_dir.x += 1; } if (IsKeyDown(KEY_Q)) { input_dir.y -= 1; } if (IsKeyDown(KEY_E)) { input_dir.y += 1; } input_dir = Vector3Normalize(input_dir); if (IsKeyDown(KEY_LEFT_SHIFT)) { mv_speed *= 3; } // makes it so you can stop faster than you can speed up f32 ms_amount = GetMouseWheelMove() < 0 ? GetMouseWheelMove() * 1.5 : GetMouseWheelMove() * 0.75; main_cam.mv_scale += ms_amount; main_cam.mv_scale = CLAMP(main_cam.mv_scale, 0.1, 50); mv_speed *= main_cam.mv_scale; mv_speed = CLAMP(mv_speed, 2, 1000); CameraMoveForward(&main_cam.cam, input_dir.z * mv_speed * GetFrameTime(), false); CameraMoveRight(&main_cam.cam, input_dir.x * mv_speed * GetFrameTime(), false); CameraMoveUp(&main_cam.cam, input_dir.y * mv_speed * GetFrameTime()); CameraYaw(&main_cam.cam, -GetMouseDelta().x * lk_speed * GetFrameTime(), 0); CameraPitch(&main_cam.cam, -GetMouseDelta().y * lk_speed * GetFrameTime(), 1, 0, 0); }