Camera - DigiPen-Faculty/DigiPen-Graphics-Library GitHub Wiki
This file contains information about all the functions in the Camera section.
Table Of Contents
- DGL_Camera_GetPosition
- DGL_Camera_GetRotation
- DGL_Camera_GetZoom
- DGL_Camera_ScreenCoordToWorld
- DGL_Camera_SetPosition
- DGL_Camera_SetRotation
- DGL_Camera_SetZoom
DGL_Camera_GetPosition
Returns the current X and Y position of the camera, in world coordinates.
Function
DGL_Vec2 DGL_Camera_GetPosition(void)
Parameters
- This function has no parameters.
Return
- DGL_Vec2 - This will contain the X and Y world coordinates of the camera.
Example
if (DGL_Input_KeyDown('W'))
{
DGL_Vec2 pos = DGL_Camera_GetPosition();
pos.y += 2.0f;
DGL_Camera_SetPosition(&pos);
}
Related
DGL_Camera_GetRotation
Returns the current rotation of the camera, in radians.
Function
float DGL_Camera_GetRotation(void)
Parameters
- This function has no parameters.
Return
- float - The current rotation of the camera, in radians.
Example
if (DGL_Input_KeyDown(VK_RIGHT))
{
float rotation = DGL_Camera_GetRotation();
rotation += 0.2f;
DGL_Camera_SetRotation(rotation);
}
Related
DGL_Camera_GetZoom
Returns the current zoom level of the camera.
Function
float DGL_Camera_GetZoom(void)
Parameters
- This function has no parameters.
Return
- float - The current zoom level of the DGL camera.
Example
if (DGL_Input_KeyDown(VK_UP))
{
float zoom = DGL_Camera_GetZoom();
zoom += 0.01f;
DGL_Camera_SetZoom(zoom);
}
Related
DGL_Camera_ScreenCoordToWorld
Takes a position in screen coordinates and returns the equivalent in world coordinates.
Function
DGL_Vec2 DGL_Camera_ScreenCoordToWorld(const DGL_Vec2* position)
Parameters
- position (const DGL_Vec2*) - The address of a DGL_Vec2 variable containing the screen coordinates that will be translated into world coordinates.
Return
- DGL_Vec2 - This will contain the equivalent world coordinates.
Example
DGL_Vec2 mouseScreen = DGL_Input_GetMousePosition();
DGL_Vec2 mouseWorld = DGL_Camera_ScreenCoordToWorld(&mouseScreen);
Related
DGL_Camera_SetPosition
Sets the position of the camera, in world coordinates.
Function
void DGL_Camera_SetPosition(const DGL_Vec2* position)
Parameters
- position (const DGL_Vec2*) - The address of a DGL_Vec2 variable containing the world position to move the camera to.
Return
- This function does not return anything.
Example
if (DGL_Input_KeyDown('W'))
{
DGL_Vec2 pos = DGL_Camera_GetPosition();
pos.y += 2.0f;
DGL_Camera_SetPosition(&pos);
}
Related
DGL_Camera_SetRotation
Sets the rotation of the camera, using radians.
Function
void DGL_Camera_SetRotation(float radians)
Parameters
- radians (float) - The value to set the camera rotation to.
Return
- This function does not return anything.
Example
if (DGL_Input_KeyDown(VK_RIGHT))
{
float rotation = DGL_Camera_GetRotation();
rotation += 0.2f;
DGL_Camera_SetRotation(rotation);
}
Related
DGL_Camera_SetZoom
Sets the zoom level of the camera. Default is 1.0. Smaller values will move the camera in (objects look larger) and larger values will move it out (objects look smaller).
Function
void DGL_Camera_SetZoom(float zoom)
Parameters
- zoom (float) - The value to set the camera zoom to.
Return
- This function does not return anything.
Example
if (DGL_Input_KeyDown(VK_UP))
{
float zoom = DGL_Camera_GetZoom();
zoom += 0.01f;
DGL_Camera_SetZoom(zoom);
}