Trace Engine
A Raycaster Engine in C
Loading...
Searching...
No Matches
trc_camera.c File Reference
#include "trc_camera.h"
#include <math.h>
#include "log.h"
#include "game_state.h"
#include "map.h"
#include "graphics.h"
#include "trc_transform.h"
#include "trc_world_position.h"

Macros

#define CAM_DEFAULT_COLLISION_SIZE   20
 
#define CAM_DEFAULT_INIT_ANGLE   0
 
#define P_COLOR   COLOR_YELLOW
 

Functions

trc_world_position_t get_camera_position (void)
 
float get_camera_angle (void)
 
trc_world_position_t get_camera_direction (void)
 
void move_camera_sliding (const trc_world_position_t velocity)
 
void move_camera_colliding (const trc_world_position_t velocity)
 
void rotate_camera (const float rotation_delta)
 
void reset_camera_info (void)
 
void draw_camera (void)
 
void open_door (void)
 

Variables

trc_transform_t trc_camera
 

Macro Definition Documentation

◆ CAM_DEFAULT_COLLISION_SIZE

#define CAM_DEFAULT_COLLISION_SIZE   20

Initial collision size for camera (check MAP_CELL_SIZE for size relation)

◆ CAM_DEFAULT_INIT_ANGLE

#define CAM_DEFAULT_INIT_ANGLE   0

Initial camera vision angle (0 means bro is seeing right)

◆ P_COLOR

#define P_COLOR   COLOR_YELLOW

The camera is yellow because reasons

Function Documentation

◆ draw_camera()

void draw_camera ( void  )

Draw the camera in the screen in the actual camera position.

Note
The camera is represented as a yellow dot with a line in front of him. This line represent the face of the camera.

◆ get_camera_angle()

float get_camera_angle ( void  )

Returns the current camera angle of vision (in radians)

◆ get_camera_direction()

trc_world_position_t get_camera_direction ( void  )

Returns the current camera direction, in the form of a normalized vector

◆ get_camera_position()

trc_world_position_t get_camera_position ( void  )

Returns the current camera position

◆ move_camera_colliding()

void move_camera_colliding ( const trc_world_position_t  velocity)

Moves the camera with the given velocity, will stop fucking moving if a collision is detected

◆ move_camera_sliding()

void move_camera_sliding ( const trc_world_position_t  velocity)

Moves the camera with the given velocity, will slide along the walls if a collision is detected

◆ open_door()

void open_door ( void  )

Check if is a door infront of the camera. If that's true, opens the door

◆ reset_camera_info()

void reset_camera_info ( void  )

Sets the camera info to the current level

Note
If you change or reset the level, call this function to update the camera position, velocity, etc

◆ rotate_camera()

void rotate_camera ( const float  rotation_delta)

Rotates the camera adding the given delta to the current camera angle

Note
The sign of rotation_delta determines the direction of the rotation

Variable Documentation

◆ trc_camera

trc_transform_t trc_camera

The camera info, like the position and actual direction of movement