GlistEngine
Loading...
Searching...
No Matches
gCameraController Class Reference

#include <gCameraController.h>

Inheritance diagram for gCameraController:
Collaboration diagram for gCameraController:

Public Member Functions

 gCameraController ()
 
 gCameraController (gCamera *camera)
 
 ~gCameraController ()
 
void setCamera (gCamera *camera)
 
gCameragetCamera () const
 
void update ()
 
void setEnabled (bool enabled)
 
bool isEnabled () const
 
void setPlayerIndex (int playerIndex)
 
int getPlayerIndex () const
 
void registerInputs ()
 
void setMoveSpeed (float speed)
 
float getMoveSpeed () const
 
void setMouseSensitivity (float sensitivity)
 
float getMouseSensitivity () const
 
void setGamepadLookSensitivity (float sensitivity)
 
float getGamepadLookSensitivity () const
 
- Public Member Functions inherited from gRenderObject
 gRenderObject ()
 
int getScreenWidth ()
 
int getScreenHeight ()
 
void pushMatrix ()
 
void popMatrix ()
 
- Public Member Functions inherited from gObject
 gObject ()
 
void logi (std::string message)
 
void logd (std::string message)
 
void logw (std::string message)
 
void loge (std::string message)
 
void logi (std::string tag, std::string message)
 
void logd (std::string tag, std::string message)
 
void logw (std::string tag, std::string message)
 
void loge (std::string tag, std::string message)
 

Static Public Attributes

static const std::string AXIS_HORIZONTAL
 Strafe. Default: A(-)/D(+), Left Stick X.
 
static const std::string AXIS_VERTICAL
 Forward/back. Default: S(-)/W(+), Left Stick Y.
 
static const std::string AXIS_ELEVATION
 Up/down. Default: LShift(-)/Space(+), LB(-)/RB(+)
 
static const std::string AXIS_LOOK_HORIZONTAL
 Gamepad look horizontal. Default: Right Stick X.
 
static const std::string AXIS_LOOK_VERTICAL
 Gamepad look vertical. Default: Right Stick Y.
 
static const std::string ACTION_TOGGLE
 Toggle on/off. Default: ESC, Start.
 
- Static Public Attributes inherited from gObject
static const int LOGLEVEL_SILENT
 
static const int LOGLEVEL_DEBUG
 
static const int LOGLEVEL_INFO
 
static const int LOGLEVEL_WARNING
 
static const int LOGLEVEL_ERROR
 

Additional Inherited Members

- Static Public Member Functions inherited from gRenderObject
static void setScreenSize (int screenWidth, int screenHeight)
 
static void setUnitScreenSize (int unitWidth, int unitHeight)
 
static void setScreenScaling (int screenScaling)
 
static void enableShadowMapping ()
 
static void disableShadowMapping ()
 
static bool isShadowMappingEnabled ()
 
static gRenderergetRenderer ()
 
static void destroyRenderer ()
 
static void createRenderer ()
 
- Static Public Member Functions inherited from gObject
static std::string gGetAppDir ()
 
static std::string gGetAssetsDir ()
 
static void gSetAssetsDir (std::string assetsDir)
 
static std::string gGetFilesDir ()
 
static std::string gGetImagesDir ()
 
static std::string gGetFontsDir ()
 
static std::string gGetModelsDir ()
 
static std::string gGetTexturesDir ()
 
static std::string gGetShadersDir ()
 
static std::string gGetSoundsDir ()
 
static std::string gGetDatabasesDir ()
 
static std::string gGetVideosDir ()
 
static void setCurrentResolution (int scalingNo, int currentResolutionNo)
 
- Static Protected Attributes inherited from gRenderObject
static bool isshadowmappingenabled
 
- Static Protected Attributes inherited from gObject
static int renderpassnum
 
static int renderpassno
 
static int releasescaling
 
static int releaseresolution
 

Detailed Description

First-person camera controller with configurable input bindings.

Uses gInputManager player-based axes for movement, mouse look, and gamepad right-stick look. All bindings can be rebound at runtime.

Default keyboard bindings (player 0): AXIS_HORIZONTAL : A(-) / D(+) AXIS_VERTICAL : S(-) / W(+) AXIS_ELEVATION : LShift(-) / Space(+) ACTION_TOGGLE : ESC

