Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
jop::Camera Class Reference

#include <Camera.hpp>

Inheritance diagram for jop::Camera:
jop::Component

Classes

union  ProjectionData
 

Public Types

enum  Projection { Projection::Orthographic, Projection::Perspective }
 
typedef std::pair< float, float > ClippingPlanes
 
typedef std::pair< glm::vec2, glm::vec2 > ViewPort
 

Public Member Functions

 Camera (Object &object, Renderer &renderer, const Projection mode)
 Constructor. More...
 
 ~Camera () override
 Destructor. More...
 
const glm::mat4 & getProjectionMatrix () const
 Get the projection matrix. More...
 
const glm::mat4 & getViewMatrix () const
 Get the view matrix. More...
 
CamerasetRenderMask (const uint32 mask)
 Set the render mask. More...
 
uint32 getRenderMask () const
 Get the render mask. More...
 
CamerasetProjectionMode (const Projection mode)
 Set the projection mode. More...
 
Projection getProjectionMode () const
 Get the projection mode. More...
 
CamerasetClippingPlanes (const float clipNear, const float clipFar)
 Set the near and far clipping planes. More...
 
const ClippingPlanesgetClippingPlanes () const
 Get the values of the clipping planes. More...
 
CamerasetSize (const glm::vec2 &size)
 Brief set the size of the projection. More...
 
CamerasetSize (const float x, const float y)
 Brief set the size of the projection. More...
 
glm::vec2 getSize () const
 Get the size of the projection. More...
 
CamerasetAspectRatio (const float ratio)
 Set the aspect ratio. More...
 
float getAspectRatio () const
 Get the aspect ratio. More...
 
CamerasetFieldOfView (const float fovY)
 Set the vertical field of view. More...
 
float getFieldOfView () const
 Get the field of view value. More...
 
CamerasetViewport (const glm::vec2 &start, const glm::vec2 &end)
 Set the view port. More...
 
const ViewPortgetViewport () const
 Get the view port. More...
 
void applyViewport (const RenderTarget &mainTarget) const
 Apply this camera's view port. More...
 
RenderTexturegetRenderTexture ()
 Get the internal render texture. More...
 
const RenderTexturegetRenderTexture () const
 Get the internal render texture. More...
 
glm::vec3 getPickRay (const glm::vec2 &mouseCoords, const RenderTarget &target) const
 Get a ray for mouse picking purposes. More...
 
- Public Member Functions inherited from jop::Component
virtual ~Component ()=0
 Virtual destructor. More...
 
Message::Result sendMessage (const Message &message)
 Send a message to this component. More...
 
virtual void update (const float deltaTime)
 Update function. More...
 
uint32 getID () const
 Get the identifier. More...
 
void setID (const uint32 ID)
 Set the identifier. More...
 
WeakReference< ObjectgetObject ()
 Get the object this component is bound to. More...
 
WeakReference< const ObjectgetObject () const
 Get the object this component is bound to. More...
 
bool isActive () const
 Check if this component is active. More...
 
void removeSelf ()
 Remove this component from its object. More...
 

Protected Member Functions

Message::Result receiveMessage (const Message &message) override
 Receive a message. More...
 
- Protected Member Functions inherited from jop::Component
 Component (Object &object, const uint32 ID)
 Constructor. More...
 
 Component (const Component &other, Object &newObj)
 Copy constructor. More...
 

Detailed Description

Definition at line 39 of file Camera.hpp.

Member Typedef Documentation

typedef std::pair<float, float> jop::Camera::ClippingPlanes

Definition at line 47 of file Camera.hpp.

typedef std::pair<glm::vec2, glm::vec2> jop::Camera::ViewPort

Definition at line 48 of file Camera.hpp.

Member Enumeration Documentation

Projection mode

Enumerator
Orthographic 

Usually used in 2D rendering.

Perspective 

Usually used in 3D rendering.

Definition at line 69 of file Camera.hpp.

Constructor & Destructor Documentation

jop::Camera::Camera ( Object object,
Renderer renderer,
const Projection  mode 
)

Constructor.

Parameters
objectThe object this camera will be bound to
rendererReference to the renderer
modeThe initial projection mode
jop::Camera::~Camera ( )
override

Destructor.

Member Function Documentation

void jop::Camera::applyViewport ( const RenderTarget mainTarget) const

Apply this camera's view port.

Parameters
mainTargetThe main render target. This will be used to calculate the absolute coordinates
float jop::Camera::getAspectRatio ( ) const

