Support Forum       G3D Web Page     
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::FirstPersonManipulator Class Reference


Uses a First Person (Quake- or World of Warcraft style) mapping to translate keyboard and mouse input into a flying camera position. More...

Inherits G3D::Manipulator.

Public Types

enum  MouseMode {
  MOUSE_DIRECT,
  MOUSE_DIRECT_RIGHT_BUTTON,
  MOUSE_SCROLL_AT_EDGE,
  MOUSE_PUSH_AT_EDGE
}
 

Public Member Functions

 FirstPersonManipulator (UserInput *ui)
 
virtual ~FirstPersonManipulator ()
 Deactivates the controller. More...
 
float altSpeedMultipler () const
 
virtual Rect2D bounds () const override
 Inherited from Surface2D. More...
 
virtual float depth () const override
 Inherited from Surface2D. More...
 
bool enabled () const override
 
virtual void fireEvent (const GEvent &event)
 Fire an event on the containing window. More...
 
GKey flyDownKey () const
 Key for translating -Y. More...
 
GKey flyUpKey () const
 Key for translating +Y. More...
 
virtual CoordinateFrame frame () const override
 
virtual void getFrame (CoordinateFrame &c) const override
 
void lookAt (const Vector3 &position)
 
Vector3 lookVector () const
 
WidgetManagermanager () const
 
MouseMode mouseMode () const
 
virtual void onAfterEvents ()
 Invoked after all onEvent handlers for the current frame and before onUserInput for any other Widget. More...
 
virtual void onAI () override
 
virtual void onBeforeGraphics ()
 Invoked by WidgetManager immediately before GApp::onGraphics runs. More...
 
virtual bool onEvent (const GEvent &event) override
 Returning true consumes the event and prevents other GModules from seeing it. More...
 
virtual void onNetwork () override
 
virtual void onPose (Array< shared_ptr< Surface > > &surfaceArray, Array< shared_ptr< Surface2D > > &surface2DArray)
 
Appends a posed model for this object to the array, if it has a graphic representation. More...
 
virtual void onPose (Array< shared_ptr< Surface >> &p3d, Array< shared_ptr< Surface2D >> &p2d) override
 
virtual void onSimulation (RealTime rdt, SimTime sdt, SimTime idt) override
 
virtual void onUserInput (UserInput *ui) override
 
float pitch () const
 
virtual float positionalEventZ (const Point2 &pixel) const
 The camera-space z position that this Widget considers this pixel to be at. More...
 
virtual void render (RenderDevice *rd) const override
 Inherited from Surface2D. More...
 
void reset ()
 Invoke immediately before entering the main game loop. More...
 
void setAltSpeedMultipler (float m)
 When the alt key is held down, multiply m_maxMoveRate by this. More...
 
virtual void setDepth (float d)
 Called by the WidgetManager. More...
 
void setEnabled (bool a) override
 When enabled, the FirstPersonManipulator responds to events and updates its frame. More...
 
void setFlyDownKey (GKey k)
 Default is 'c'. More...
 
void setFlyUpKey (GKey k)
 Default is 'z'. More...
 
virtual void setFrame (const CoordinateFrame &c) override
 Sets to the closest legal controller orientation to the coordinate frame. More...
 
virtual void setFrame (const CFrame &c)
 By default, does nothing. More...
 
virtual void setManager (WidgetManager *m)
 Called by the WidgetManager when this module is added to it. More...
 
void setMouseMode (MouseMode m)
 
void setMoveRate (double metersPerSecond)
 Initial value is 10. More...
 
void setPitch (float p)
 
void setPosition (const Vector3 &t)
 
void setShiftSpeedMultipler (float m)
 When the shift key is held down, multiply m_maxMoveRate by this. More...
 
void setTurnRate (double radiansPerSecond)
 Initial value is PI / 2. More...
 
void setYaw (float y)
 
float shiftSpeedMultipler () const
 
const Vector3translation () const
 