Default gamepad bindings (when gamepad assigned): AXIS_HORIZONTAL : Left Stick X AXIS_VERTICAL : Left Stick Y (inverted) AXIS_ELEVATION : LB(-) / RB(+) AXIS_LOOK_HORIZONTAL : Right Stick X AXIS_LOOK_VERTICAL : Right Stick Y (inverted) ACTION_TOGGLE : Start

Example - basic usage:

gCamera camera;
gCameraController camcontroller;
camcontroller.setCamera(&camera);
// In update():
camcontroller.update();
Definition gCameraController.h:58
void setCamera(gCamera *camera)
Definition gCamera.h:19

Example - local co-op with gamepad:

gCameraController camcontroller2;
camcontroller2.setPlayerIndex(1);
camcontroller2.setCamera(&camera2);
void setPlayerIndex(int playerIndex)
gInputPlayer * getPlayer(int playerIndex)
void setGamepadId(int id)
gInputManager * inputmanager

Example - rebinding axes:

static const std::string AXIS_HORIZONTAL
Strafe. Default: A(-)/D(+), Left Stick X.
Definition gCameraController.h:114
#define G_KEY_LEFT
Definition gKeyCode.h:61
#define G_KEY_RIGHT
Definition gKeyCode.h:60

Constructor & Destructor Documentation

◆ gCameraController() [1/2]

gCameraController::gCameraController ( )

◆ gCameraController() [2/2]

gCameraController::gCameraController ( gCamera camera)

◆ ~gCameraController()

gCameraController::~gCameraController ( )

Member Function Documentation

◆ getCamera()

gCamera * gCameraController::getCamera ( ) const

◆ getGamepadLookSensitivity()

float gCameraController::getGamepadLookSensitivity ( ) const

◆ getMouseSensitivity()

float gCameraController::getMouseSensitivity ( ) const

◆ getMoveSpeed()

float gCameraController::getMoveSpeed ( ) const

◆ getPlayerIndex()

int gCameraController::getPlayerIndex ( ) const

◆ isEnabled()

bool gCameraController::isEnabled ( ) const

◆ registerInputs()

void gCameraController::registerInputs ( )

Registers default keyboard and gamepad bindings on the current player. Called automatically in the constructor. Call manually after changing the player index if you want the defaults re-registered.

◆ setCamera()

void gCameraController::setCamera ( gCamera camera)

◆ setEnabled()

void gCameraController::setEnabled ( bool  enabled)

Enables or disables the controller. When enabled and the player has KB+M assigned, the cursor switches to relative mode for mouse look.

◆ setGamepadLookSensitivity()

void gCameraController::setGamepadLookSensitivity ( float  sensitivity)

Gamepad right-stick look speed in radians per second at full deflection. Default: 3.0

◆ setMouseSensitivity()

void gCameraController::setMouseSensitivity ( float  sensitivity)

Mouse look sensitivity multiplier. Default: 2.0

◆ setMoveSpeed()

void gCameraController::setMoveSpeed ( float  speed)

Movement speed in units per second. Default: 2.0

◆ setPlayerIndex()

void gCameraController::setPlayerIndex ( int  playerIndex)

Which player index this controller reads input from. Default: 0. Set before calling update() for the first time, or call registerInputs() after changing to re-register default bindings on the new player.

◆ update()

void gCameraController::update ( )

Updates camera position and orientation based on current input state. Call this once per frame from your canvas update().

Member Data Documentation

◆ ACTION_TOGGLE

const std::string gCameraController::ACTION_TOGGLE
static

Toggle on/off. Default: ESC, Start.

◆ AXIS_ELEVATION

const std::string gCameraController::AXIS_ELEVATION
static

Up/down. Default: LShift(-)/Space(+), LB(-)/RB(+)

◆ AXIS_HORIZONTAL

const std::string gCameraController::AXIS_HORIZONTAL
static

Strafe. Default: A(-)/D(+), Left Stick X.

◆ AXIS_LOOK_HORIZONTAL

const std::string gCameraController::AXIS_LOOK_HORIZONTAL
static

Gamepad look horizontal. Default: Right Stick X.

◆ AXIS_LOOK_VERTICAL

const std::string gCameraController::AXIS_LOOK_VERTICAL
static

Gamepad look vertical. Default: Right Stick Y.

◆ AXIS_VERTICAL

const std::string gCameraController::AXIS_VERTICAL
static

Forward/back. Default: S(-)/W(+), Left Stick Y.


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