![]() |
Jopnal Engine
alpha 0.4
Simple Component Based 2D/3D Game Engine
|
#include <Camera.hpp>
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... | |
Camera & | setRenderMask (const uint32 mask) |
Set the render mask. More... | |
uint32 | getRenderMask () const |
Get the render mask. More... | |
Camera & | setProjectionMode (const Projection mode) |
Set the projection mode. More... | |
Projection | getProjectionMode () const |
Get the projection mode. More... | |
Camera & | setClippingPlanes (const float clipNear, const float clipFar) |
Set the near and far clipping planes. More... | |
const ClippingPlanes & | getClippingPlanes () const |
Get the values of the clipping planes. More... | |
Camera & | setSize (const glm::vec2 &size) |
Brief set the size of the projection. More... | |
Camera & | setSize (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... | |
Camera & | setAspectRatio (const float ratio) |
Set the aspect ratio. More... | |
float | getAspectRatio () const |
Get the aspect ratio. More... | |
Camera & | setFieldOfView (const float fovY) |
Set the vertical field of view. More... | |
float | getFieldOfView () const |
Get the field of view value. More... | |
Camera & | setViewport (const glm::vec2 &start, const glm::vec2 &end) |
Set the view port. More... | |
const ViewPort & | getViewport () const |
Get the view port. More... | |
void | applyViewport (const RenderTarget &mainTarget) const |
Apply this camera's view port. More... | |
RenderTexture & | getRenderTexture () |
Get the internal render texture. More... | |
const RenderTexture & | getRenderTexture () 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... | |
![]() | |
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< Object > | getObject () |
Get the object this component is bound to. More... | |
WeakReference< const Object > | getObject () 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... | |
![]() | |
Component (Object &object, const uint32 ID) | |
Constructor. More... | |
Component (const Component &other, Object &newObj) | |
Copy constructor. More... | |
Definition at line 39 of file Camera.hpp.
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.
|
strong |
Projection mode
Enumerator | |
---|---|
Orthographic |
Usually used in 2D rendering. |
Perspective |
Usually used in 3D rendering. |
Definition at line 69 of file Camera.hpp.
jop::Camera::Camera | ( | Object & | object, |
Renderer & | renderer, | ||
const Projection | mode | ||
) |
Constructor.
object | The object this camera will be bound to |
renderer | Reference to the renderer |
mode | The initial projection mode |
|
override |
Destructor.
void jop::Camera::applyViewport | ( | const RenderTarget & | mainTarget | ) | const |
Apply this camera's view port.
mainTarget | The 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
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.
float jop::Camera::getFieldOfView | ( | ) | const |
Get 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
mouseCoords | Mouse coordinates. Origin is assumed to be in the upper left corner |
target | The render target (main usually). This is used to get the correct view port dimensions |
const glm::mat4& jop::Camera::getProjectionMatrix | ( | ) | const |
Get the projection matrix.
Projection jop::Camera::getProjectionMode | ( | ) | const |
Get the projection mode.
uint32 jop::Camera::getRenderMask | ( | ) | const |
Get the render mask.
RenderTexture& jop::Camera::getRenderTexture | ( | ) |
Get the internal render texture.
const RenderTexture& jop::Camera::getRenderTexture | ( | ) | const |
Get the internal render texture.
glm::vec2 jop::Camera::getSize | ( | ) | const |
Get the size of the projection.
In perspective mode the return value is undefined.
const glm::mat4& jop::Camera::getViewMatrix | ( | ) | const |
Get the view matrix.
The matrix will be fetched straight from the object.
const ViewPort& jop::Camera::getViewport | ( | ) | const |
Get the view port.
first = start second = size
|
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.
message | The message |
Reimplemented from jop::Component.
Camera& jop::Camera::setAspectRatio | ( | const float | ratio | ) |
Set the aspect ratio.
This call is only valid in perspective mode.
ratio | The new aspect ratio to be set |
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.
clipNear | The near clipping plane |
clipFar | The far clipping plane |
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.
fovY | The new field of view value |
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.
mode | The mode to be set |
Set the render mask.
mask | The 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)
size | The new size of the projection |
Camera& jop::Camera::setSize | ( | const float | x, |
const float | y | ||
) |
Brief set the size of the projection.
x | The width |
y | The height |
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.
start | The start coordinates |
end | The end coordinates |