Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CCameraBrain Class Reference

This is an object class that makes it easier to switch between multiple cameras. More...

#include <Camera/CCameraBrain.h>

Inheritance diagram for Skylicht::CCameraBrain:
Skylicht::CComponentSystem Skylicht::ILateUpdate Skylicht::IActivatorObject

Public Member Functions

virtual void initComponent ()
virtual void updateComponent ()
virtual void lateUpdate ()
void setTargetCamera (CCamera *cam, float blendTarget=1.0f)
 Sets a new target camera and initiates blending.
CCameragetCamera ()
 Gets the main camera component controlled by this brain.
CCameragetTargetCamera ()
 Gets the current target camera.
void setBlendValue (float value)
 Manually sets the blending factor.
float getBlendValue ()
 Gets the current blending factor.
const core::vector3df & getPosition ()
 Gets the current blended world position.
const core::vector3df & getLookAt ()
 Gets the current blended forward look direction.
const core::vector3df & getUp ()
 Gets the current blended 'up' vector.
Public Member Functions inherited from Skylicht::CComponentSystem
const char * getName ()
virtual void reset ()
virtual void startComponent ()
virtual void endUpdate ()
virtual void onEnable (bool b)
virtual void onUpdateCullingLayer (u32 mask)
virtual CObjectSerializablecreateSerializable ()
virtual void loadSerializable (CObjectSerializable *object)
void setEnable (bool b)
bool isEnable ()
CGameObject * getGameObject ()
void setEnableSerializable (bool b)
bool isSerializable ()
void addLinkComponent (CComponentSystem *comp)
void removeAllLink ()
Public Member Functions inherited from Skylicht::IActivatorObject
virtual ~IActivatorObject ()
 Virtual destructor for polymorphic activator objects.

Protected Attributes

CCameram_camera
 Pointer to the main camera component being controlled.
CCameram_targetCamera
 The target camera to blend towards.
float m_blend
 Current blending factor (0 to 1).
core::vector3df m_position
 Current blended world position.
core::vector3df m_lookAt
 Current blended forward direction.
core::vector3df m_upVector
 Current blended up direction.
float m_viewFov
 Current blended FOV.
float m_viewNear
 Current blended near plane.
float m_viewFar
 Current blended far plane.
core::vector3df m_lastPosition
 Last position before starting a new blend.
core::vector3df m_lastLookAt
 Last forward direction before starting a new blend.
core::vector3df m_lastUpVector
 Last up direction before starting a new blend.
float m_lastFov
 Last FOV before starting a new blend.
float m_lastNear
 Last near plane before starting a new blend.
float m_lastFar
 Last far plane before starting a new blend.
Protected Attributes inherited from Skylicht::CComponentSystem
CGameObject * m_gameObject
bool m_enable
bool m_serializable
std::vector< CComponentSystem * > m_linkComponent

Additional Inherited Members

Static Public Member Functions inherited from Skylicht::CComponentSystem
static int useComponent (CComponentSystem *used)
Protected Member Functions inherited from Skylicht::CComponentSystem
void setOwner (CGameObject *obj)

Detailed Description

This is an object class that makes it easier to switch between multiple cameras.

You can use CTween and CTweenManager to make the camera transitions smoother.

Example of setting up a brain camera

// camera 1
CGameObject* cam1Obj = zone->createEmptyObject();
CCamera* camera1 = cam1Obj->addComponent<CCamera>();
camera1->setPosition(core::vector3df(0.0f, 1.8f, 3.0f));
camera1->lookAt(core::vector3df(0.0f, 1.0f, 0.0f), Transform::Oy);
// camera 2
CGameObject* cam2Obj = zone->createEmptyObject();
CCamera* camera2 = cam2Obj->addComponent<CCamera>();
camera2->setPosition(core::vector3df(3.0f, 1.8f, 3.0f));
camera2->lookAt(core::vector3df(0.0f, 1.0f, 0.0f), Transform::Oy);
// create main camera
CGameObject* cameraMainObj = zone->createEmptyObject();
CCamera* cameraMain = cameraMainObj->addComponent<CCamera>();
CCameraBrain* g_cameraBrain = cameraMainObj->addComponent<CCameraBrain>();
setTargetCamera(camera1, 0.0f);
setTargetCamera(camera2, 5000.0f);
void setTargetCamera(CCamera* cam, float blendDuration)
{
// focus new camera
g_cameraBrain->setTargetCamera(cam, blendDuration <= 0.0f ? 1.0f: 0.0f);
if (g_cameraBlendTween)
{
g_cameraBlendTween->stop();
g_cameraBlendTween = NULL;
}
if (blendDuration > 0.0f)
{
// create a tween animation from 0.0 to 1.0 over a duration of blendDuration
g_cameraBlendTween = new CTweenFloat(0.0f, 1.0f, blendDuration);
g_cameraBlendTween->setEase(EaseOutCubic);
g_cameraBlendTween->OnUpdate = [&](CTween* tween) { g_cameraBrain->setBlendValue(g_cameraBlendTween->getValue()); };
g_cameraBlendTween->OnFinish = [&](CTween* tween) { g_cameraBlendTween = NULL; };
CTweenManager::getInstance()->addTween(g_cameraBlendTween);
}
// you can call force update a frame
g_cameraBrain->lateUpdate();
}
void setTargetCamera(CCamera *cam, float blendTarget=1.0f)
Sets a new target camera and initiates blending.
This is an object class used to set up the camera, including its position, viewing angle,...
Definition CCamera.h:70
void lookAt(const core::vector3df &position, const core::vector3df &target, const core::vector3df &up)
Configures the camera to look at a target from a specific position.
void setPosition(const core::vector3df &position)
Sets the world position of the camera.
Definition CTweenFloat.h:8
Definition CTween.h:11
See also
CCamera

Member Function Documentation

◆ getBlendValue()

float Skylicht::CCameraBrain::getBlendValue ( )
inline

Gets the current blending factor.

Returns
Factor (0 to 1).

◆ getCamera()

CCamera * Skylicht::CCameraBrain::getCamera ( )
inline

Gets the main camera component controlled by this brain.

Returns
Pointer to CCamera.

◆ getLookAt()

const core::vector3df & Skylicht::CCameraBrain::getLookAt ( )
inline

Gets the current blended forward look direction.

Returns
Direction vector.

◆ getPosition()

const core::vector3df & Skylicht::CCameraBrain::getPosition ( )
inline

Gets the current blended world position.

Returns
Position vector.

◆ getTargetCamera()

CCamera * Skylicht::CCameraBrain::getTargetCamera ( )
inline

Gets the current target camera.

Returns
Pointer to CCamera.

◆ getUp()

const core::vector3df & Skylicht::CCameraBrain::getUp ( )
inline

Gets the current blended 'up' vector.

Returns
Up vector.

◆ initComponent()

virtual void Skylicht::CCameraBrain::initComponent ( )
virtual

◆ lateUpdate()

virtual void Skylicht::CCameraBrain::lateUpdate ( )
virtual

Implements Skylicht::ILateUpdate.

◆ setBlendValue()

void Skylicht::CCameraBrain::setBlendValue ( float value)
inline

Manually sets the blending factor.

Parameters
valueBlending factor (0.0 = old camera, 1.0 = target camera).

◆ setTargetCamera()

void Skylicht::CCameraBrain::setTargetCamera ( CCamera * cam,
float blendTarget = 1.0f )

Sets a new target camera and initiates blending.

Parameters
camPointer to the target camera.
blendTargetInitial blend value (default: 1.0, immediate switch).

◆ updateComponent()

virtual void Skylicht::CCameraBrain::updateComponent ( )
virtual

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