NAP
Public Member Functions | List of all members
ZoomPanControllerInstance Class Reference

#include <zoompancontroller.h>

Public Member Functions

 ZoomPanControllerInstance (EntityInstance &entity, Component &resource)
 
virtual bool init (utility::ErrorState &errorState) override
 
virtual void update (double deltaTime) override
 
void frameTexture (const Texture2D &texture, nap::TransformComponentInstance &ioTextureTransform, float scale=1.0f)
 
void frameTexture (const glm::vec2 &textureSize, nap::TransformComponentInstance &ioTextureTransform, float scale=1.0f)
 
void reset ()
 
float getZoomLevel () const
 
nap::OrthoCameraComponentInstancegetCamera ()
 
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
 
nap::EntityInstancegetEntityInstance () const
 
nap::ComponentgetComponent () const
 
template<typename T >
T * getComponent () const
 
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

2D texture zoom and pan camera controller.

Allows for freely moving around and zooming into a 2D texture using an orthographic camera. Use the 'frameTexture' function to adjust the scale and position of your texture, ensuring it fits perfectly in the viewport.

This component updates the projection and transform matrix of an orthographic camera, based on pointer input events. It therefore requires the following components to be present on the same entity.

After calling 'frameTexture':

Not calling 'frameTexture' allows you to use your own texture scale and orthographic camera settings. Note that for the component to work properly it can't have any parent transform, if it does the the result is undefined.

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

Constructor & Destructor Documentation

◆ ZoomPanControllerInstance()

ZoomPanControllerInstance ( EntityInstance entity,
Component resource 
)

Member Function Documentation

◆ frameTexture() [1/2]

void frameTexture ( const glm::vec2 &  textureSize,
nap::TransformComponentInstance ioTextureTransform,
float  scale = 1.0f 
)

Scales and positions a texture to perfectly fit in the viewport. The adjusted transform can be applied to a uniform 1m2 (default) plane to position it correctly in this frame. The current zoom and pan levels are reset and the camera position, viewport, and clipping planes are adjusted to capture the texture:

- The texture is placed at a depth of (z)0, with dimensions adjusted to fit in the current viewport.
- The camera is placed at (xy)0 at a depth of (z)5.
- The camera planes will match the size of the viewport.
- The near and far clipping planes are setup to include the framed texture.

Avoid calling this function if you need to manually control the orthographic camera.

Parameters
textureSizesize of the texture
ioTextureTransformthe texture transform to update
scalemultiplication factor, defaults to 1 (perfect fit)

◆ frameTexture() [2/2]

void frameTexture ( const Texture2D texture,
nap::TransformComponentInstance ioTextureTransform,
float  scale = 1.0f 
)

Scales and positions a texture to perfectly fit in the viewport. The adjusted transform can be applied to a uniform 1m2 (default) plane to position it correctly in this frame. The current zoom and pan levels are reset and the camera position, viewport, and clipping planes are adjusted to capture the texture:

- The texture is placed at a depth of (z)0, with dimensions adjusted to fit in the current viewport.
- The camera is placed at (xy)0 at a depth of (z)5.
- The camera planes will match the size of the viewport.
- The near and far clipping planes are setup to include the framed texture.

Avoid calling this function if you need to manually control the orthographic camera.

Parameters
textureSizesize of the texture
ioTextureTransformthe texture transform to update
scalemultiplication factor, defaults to 1 (perfect fit)

◆ getCamera()

Returns
orthographic camera

◆ getZoomLevel()

float getZoomLevel ( ) const

Returns the current zoom level, where 0 = completely zoomed in, 1 = framed in window and anything higher is zoomed out.

Returns
current zoom level.

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initializes the component based on the resource.

Parameters
errorStatethe error message when initialization fails
Returns
if the component initialized successfully

Reimplemented from ComponentInstance.

◆ reset()

void reset ( )

Updates the camera planes to match size of the viewport.

◆ update()

virtual void update ( double  deltaTime)
overridevirtual

update pancontrollerInstance. This is called by NAP core automatically

Parameters
deltaTimetime in between frames in seconds

Reimplemented from ComponentInstance.