sphore 0.0.1
SPH openGL rendering engine

src/camera.c File Reference

Code for managing a camera. More...

#include "camera.h"
#include <stdlib.h>
#include <math.h>

Data Structures

struct  _camera
 Internal storage for a camera. More...

Functions

void _matrix4_product (float *result, float *A, float *B)
 An internal function that calculates a matrix product.
camera_tcamera_create ()
 Creates a new camera object.
void camera_destroy (camera_t *c)
 Cleans up a camera object.
void camera_reset (camera_t *cam)
 Resets the position and rotation of the camera to default.
void camera_translate (camera_t *cam, float x, float y, float z)
 Translate the camera.
void camera_rotate (camera_t *cam, float theta, float x, float y, float z)
 Rotates the camera.
const float * camera_get_matrix (camera_t *cam)
 Returns the matrix representation of the camera.
float * camera_get_inverse_rotation_matrix (camera_t *cam)
 Returns a new matrix representing the inverse of the camera rotation.
void camera_set_position (camera_t *cam, float x, float y, float z)
 Sets the camera's position in absolute coordinants.

Detailed Description

Code for managing a camera.


Function Documentation

void _matrix4_product ( float *  result,
float *  A,
float *  B 
)

An internal function that calculates a matrix product.

Parameters:
[out]resultThe result is stored here. It must be an array of length 16.
[in]AThe matrix on the left side of the multiplication.
[in]BThe matrix on the right side of the multiplication.
camera_t* camera_create ( void  )

Creates a new camera object.

The camera should be cleaned up with camera_destroy. The camera is set to the default position.

Returns:
A pointer to the new camera
void camera_destroy ( camera_t cam)

Cleans up a camera object.

Frees the memory used by a camera object.

Parameters:
[in]camThe camera to destroy.
float* camera_get_inverse_rotation_matrix ( camera_t cam)

Returns a new matrix representing the inverse of the camera rotation.

This array must be subsequently be freed!

Parameters:
[in]camThe camera to get the inverse from.
Returns:
A pointer to an array representing the 4x4 homogoneous matrix.
const float* camera_get_matrix ( camera_t cam)

Returns the matrix representation of the camera.

Parameters:
[in]camThe camera to get the matrix for.
Returns:
The homogenous matrix representing the transform.
void camera_reset ( camera_t cam)

Resets the position and rotation of the camera to default.

The default position is at the origin, looking in the negative z direction.

Parameters:
[in]camThe camera to reset.
void camera_rotate ( camera_t cam,
float  theta,
float  x,
float  y,
float  z 
)

Rotates the camera.

Rotates the camera around the specified axis.

Parameters:
[in]camThe camera to rotate.
[in]thetaThe angle to rotate through (in radians).
[in]xThe component of the axis of rotation in the x direction.
[in]yThe component of the axis of rotation in the y direction.
[in]zThe component of the axis of rotation in the z direction.
void camera_set_position ( camera_t cam,
float  x,
float  y,
float  z 
)

Sets the camera's position in absolute coordinants.

Parameters:
[in]camThe camera to set the position of.
[in]xThe x coordinant of the new position.
[in]yThe y coordinant of the new position.
[in]zThe z coordinant of the new position.
void camera_translate ( camera_t cam,
float  x,
float  y,
float  z 
)

Translate the camera.

Moves the camera to (x, y, z), in the frame of reference of the camera.

Parameters:
[in]camThe camera to move.
[in]xThe x-coordinant to move to.
[in]yThe y-coordinant to move to.
[in]zThe z-coordinant to move to.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines