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.
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
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
◆ CameraSystem
◆ 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
-
| screenPosition | Position 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
-
| rect | Rectangle 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
-
| worldPosition | Position in world space |
- Returns
- Vec2 Converted position in screen space
◆ camera