Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
camera.h File Reference

Provides camera functionality for world-to-screen coordinate conversion. More...

#include <vec2.h>
#include <SDL.h>
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  CameraSystem
 

Typedefs

typedef struct CameraSystem CameraSystem
 

Functions

void Camera_UpdatePosition ()
 [PostUpdate] Updates the camera position based on player position and mouse input
 
Vec2 Camera_WorldVecToScreen (Vec2 worldPosition)
 [Utility] Converts world coordinates to screen coordinates
 
Vec2 Camera_ScreenVecToWorld (Vec2 screenPosition)
 [Utility] Converts screen coordinates to world coordinates
 
SDL_Rect Camera_GetWorldViewRect ()
 [Utility] Gets the current view rectangle in world coordinates
 
bool Camera_WorldRectIsOnScreen (SDL_Rect rect)
 [Utility] Checks if a rectangle is visible on screen
 
bool Camera_ScreenRectIsOnScreen (SDL_Rect rect)
 

Variables

CameraSystem camera
 

Detailed Description

Provides camera functionality for world-to-screen coordinate conversion.

The camera system is used to convert between world and screen coordinates. For most objects, the variable "position" is in world coordinates. That's why, the Camera_WorldVecToScreen() function is used in render functions to convert that position to screen coordinates. Vice versa, the Camera_ScreenVecToWorld() function is used to convert screen coordinates to world coordinates.

Author
Mango
Date
2025-03-12

Usage Examples

player.state.position // This is world position
Vec2 screenPosition = Camera_WorldVecToScreen(player.state.position); // screenPosition is now the screen position of the player
// We can now render the player at the screen position
Vec2 Camera_WorldVecToScreen(Vec2 worldPosition)
[Utility] Converts world coordinates to screen coordinates
Definition camera.c:57
PlayerData player
[Data] The player's initial data and configuration
Definition player_data.c:22
PlayerState state
Current player state.
Definition player.h:144
Vec2 position
Current player position.
Definition player.h:89
A 2D vector structure.
Definition vec2.h:81

Typedef Documentation

◆ CameraSystem

typedef struct CameraSystem CameraSystem

Function Documentation

◆ Camera_GetWorldViewRect()

SDL_Rect Camera_GetWorldViewRect ( )

[Utility] Gets the current view rectangle in world coordinates

Returns
SDL_Rect Rectangle representing the camera's view in world space

◆ Camera_ScreenRectIsOnScreen()

bool Camera_ScreenRectIsOnScreen ( SDL_Rect  rect)

◆ Camera_ScreenVecToWorld()

Vec2 Camera_ScreenVecToWorld ( Vec2  screenPosition)

[Utility] Converts screen coordinates to world coordinates

Parameters
screenPositionPosition in screen space
Returns
Vec2 Converted position in world space

◆ Camera_UpdatePosition()

void Camera_UpdatePosition ( )

[PostUpdate] Updates the camera position based on player position and mouse input

◆ Camera_WorldRectIsOnScreen()

bool Camera_WorldRectIsOnScreen ( SDL_Rect  rect)

[Utility] Checks if a rectangle is visible on screen

Parameters
rectRectangle in world coordinates to check
Returns
bool True if the rectangle is at least partially visible, false otherwise

◆ Camera_WorldVecToScreen()

Vec2 Camera_WorldVecToScreen ( Vec2  worldPosition)

[Utility] Converts world coordinates to screen coordinates

Parameters
worldPositionPosition in world space
Returns
Vec2 Converted position in screen space

Variable Documentation

◆ camera

CameraSystem camera
extern