Get the aspect ratio.

In orthographic mode the return value is undefined

Returns
The aspect ratio
const ClippingPlanes& jop::Camera::getClippingPlanes ( ) const

Get the values of the clipping planes.

The first value is the near clipping plane. The second value is the far clipping plane.

Returns
Reference to the internal pair of clipping planes
float jop::Camera::getFieldOfView ( ) const

Get the field of view value.

Returns
The field of view value
glm::vec3 jop::Camera::getPickRay ( const glm::vec2 &  mouseCoords,
const RenderTarget target 
) const

Get a ray for mouse picking purposes.

The resulting ray is normalized

Parameters
mouseCoordsMouse coordinates. Origin is assumed to be in the upper left corner
targetThe render target (main usually). This is used to get the correct view port dimensions
Returns
Normalized ray pointing from camera to the pointed position
const glm::mat4& jop::Camera::getProjectionMatrix ( ) const

Get the projection matrix.

Returns
The projection matrix
Projection jop::Camera::getProjectionMode ( ) const

Get the projection mode.

Returns
The projection mode
uint32 jop::Camera::getRenderMask ( ) const

Get the render mask.

Returns
The render mask
RenderTexture& jop::Camera::getRenderTexture ( )

Get the internal render texture.

Returns
Reference to the render texture
const RenderTexture& jop::Camera::getRenderTexture ( ) const

Get the internal render texture.

Returns
Reference to the render texture
glm::vec2 jop::Camera::getSize ( ) const

Get the size of the projection.

In perspective mode the return value is undefined.

Returns
Size of the projection
const glm::mat4& jop::Camera::getViewMatrix ( ) const

Get the view matrix.

The matrix will be fetched straight from the object.

Returns
The view matrix
const ViewPort& jop::Camera::getViewport ( ) const

Get the view port.

first = start second = size

See also
setViewport
Returns
Reference to the view port
Message::Result jop::Camera::receiveMessage ( const Message message)
overrideprotectedvirtual

Receive a message.

Override this to handle messages sent to this. Don't forget to call the base class' method as well to ensure that the message gets forwarded correctly.

Parameters
messageThe message
Returns
The message result

Reimplemented from jop::Component.

Camera& jop::Camera::setAspectRatio ( const float  ratio)

Set the aspect ratio.

This call is only valid in perspective mode.

Parameters
ratioThe new aspect ratio to be set
This method is exposed as command named setAspectRatio
Camera& jop::Camera::setClippingPlanes ( const float  clipNear,
const float  clipFar 
)

Set the near and far clipping planes.

In perspective projection the clipping planes need to be positive. Otherwise, the projection result is undefined.

Parameters
clipNearThe near clipping plane
clipFarThe far clipping plane
Returns
Reference to self
This method is exposed as command named setClippingPlanes
Camera& jop::Camera::setFieldOfView ( const float  fovY)

Set the vertical field of view.

The minimum value is glm::radians(1) and maximum glm::radians(179). The value will be clamped inside this range.

Parameters
fovYThe new field of view value
Returns
Reference to self
This method is exposed as command named setFieldOfView
Camera& jop::Camera::setProjectionMode ( const Projection  mode)

Set the projection mode.

You need to accompany this call with calls to set the camera properties, as they won't be set to defaults automatically. Failing to set the properties will cause the projection to malfunction.

Parameters
modeThe mode to be set
Returns
Reference to self
This method is exposed as command named setProjectionMode
Camera& jop::Camera::setRenderMask ( const uint32  mask)

Set the render mask.

Parameters
maskThe new mask to set
Camera& jop::Camera::setSize ( const glm::vec2 &  size)

Brief set the size of the projection.

In perspective mode this call is equal to calling setAspectRatio(size.x / size.y)

Parameters
sizeThe new size of the projection
Returns
Reference to self
Camera& jop::Camera::setSize ( const float  x,
const float  y 
)

Brief set the size of the projection.

Parameters
xThe width
yThe height
Returns
Reference to self
This method is exposed as command named setSize
Camera& jop::Camera::setViewport ( const glm::vec2 &  start,
const glm::vec2 &  end 
)

Set the view port.

The values are in relative coordinates. For example, [0.5,0.5] and [1.0,1.0] will select the right half of the screen.

Parameters
startThe start coordinates
endThe end coordinates
Returns
Reference to self
This method is exposed as command named setViewport

The documentation for this class was generated from the following file: