Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
CameraController Class Reference

#include <CameraController.hpp>

+ Collaboration diagram for CameraController:

Public Member Functions

void init (float worldWidth, float worldHeight)
 
void update (float dt, float worldWidth, float worldHeight, const WorldState *world)
 
void handleInput ()
 
const Camera3D & camera () const
 
void enterFreecam ()
 
void exitFreecam ()
 
void startFollow (int playerId)
 
void stopFollow ()
 
bool isFreecamActive () const
 
bool isFollowActive () const
 
bool isTransitioning () const
 
int followedPlayerId () const
 

Public Attributes

float orbitalMoveSpeed = 2.0f
 
float freecamMoveSpeed = 5.0f
 
float freecamLookSpeed = 0.002f
 
float followDist = 2.5f
 
float followHeight = 1.8f
 
float followLookOffsetY = 0.5f
 
float transitionDuration = 0.8f
 

Private Types

enum class  Mode { Orbital , Freecam , Follow , FollowLive }
 

Private Member Functions

void _startTransition (Vector3 toPos, Vector3 toTarget, Mode nextMode)
 
void _applyOrbital (float worldWidth, float worldHeight)
 
void _orbitalDest (float worldWidth, float worldHeight, Vector3 &outPos, Vector3 &outTarget) const
 
bool _followTarget (const WorldState *world, Vector3 &outPos, Vector3 &outLookAt) const
 
void _handleOrbitalInput ()
 
void _handleFreecamInput ()
 

Private Attributes

Camera3D _camera = {}
 
Mode _mode = Mode::Orbital
 
float _angle = 0.0f
 
float _height = 5.0f
 
float _savedOrbitalAngle = 0.0f
 
float _savedOrbitalHeight = 5.0f
 
float _freecamYaw = 0.0f
 
float _freecamPitch = 0.0f
 
int _followedPlayerId = -1
 
float _lastWorldWidth = 10.0f
 
float _lastWorldHeight = 10.0f
 
float _transitionT = 1.0f
 
Vector3 _fromPos = {}
 
Vector3 _fromTarget = {}
 
Vector3 _toPos = {}
 
Vector3 _toTarget = {}
 
Mode _pendingMode = Mode::Orbital
 

Detailed Description

Definition at line 9 of file CameraController.hpp.

Member Enumeration Documentation

◆ Mode

enum class CameraController::Mode
strongprivate
Enumerator
Orbital 
Freecam 
Follow 
FollowLive 

Definition at line 40 of file CameraController.hpp.

Member Function Documentation

◆ _applyOrbital()

void CameraController::_applyOrbital ( float  worldWidth,
float  worldHeight 
)
private

Definition at line 40 of file CameraController.cpp.

References _angle, _camera, and _height.

Referenced by init(), and update().

+ Here is the caller graph for this function:

◆ _followTarget()

bool CameraController::_followTarget ( const WorldState world,
Vector3 &  outPos,
Vector3 &  outLookAt 
) const
private

Definition at line 56 of file CameraController.cpp.

References _followedPlayerId, VisualState::angle, followDist, followHeight, followLookOffsetY, WorldState::playerExists(), WorldState::players, and VisualState::pos.

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _handleFreecamInput()

void CameraController::_handleFreecamInput ( )
private

Definition at line 156 of file CameraController.cpp.

References _camera, _freecamPitch, _freecamYaw, freecamLookSpeed, and freecamMoveSpeed.

Referenced by handleInput().

+ Here is the caller graph for this function:

◆ _handleOrbitalInput()

void CameraController::_handleOrbitalInput ( )
private

Definition at line 148 of file CameraController.cpp.

References _angle, and orbitalMoveSpeed.

Referenced by handleInput().

+ Here is the caller graph for this function:

◆ _orbitalDest()

void CameraController::_orbitalDest ( float  worldWidth,
float  worldHeight,
Vector3 &  outPos,
Vector3 &  outTarget 
) const
private

Definition at line 26 of file CameraController.cpp.

References _angle, and _height.

Referenced by exitFreecam(), and stopFollow().

+ Here is the caller graph for this function:

◆ _startTransition()

void CameraController::_startTransition ( Vector3  toPos,
Vector3  toTarget,
Mode  nextMode 
)
private

Definition at line 71 of file CameraController.cpp.

References _camera, _fromPos, _fromTarget, _pendingMode, _toPos, _toTarget, and _transitionT.

Referenced by exitFreecam(), startFollow(), and stopFollow().

+ Here is the caller graph for this function:

◆ camera()

const Camera3D & CameraController::camera ( ) const
inline

Definition at line 25 of file CameraController.hpp.

References _camera.

Referenced by RaylibRenderer::_performRaycast(), RaylibRenderer::_render2D(), RaylibRenderer::_render3D(), and RaylibRenderer::render().

+ Here is the caller graph for this function:

◆ enterFreecam()

void CameraController::enterFreecam ( )

Definition at line 179 of file CameraController.cpp.

References _angle, _camera, _freecamPitch, _freecamYaw, _height, _mode, _savedOrbitalAngle, _savedOrbitalHeight, _transitionT, Freecam, isTransitioning(), and transitionDuration.

Referenced by RaylibRenderer::handleInput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exitFreecam()

void CameraController::exitFreecam ( )

Definition at line 193 of file CameraController.cpp.

References _angle, _height, _lastWorldHeight, _lastWorldWidth, _mode, _orbitalDest(), _savedOrbitalAngle, _savedOrbitalHeight, _startTransition(), Freecam, and Orbital.

Referenced by RaylibRenderer::handleInput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ followedPlayerId()

int CameraController::followedPlayerId ( ) const
inline

Definition at line 37 of file CameraController.hpp.

References _followedPlayerId.

Referenced by RaylibRenderer::handleInput().

+ Here is the caller graph for this function:

◆ handleInput()

void CameraController::handleInput ( )

Definition at line 138 of file CameraController.cpp.

References _handleFreecamInput(), _handleOrbitalInput(), _mode, Freecam, isTransitioning(), and Orbital.

Referenced by RaylibRenderer::handleInput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

void CameraController::init ( float  worldWidth,
float  worldHeight 
)

Definition at line 15 of file CameraController.cpp.

References _applyOrbital(), _camera, _transitionT, and transitionDuration.

Referenced by RaylibRenderer::init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFollowActive()

bool CameraController::isFollowActive ( ) const
inline

Definition at line 35 of file CameraController.hpp.

References _followedPlayerId.

Referenced by RaylibRenderer::_render2D(), RaylibRenderer::handleInput(), and stopFollow().

+ Here is the caller graph for this function:

◆ isFreecamActive()

bool CameraController::isFreecamActive ( ) const
inline

Definition at line 34 of file CameraController.hpp.

References _mode, and Freecam.

Referenced by RaylibRenderer::handleInput().

+ Here is the caller graph for this function:

◆ isTransitioning()

bool CameraController::isTransitioning ( ) const
inline

Definition at line 36 of file CameraController.hpp.

References _transitionT, and transitionDuration.

Referenced by enterFreecam(), handleInput(), and startFollow().

+ Here is the caller graph for this function:

◆ startFollow()

void CameraController::startFollow ( int  playerId)

Definition at line 204 of file CameraController.cpp.

References _camera, _followedPlayerId, _mode, _startTransition(), Follow, Freecam, and isTransitioning().

Referenced by RaylibRenderer::handleInput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stopFollow()

void CameraController::stopFollow ( )

Definition at line 213 of file CameraController.cpp.

References _lastWorldHeight, _lastWorldWidth, _orbitalDest(), _startTransition(), isFollowActive(), and Orbital.

Referenced by RaylibRenderer::handleInput(), and update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

void CameraController::update ( float  dt,
float  worldWidth,
float  worldHeight,
const WorldState world 
)

Definition at line 81 of file CameraController.cpp.

References _applyOrbital(), _camera, _followedPlayerId, _followTarget(), _freecamPitch, _freecamYaw, _fromPos, _fromTarget, _lastWorldHeight, _lastWorldWidth, _mode, _pendingMode, _toPos, _toTarget, _transitionT, Follow, FollowLive, Freecam, Orbital, smoothstep(), stopFollow(), and transitionDuration.

Referenced by RaylibRenderer::render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _angle

float CameraController::_angle = 0.0f
private

◆ _camera

Camera3D CameraController::_camera = {}
private

◆ _followedPlayerId

int CameraController::_followedPlayerId = -1
private

◆ _freecamPitch

float CameraController::_freecamPitch = 0.0f
private

Definition at line 51 of file CameraController.hpp.

Referenced by _handleFreecamInput(), enterFreecam(), and update().

◆ _freecamYaw

float CameraController::_freecamYaw = 0.0f
private

Definition at line 50 of file CameraController.hpp.

Referenced by _handleFreecamInput(), enterFreecam(), and update().

◆ _fromPos

Vector3 CameraController::_fromPos = {}
private

Definition at line 58 of file CameraController.hpp.

Referenced by _startTransition(), and update().

◆ _fromTarget

Vector3 CameraController::_fromTarget = {}
private

Definition at line 59 of file CameraController.hpp.

Referenced by _startTransition(), and update().

◆ _height

float CameraController::_height = 5.0f
private

Definition at line 46 of file CameraController.hpp.

Referenced by _applyOrbital(), _orbitalDest(), enterFreecam(), and exitFreecam().

◆ _lastWorldHeight

float CameraController::_lastWorldHeight = 10.0f
private

Definition at line 55 of file CameraController.hpp.

Referenced by exitFreecam(), stopFollow(), and update().

◆ _lastWorldWidth

float CameraController::_lastWorldWidth = 10.0f
private

Definition at line 54 of file CameraController.hpp.

Referenced by exitFreecam(), stopFollow(), and update().

◆ _mode

Mode CameraController::_mode = Mode::Orbital
private

◆ _pendingMode

Mode CameraController::_pendingMode = Mode::Orbital
private

Definition at line 62 of file CameraController.hpp.

Referenced by _startTransition(), and update().

◆ _savedOrbitalAngle

float CameraController::_savedOrbitalAngle = 0.0f
private

Definition at line 47 of file CameraController.hpp.

Referenced by enterFreecam(), and exitFreecam().

◆ _savedOrbitalHeight

float CameraController::_savedOrbitalHeight = 5.0f
private

Definition at line 48 of file CameraController.hpp.

Referenced by enterFreecam(), and exitFreecam().

◆ _toPos

Vector3 CameraController::_toPos = {}
private

Definition at line 60 of file CameraController.hpp.

Referenced by _startTransition(), and update().

◆ _toTarget

Vector3 CameraController::_toTarget = {}
private

Definition at line 61 of file CameraController.hpp.

Referenced by _startTransition(), and update().

◆ _transitionT

float CameraController::_transitionT = 1.0f
private

Definition at line 57 of file CameraController.hpp.

Referenced by _startTransition(), enterFreecam(), init(), isTransitioning(), and update().

◆ followDist

float CameraController::followDist = 2.5f

Definition at line 15 of file CameraController.hpp.

Referenced by _followTarget().

◆ followHeight

float CameraController::followHeight = 1.8f

Definition at line 16 of file CameraController.hpp.

Referenced by _followTarget().

◆ followLookOffsetY

float CameraController::followLookOffsetY = 0.5f

Definition at line 17 of file CameraController.hpp.

Referenced by _followTarget().

◆ freecamLookSpeed

float CameraController::freecamLookSpeed = 0.002f

Definition at line 14 of file CameraController.hpp.

Referenced by _handleFreecamInput().

◆ freecamMoveSpeed

float CameraController::freecamMoveSpeed = 5.0f

Definition at line 13 of file CameraController.hpp.

Referenced by _handleFreecamInput().

◆ orbitalMoveSpeed

float CameraController::orbitalMoveSpeed = 2.0f

Definition at line 12 of file CameraController.hpp.

Referenced by _handleOrbitalInput().

◆ transitionDuration

float CameraController::transitionDuration = 0.8f

Definition at line 18 of file CameraController.hpp.

Referenced by enterFreecam(), init(), isTransitioning(), and update().


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