Untitled
Loading...
Searching...
No Matches
camera.h File Reference

Functions for camera. More...

#include "engine_types.h"

Go to the source code of this file.

Functions

mat4 make_ortho (float left, float right, float bottom, float top, float near, float far)
 Makes an 4x4 orthographic matrix.
mat4 make_projection (float fov_deg, float aspect, float near, float far)
 Makes an 4x4 projection matrix.
mat4 make_look_at (Camera *cam, vec3 eye)
 Makes a 4x4 view matrix using camera vectors.
void compute_camera_basis (Camera *cam, float yaw, float pitch, float roll, vec3 world_up)
 Computes camera vectors based on yaw, pitch, and roll.
void update_camera (Skeleton *s, Camera *cam)
 Updates a camera based on a skeleton's current neck and body position.
void update_light_camera (Camera *lcam, Light *light)
 Updates a directional light camera and locks it to texel size.
void resolve_collisions (Camera *current_cam)
 Resolves collisions between camera and geometry, uses player.
void apply_velocity (Camera *current_cam, vec3 move_dir, float dt)
 Applies no-clip mode velocity to player with no gravity applied.
void apply_planet_velocity (Camera *current_cam, vec3 move_dir, float dt)
 Applies normal velocity to player with gravity and friction applied.
void update_skeleton (Skeleton *s, Camera *cam, vec3 vel)
 Moves feet, then solves a skeleton's leg IKs and updates the springs accordingly.
void update_body_from_legs (LegIK *left_leg, LegIK *right_leg, vec3 intended_vel, float dt)
 Calculates velocity based on leg positions and integrates them into the player.
void reset_skeleton (Skeleton *s, vec3 pos)
 Resets a skeleton to be relative to a new position.
bool collision (vec3 proposed, vec3 pts[3], vec3 normal, CollisionPoints *p)

Variables

Camera cam
 This is currently the player cam.

Detailed Description

Functions for camera.

Definition in file camera.h.

Function Documentation

◆ make_ortho()

mat4 make_ortho ( float left,
float right,
float bottom,
float top,
float near,
float far )

Makes an 4x4 orthographic matrix.

Parameters
leftThe left dist.
rightThe right dist.
bottomThe bottom dist.
topThe top dist.
nearThe near plane.
farThe far plane.
Returns
The 4x4 orthographic matrix.

Definition at line 178 of file camera.c.

References mat4::a0, mat4::a1, mat4::a2, mat4::a3, mat4::b0, mat4::b1, mat4::b2, mat4::b3, mat4::c0, mat4::c1, mat4::c2, mat4::c3, mat4::d0, mat4::d1, mat4::d2, mat4::d3, and make_ortho().

Referenced by make_ortho(), render(), and update_light_camera().

◆ make_projection()

mat4 make_projection ( float fov_deg,
float aspect,
float near,
float far )

Makes an 4x4 projection matrix.

Parameters
fov_degFOV in degrees.
aspectThe aspect ratio (W/H).
nearThe near plane.
farThe far plane.
Returns
The 4x4 projection matrix.

Definition at line 220 of file camera.c.

References mat4::a0, mat4::a1, mat4::a2, mat4::a3, mat4::b0, mat4::b1, mat4::b2, mat4::b3, mat4::c0, mat4::c1, mat4::c2, mat4::c3, mat4::d0, mat4::d1, mat4::d2, mat4::d3, M_PI, and make_projection().

Referenced by bake_reflection_probes(), make_projection(), update_camera(), and write_point_light_shadows().

◆ make_look_at()

mat4 make_look_at ( Camera * cam,
vec3 eye )

Makes a 4x4 view matrix using camera vectors.

Parameters
camThe camera to use.
eyeThe camera's "eye" position.
Returns
The 4x4 view matrix.

Definition at line 257 of file camera.c.

References mat4::a0, mat4::a1, mat4::a2, mat4::a3, mat4::b0, mat4::b1, mat4::b2, mat4::b3, mat4::c0, mat4::c1, mat4::c2, mat4::c3, cam, mat4::d0, mat4::d1, mat4::d2, mat4::d3, Camera::forward, make_look_at(), Camera::right, Camera::up, vec3_dot(), vec3::x, vec3::y, and vec3::z.

Referenced by bake_reflection_probes(), make_look_at(), update_camera(), update_light_camera(), and write_point_light_shadows().

◆ compute_camera_basis()

void compute_camera_basis ( Camera * cam,
float yaw,
float pitch,
float roll,
vec3 world_up )

Computes camera vectors based on yaw, pitch, and roll.

Parameters
camThe camera to effect.
yawThe direction left-right in radians.
pitchThe direction up-down in radians.
rollThe rotation in radians.
world_upThe vector to cross with, normally (0,0,1).

Definition at line 135 of file camera.c.

References cam, compute_camera_basis(), Camera::forward, Camera::right, Camera::up, vec3_add(), vec3_cross(), vec3_normalize(), vec3_scale(), vec3_sub(), vec3::x, vec3::y, and vec3::z.

Referenced by bake_reflection_probes(), compute_camera_basis(), update_camera(), and write_point_light_shadows().

◆ update_camera()

◆ update_light_camera()

void update_light_camera ( Camera * lcam,
Light * light )

Updates a directional light camera and locks it to texel size.

Parameters
lcamPointer to the light camera.
lightPointer to directional light.

Definition at line 297 of file camera.c.

References cam, Camera::cam_data, Light::dir, Camera::forward, FOV, M_PI, make_look_at(), make_ortho(), mat4_mul_point(), Skeleton::neck, player, Spring::pos, CamData::proj, RENDER_HEIGHT, RENDER_WIDTH, Camera::right, SHADOW_MAP_FBO, Player::skeleton, Camera::target, Camera::up, update_light_camera(), vec3_add(), vec3_cross(), vec3_dot(), vec3_normalize(), vec3_scale(), vec3_sub(), CamData::view, Framebuffer::w, vec3::x, vec3::y, and vec3::z.

Referenced by main(), and update_light_camera().

◆ resolve_collisions()

◆ apply_velocity()

void apply_velocity ( Camera * current_cam,
vec3 move_dir,
float dt )

Applies no-clip mode velocity to player with no gravity applied.

Parameters
move_dirThe move vectors from input.
dtThe frame time / simulation step time.

Definition at line 659 of file camera.c.

References apply_velocity(), cam, dt, Player::pc, Camera::pitch, player, vec3_normalize(), vec3_scale(), PhysicsComponent::vel, vec3::x, vec3::y, Camera::yaw, and vec3::z.

Referenced by apply_velocity(), and process_input().

◆ apply_planet_velocity()

void apply_planet_velocity ( Camera * current_cam,
vec3 move_dir,
float dt )

Applies normal velocity to player with gravity and friction applied.

Parameters
move_dirThe move vectors from input.
dtThe frame time / simulation step time.

Definition at line 593 of file camera.c.

References apply_planet_velocity(), calculate_stride_governor(), cam, dt, Skeleton::left_leg, Camera::on_ground, Player::pc, Camera::pitch, player, Player::pos, Skeleton::right_leg, Player::skeleton, Player::sprinting, vec3_normalize(), vec3_scale(), PhysicsComponent::vel, vec3::x, vec3::y, Camera::yaw, and vec3::z.

Referenced by apply_planet_velocity().

◆ update_skeleton()

◆ update_body_from_legs()

void update_body_from_legs ( LegIK * left_leg,
LegIK * right_leg,
vec3 intended_vel,
float dt )

Calculates velocity based on leg positions and integrates them into the player.

Also handles falling off ledges by initiating a drop when raycasts to ground fail above a certain margin.

Parameters
left_legLeft leg IK.
right_legRight leg IK.
intended_velThe raw input direction.
dtThe frame time / simulation frame time.

Definition at line 1052 of file camera.c.

References SceneData::bvh_nodes, cam, CAST_VEC, dt, GLOBALS, hit, RayHit::hit, Player::pc, Camera::pitch, player, LegIK::pos, Player::pos, RayHit::pos, raycast_scene(), Globals::scene_data, LegIK::stepping, LegIK::stepping_off_ledge, update_body_from_legs(), vec3_add(), vec3_normalize(), vec3_scale(), vec3_sub(), PhysicsComponent::vel, vec3::x, vec3::y, Camera::yaw, and vec3::z.

Referenced by process_input(), and update_body_from_legs().

◆ reset_skeleton()

void reset_skeleton ( Skeleton * s,
vec3 pos )

Resets a skeleton to be relative to a new position.

Parameters
sThe skeleton to effect.
posThe target position.

Definition at line 963 of file camera.c.

References Spring::angular_vel, Skeleton::left_leg, Skeleton::neck, Skeleton::neck_height, Skeleton::pelvis, Skeleton::pelvis_height, LegIK::pos, Spring::pos, reset_skeleton(), Skeleton::right_leg, LegIK::stepping, Spring::velocity, and vec3::z.

Referenced by process_input(), and reset_skeleton().

◆ collision()

bool collision ( vec3 proposed,
vec3 pts[3],
vec3 normal,
CollisionPoints * p )

Variable Documentation

◆ cam