virtual OSWindowwindow () const
 Returns the operating system window that is currently rendering this Widget. More...
 
float yaw () const
 

Static Public Member Functions

static shared_ptr< FirstPersonManipulatorcreate (UserInput *ui=nullptr)
 If the UserInput is not provided here, it is automatically recorded after the first onUserInput method invocation. More...
 
static void sort (Array< shared_ptr< Surface2D >> &array)
 Sorts from farthest to nearest. More...
 
static void sortAndRender (RenderDevice *rd, Array< shared_ptr< Surface2D >> &array)
 Calls sort, RenderDevice::push2D, and then render on all elements. More...
 

Protected Member Functions

bool rightDown (UserInput *) const
 Returns true if the right mouse button is down, or on OSX, the user is using the left mouse and ctrl. More...
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

float m_altSpeedMultiplier
 
More...
 
float m_depth
 
bool m_enabled
 
GKey m_flyDownKey
 
GKey m_flyUpKey
 
WidgetManagerm_manager
 The manager, set by setManager(). More...
 
float m_maxMoveRate
 m/s More...
 
float m_maxTurnRate
 rad/s More...
 
MouseMode m_mouseMode
 
float m_pitch
 
bool m_rightDown
 Is the right mouse button currently held down? More...
 
float m_shiftSpeedMultiplier
 
More...
 
Vector3 m_translation
 
class UserInputm_userInput
 
float m_yaw
 
GKey m_yawLeftKey
 
GKey m_yawRightKey
 

Detailed Description


Uses a First Person (Quake- or World of Warcraft style) mapping to translate keyboard and mouse input into a flying camera position.

The result is an Euler-angle camera controller suitable for games and fly-throughs.
To use without G3D::GApp:

  1. Create a G3D::RenderDevice
  2. Create a UserInput object (set the keyboard controls when creating it)
  3. Create a ManualCameraController
  4. Call ManualCameraController::setActive(true)
  5. Invoke ManualCameraController::doSimulation every time simulation is invoked (e.g. once per rendering iteration)
  6. Use ManualCameraController::getCoordinateFrame() to set the camera's position

Member Enumeration Documentation

◆ MouseMode

Enumerator
MOUSE_DIRECT 

Shooter/Quake style (default), mouse cursor is hidden and mouse controls yaw/pitch.

MOUSE_DIRECT_RIGHT_BUTTON 

RPG/World of Warcraft style, on right mouse button cursor is hidden and mouse controls yaw/pitch.

To support single-button systems the combination ctrl+left button is also treated as if it were the right mouse button.

MOUSE_SCROLL_AT_EDGE 

Leaves mouse cursor visible and rotates while mouse is near the window edge.

MOUSE_PUSH_AT_EDGE 

RTS style.

Leaves mouse cursor visible and rotates when the mouse is actively pushing against the window edge

Constructor & Destructor Documentation

◆ FirstPersonManipulator()

G3D::FirstPersonManipulator::FirstPersonManipulator ( UserInput ui)

◆ ~FirstPersonManipulator()

virtual G3D::FirstPersonManipulator::~FirstPersonManipulator ( )
virtual

Deactivates the controller.

Member Function Documentation

◆ altSpeedMultipler()

float G3D::FirstPersonManipulator::altSpeedMultipler ( ) const
inline

◆ bounds()

virtual Rect2D G3D::Widget::bounds ( ) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Implements G3D::Surface2D.

Reimplemented in G3D::GuiWindow, G3D::GConsole, and G3D::FullScreenWidget.

◆ create()

static shared_ptr<FirstPersonManipulator> G3D::FirstPersonManipulator::create ( UserInput ui = nullptr)
static

If the UserInput is not provided here, it is automatically recorded after the first onUserInput method invocation.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ depth()

virtual float G3D::Widget::depth ( ) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Controls the depth of objects when rendering. Subclasses may override this but it can interfere with the normal handling of rendering and event delivery. depth = 0 is usually the "top" widget and depth = 1 is usually the "bottom" widget.

