Camera
Functions
get_active_camera
Get the currently active camera entity.
EntityHandle get_active_camera(ScriptContext* ctx);
Returns the active camera handle, or NULL_ENTITY_HANDLE if none is set.
set_active_camera
Switch the rendering to a different camera entity.
bool set_active_camera(ScriptContext* ctx, EntityHandle camera);
| Parameter | Type | Description |
|---|---|---|
camera | EntityHandle | Entity with CameraComponent |
Returns true if the entity exists and has a CameraComponent.
get_camera_fov
Get the camera's field of view in degrees.
bool get_camera_fov(ScriptContext* ctx, EntityHandle entity, float* out_fov);
| Parameter | Type | Description |
|---|---|---|
entity | EntityHandle | Camera entity |
out_fov | float* | Output FOV in degrees (caller-allocated) |
set_camera_fov
Set the camera's field of view (clamped to 1-179 degrees).
bool set_camera_fov(ScriptContext* ctx, EntityHandle entity, float fov);
| Parameter | Type | Description |
|---|---|---|
entity | EntityHandle | Camera entity |
fov | float | FOV in degrees |
Example: Camera Switcher
static EntityHandle cam_fps;
static EntityHandle cam_third;
static bool first_person = true;
void OnStart(ScriptContext* ctx) {
cam_fps = ctx->find_entity_by_name(ctx, "FPSCamera");
cam_third = ctx->find_entity_by_name(ctx, "ThirdPersonCamera");
ctx->set_active_camera(ctx, cam_fps);
}
void OnUpdate(ScriptContext* ctx) {
// Toggle camera with Tab
if (ctx->is_key_pressed(ctx, 258)) {
first_person = !first_person;
ctx->set_active_camera(ctx,
first_person ? cam_fps : cam_third);
}
}
Example: Zoom with FOV
static float base_fov = 60.0f;
static float zoom_fov = 20.0f;
void OnUpdate(ScriptContext* ctx) {
EntityHandle cam = ctx->get_active_camera(ctx);
// Hold right-click to zoom
float fov = ctx->is_mouse_button_down(ctx, 1) ? zoom_fov : base_fov;
ctx->set_camera_fov(ctx, cam, fov);
}
Camera Effect Helpers
Razorbill includes pure math utility functions in math_utils.hpp for common camera effects. These can be used in scripts by including the header:
#include <eng/sdk/math_utils.hpp>
smooth_damp
Smoothly interpolates a value toward a target, with velocity tracking for natural deceleration:
float smooth_damp(float current, float target, float& velocity,
float smooth_time, float dt);
Use for smooth camera follow, gradual FOV transitions, or any value that should ease toward a target.
look_at_rotation
Compute a quaternion rotation that points from one position toward another:
void look_at_rotation(const float from[3], const float to[3],
float out_quat[4]);
quat_slerp
Spherical linear interpolation between two quaternion rotations:
void quat_slerp(const float a[4], const float b[4],
float t, float out[4]);
camera_shake
Generate Perlin noise-based camera shake offsets:
void camera_shake(float intensity, float frequency, float time,
float out_offset[3]);
Example: Smooth Follow Camera
static EntityHandle target;
static float smooth_vel_x = 0, smooth_vel_y = 0, smooth_vel_z = 0;
void OnStart(ScriptContext* ctx) {
target = ctx->find_entity_by_name(ctx, "Player");
}
void OnUpdate(ScriptContext* ctx) {
float dt = ctx->get_delta_time();
float target_pos[3], cam_pos[3];
ctx->get_position(target, target_pos);
ctx->get_position(ctx->self, cam_pos);
// Follow with offset, smoothed
float goal_x = target_pos[0];
float goal_y = target_pos[1] + 5.0f;
float goal_z = target_pos[2] + 8.0f;
cam_pos[0] = smooth_damp(cam_pos[0], goal_x, smooth_vel_x, 0.3f, dt);
cam_pos[1] = smooth_damp(cam_pos[1], goal_y, smooth_vel_y, 0.3f, dt);
cam_pos[2] = smooth_damp(cam_pos[2], goal_z, smooth_vel_z, 0.3f, dt);
ctx->set_position(ctx->self, cam_pos);
// Look at target
float look_rot[4];
look_at_rotation(cam_pos, target_pos, look_rot);
ctx->set_rotation(ctx->self, look_rot);
}