NAP
Public Member Functions | List of all members
CameraComponentInstance Class Referenceabstract

#include <cameracomponent.h>

Public Member Functions

 CameraComponentInstance (EntityInstance &entity, Component &resource)
 
virtual const glm::mat4 & getProjectionMatrix () const =0
 
virtual const glm::mat4 getViewMatrix () const =0
 
virtual void setRenderTargetSize (const glm::ivec2 &size)
 
glm::vec3 screenToWorld (const glm::vec3 &screenPos, const math::Rect &viewport)
 
glm::vec3 worldToScreen (const glm::vec3 &worldPos, const math::Rect &viewport)
 
glm::vec3 rayFromScreen (const glm::vec2 &screenPos, const math::Rect &viewport)
 
const glm::ivec2 & getRenderTargetSize () const
 
virtual float getNearClippingPlane () const =0
 
virtual float getFarClippingPlane () const =0
 
virtual const glm::mat4 & getRenderProjectionMatrix () const =0
 
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
 
virtual void update (double deltaTime)
 
nap::EntityInstancegetEntityInstance () const
 
nap::ComponentgetComponent () const
 
template<typename T >
T * getComponent () const
 
virtual bool init (utility::ErrorState &errorState)
 
virtual bool init (utility::ErrorState &errorState)
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Description

Base class for perspective and orthographic cameras.

Inheritance diagram for CameraComponentInstance:
[legend]
Collaboration diagram for CameraComponentInstance:
[legend]

Constructor & Destructor Documentation

◆ CameraComponentInstance()

CameraComponentInstance ( EntityInstance entity,
Component resource 
)

Member Function Documentation

◆ getFarClippingPlane()

virtual float getFarClippingPlane ( ) const
pure virtual
Returns
the far clipping plane of the camera

Implemented in OrthoCameraComponentInstance, and PerspCameraComponentInstance.

◆ getNearClippingPlane()

virtual float getNearClippingPlane ( ) const
pure virtual
Returns
the near clipping plane of the camera

Implemented in OrthoCameraComponentInstance, and PerspCameraComponentInstance.

◆ getProjectionMatrix()

virtual const glm::mat4& getProjectionMatrix ( ) const
pure virtual

Returns the matrix that is used to transform a 3d scene in to a 2d projection.

Returns
default camera projection matrix

Implemented in OrthoCameraComponentInstance, and PerspCameraComponentInstance.

◆ getRenderProjectionMatrix()

virtual const glm::mat4& getRenderProjectionMatrix ( ) const
pure virtual

Returns the matrix that is used to transform a 3d scene in to a 2d projection by the renderer. This can be different from the default if the renderer uses a different coordinate system. Use this matrix to transform a 3d scene in to a 2d projection.

Returns
the projection matrix used by the renderer

Implemented in OrthoCameraComponentInstance, and PerspCameraComponentInstance.

◆ getRenderTargetSize()

const glm::ivec2& getRenderTargetSize ( ) const
Returns
RenderTarget size

◆ getViewMatrix()

virtual const glm::mat4 getViewMatrix ( ) const
pure virtual

Returns the world space position and rotation of the camera in 3D space.

Returns
camera view matrix

Implemented in OrthoCameraComponentInstance, and PerspCameraComponentInstance.

◆ rayFromScreen()

glm::vec3 rayFromScreen ( const glm::vec2 &  screenPos,
const math::Rect viewport 
)

Computes a ray directed outwards from the camera based on a screen space position. The ray is normalized.

Parameters
screenPoshorizontal and vertical screen coordinates: where 0, 0 is the lower left corner
viewportrectangle that defines the viewport
Returns
a normalized ray pointing outwards from the camera in to the scene

◆ screenToWorld()

glm::vec3 screenToWorld ( const glm::vec3 &  screenPos,
const math::Rect viewport 
)

Maps a pixel coordinate to a world space coordinate using the camera project and view matrix The z component is generally acquired by sampling the window depth buffer. When screenPos.z has a value of 0 the result is relative to this camera, ie: the return value is the location of this camera in the world.

Parameters
screenPoswindow coordinates, where 0,0 is the lower left corner
viewportrectangle that defines the viewport
Returns
converted screen to world space pixel coordinate

◆ setRenderTargetSize()

virtual void setRenderTargetSize ( const glm::ivec2 &  size)
virtual

This is used by derived classes for extracting information like aspect ratio or the the size of the screen, in case of orthographic camera's (where pixels coordinates can be used).

Parameters
sizesize of the render target in pixels.

Reimplemented in OrthoCameraComponentInstance, and PerspCameraComponentInstance.

◆ worldToScreen()

glm::vec3 worldToScreen ( const glm::vec3 &  worldPos,
const math::Rect viewport 
)

Maps a world space coordinate to a screen space coordinate using the camera projection and view matrix

Parameters
worldPosthe point position in world space
viewportrectangle that defines the viewport
Returns
the converted world to screen space coordinate