Implements G3D::Surface2D.

Reimplemented in G3D::GuiWindow, G3D::GConsole, and G3D::FullScreenWidget.

◆ enabled()

bool G3D::FirstPersonManipulator::enabled ( ) const
overridevirtual

Reimplemented from G3D::Manipulator.

◆ fireEvent()

virtual void G3D::Widget::fireEvent ( const GEvent event)
virtualinherited

Fire an event on the containing window.

Reimplemented in G3D::WidgetManager.

◆ flyDownKey()

GKey G3D::FirstPersonManipulator::flyDownKey ( ) const
inline

Key for translating -Y.

◆ flyUpKey()

GKey G3D::FirstPersonManipulator::flyUpKey ( ) const
inline

Key for translating +Y.

◆ frame()

virtual CoordinateFrame G3D::FirstPersonManipulator::frame ( ) const
overridevirtual

Implements G3D::Manipulator.

Referenced by lookVector().

◆ getFrame()

virtual void G3D::FirstPersonManipulator::getFrame ( CoordinateFrame c) const
overridevirtual

Implements G3D::Manipulator.

◆ lookAt()

void G3D::FirstPersonManipulator::lookAt ( const Vector3 position)

◆ lookVector()

Vector3 G3D::FirstPersonManipulator::lookVector ( ) const
inline

◆ manager()

WidgetManager* G3D::Widget::manager ( ) const
inlineinherited

◆ mouseMode()

MouseMode G3D::FirstPersonManipulator::mouseMode ( ) const

◆ onAfterEvents()

virtual void G3D::Widget::onAfterEvents ( )
inlinevirtualinherited

Invoked after all onEvent handlers for the current frame and before onUserInput for any other Widget.

Reimplemented in G3D::WidgetManager, and G3D::GameController.

◆ onAI()

virtual void G3D::FirstPersonManipulator::onAI ( )
overridevirtual

Reimplemented from G3D::Widget.

◆ onBeforeGraphics()

virtual void G3D::Widget::onBeforeGraphics ( )
inlinevirtualinherited

Invoked by WidgetManager immediately before GApp::onGraphics runs.

Reimplemented in G3D::WidgetManager, G3D::CallbackWidget, and G3D::XRWidget.

◆ onEvent()

virtual bool G3D::FirstPersonManipulator::onEvent ( const GEvent event)
overridevirtual

Returning true consumes the event and prevents other GModules from seeing it.

Motion events (GEventType::MOUSEMOTION, GEventType::JOYHATMOTION, JGEventType::OYBALLMOTION, and GEventType::JOYAXISMOTION) cannot be cancelled.

Reimplemented from G3D::Widget.

◆ onNetwork()

virtual void G3D::FirstPersonManipulator::onNetwork ( )
overridevirtual

Reimplemented from G3D::Widget.

◆ onPose() [1/2]

virtual void G3D::Widget::onPose ( Array< shared_ptr< Surface > > &  surfaceArray,
Array< shared_ptr< Surface2D > > &  surface2DArray 
)
inlinevirtualinherited


Appends a posed model for this object to the array, if it has a graphic representation.

The posed model appended is allowed to reference the agent and is allowed to mutate if the agent is mutated.

Reimplemented in G3D::GuiWindow, G3D::WidgetManager, G3D::Discovery::Client, G3D::SceneEditorWindow, G3D::CallbackWidget, G3D::FullScreenWidget, G3D::UprightSplineManipulator, and G3D::ControlPointEditor.

◆ onPose() [2/2]

virtual void G3D::FirstPersonManipulator::onPose ( Array< shared_ptr< Surface >> &  p3d,
Array< shared_ptr< Surface2D >> &  p2d 
)
overridevirtual

◆ onSimulation()

virtual void G3D::FirstPersonManipulator::onSimulation ( RealTime  rdt,
SimTime  sdt,
SimTime  idt 
)
overridevirtual

Reimplemented from G3D::Widget.

◆ onUserInput()

virtual void G3D::FirstPersonManipulator::onUserInput ( UserInput ui)
overridevirtual

Reimplemented from G3D::Widget.

◆ pitch()

float G3D::FirstPersonManipulator::pitch ( ) const
inline

◆ positionalEventZ()

virtual float G3D::Widget::positionalEventZ ( const Point2 pixel) const
inlinevirtualinherited

The camera-space z position that this Widget considers this pixel to be at.

Used for positional event (e.g., mouse click) delivery. Higher means closer.

Large negative values are far away. 0 is the closest 3D object. Values greater than zero are used for 2D objects. Returning fnan() [the default] requests the WidgetManager to set hte positionalEventZ to the object's normal event zorder.

See the implementation of ControlPointEditor::positionalEventZ for an example of how to use this with a 3D object.

Reimplemented in G3D::ControlPointEditor.

◆ render()

virtual void G3D::Widget::render ( RenderDevice rd) const
inlineoverridevirtualinherited

Inherited from Surface2D.

Implements G3D::Surface2D.

Reimplemented in G3D::GConsole, G3D::GuiWindow, G3D::GuiMenu, and G3D::DebugTextWidget.

◆ reset()

void G3D::FirstPersonManipulator::reset ( )

Invoke immediately before entering the main game loop.

◆ rightDown()

bool G3D::FirstPersonManipulator::rightDown ( UserInput ) const
protected

Returns true if the right mouse button is down, or on OSX, the user is using the left mouse and ctrl.

◆ setAltSpeedMultipler()

void G3D::FirstPersonManipulator::setAltSpeedMultipler ( float  m)
inline

When the alt key is held down, multiply m_maxMoveRate by this.

Default is 0.1

◆ setDepth()

virtual void G3D::Widget::setDepth ( float  d)
inlinevirtualinherited

Called by the WidgetManager.

This is the depth that the Widget is expected to use when posed as a Surface2D. Subclasses may override or ignore this but it can interfere with the normal handling of rendering.

◆ setEnabled()

void G3D::FirstPersonManipulator::setEnabled ( bool  a)
overridevirtual

When enabled, the FirstPersonManipulator responds to events and updates its frame.

When deactivated, the mouse cursor is restored and the mouse is located where it was when the camera controller was activated.

In some modes (e.g., MOUSE_DIRECT_RIGHT_BUTTON), the FirstPersonManipulator does not hide the mouse until some other event has occured.

In release mode, the cursor movement is restricted to the window while the controller is active. This does not occur in debug mode because you might hit a breakpoint while the controller is active and it would be annoying to not be able to move the mouse.

Reimplemented from G3D::Manipulator.

◆ setFlyDownKey()

void G3D::FirstPersonManipulator::setFlyDownKey ( GKey  k)
inline

Default is 'c'.

◆ setFlyUpKey()

void G3D::FirstPersonManipulator::setFlyUpKey ( GKey  k)
inline

Default is 'z'.

◆ setFrame() [1/2]

virtual void G3D::FirstPersonManipulator::setFrame ( const CoordinateFrame c)
overridevirtual

Sets to the closest legal controller orientation to the coordinate frame.

◆ setFrame() [2/2]

virtual void G3D::Manipulator::setFrame ( const CFrame c)
inlinevirtualinherited

By default, does nothing.

◆ setManager()

virtual void G3D::Widget::setManager ( WidgetManager m)
inlinevirtualinherited

◆ setMouseMode()

void G3D::FirstPersonManipulator::setMouseMode ( MouseMode  m)

◆ setMoveRate()

void G3D::FirstPersonManipulator::setMoveRate ( double  metersPerSecond)

Initial value is 10.

◆ setPitch()

void G3D::FirstPersonManipulator::setPitch ( float  p)
inline

◆ setPosition()

void G3D::FirstPersonManipulator::setPosition ( const Vector3 t)
inline

◆ setShiftSpeedMultipler()

void G3D::FirstPersonManipulator::setShiftSpeedMultipler ( float  m)
inline

When the shift key is held down, multiply m_maxMoveRate by this.

Default is 0.1

◆ setTurnRate()

void G3D::FirstPersonManipulator::setTurnRate ( double  radiansPerSecond)

Initial value is PI / 2.

◆ setYaw()

void G3D::FirstPersonManipulator::setYaw ( float  y)
inline

◆ shiftSpeedMultipler()

float G3D::FirstPersonManipulator::shiftSpeedMultipler ( ) const
inline

◆ sort()

static void G3D::Surface2D::sort ( Array< shared_ptr< Surface2D >> &  array)
staticinherited

Sorts from farthest to nearest.

◆ sortAndRender()

static void G3D::Surface2D::sortAndRender ( RenderDevice rd,
Array< shared_ptr< Surface2D >> &  array 
)
staticinherited

Calls sort, RenderDevice::push2D, and then render on all elements.

◆ translation()

const Vector3& G3D::FirstPersonManipulator::translation ( ) const
inline

◆ window()

virtual OSWindow* G3D::Widget::window ( ) const
virtualinherited

Returns the operating system window that is currently rendering this Widget.

Reimplemented in G3D::WidgetManager.

Referenced by G3D::FullScreenWidget::bounds().

◆ yaw()

float G3D::FirstPersonManipulator::yaw ( ) const
inline

Member Data Documentation

◆ m_altSpeedMultiplier

float G3D::FirstPersonManipulator::m_altSpeedMultiplier
protected

◆ m_depth

float G3D::Widget::m_depth
protectedinherited

◆ m_enabled

bool G3D::FirstPersonManipulator::m_enabled
protected

◆ m_flyDownKey

GKey G3D::FirstPersonManipulator::m_flyDownKey
protected

Referenced by flyDownKey(), and setFlyDownKey().

◆ m_flyUpKey

GKey G3D::FirstPersonManipulator::m_flyUpKey
protected

Referenced by flyUpKey(), and setFlyUpKey().

◆ m_manager

WidgetManager* G3D::Widget::m_manager
protectedinherited

The manager, set by setManager().

This cannot be a reference counted pointer because that would create a cycle between the Widget and its manager.

Referenced by G3D::Widget::manager(), G3D::GuiWindow::manager(), G3D::Widget::setManager(), and G3D::GuiWindow::setVisible().

◆ m_maxMoveRate

float G3D::FirstPersonManipulator::m_maxMoveRate
protected

m/s

◆ m_maxTurnRate

float G3D::FirstPersonManipulator::m_maxTurnRate
protected

rad/s

◆ m_mouseMode

MouseMode G3D::FirstPersonManipulator::m_mouseMode
protected

◆ m_pitch

float G3D::FirstPersonManipulator::m_pitch
protected

Referenced by pitch(), and setPitch().

◆ m_rightDown

bool G3D::FirstPersonManipulator::m_rightDown
protected

Is the right mouse button currently held down?

◆ m_shiftSpeedMultiplier

float G3D::FirstPersonManipulator::m_shiftSpeedMultiplier
protected

◆ m_translation

Vector3 G3D::FirstPersonManipulator::m_translation
protected

Referenced by setPosition(), and translation().

◆ m_userInput

class UserInput* G3D::FirstPersonManipulator::m_userInput
protected

◆ m_yaw

float G3D::FirstPersonManipulator::m_yaw
protected

Referenced by setYaw(), and yaw().

◆ m_yawLeftKey

GKey G3D::FirstPersonManipulator::m_yawLeftKey
protected

◆ m_yawRightKey

GKey G3D::FirstPersonManipulator::m_yawRightKey
protected

documentation generated on Wed Nov 24 2021 08:01:55 using doxygen 1.8.15