Packagealternativa.engine3d.controllers
Classpublic class ObjectController
SubclassesFlyController, WalkController

The base controller to manipulate an object's orientation and position. The class implements keyboard commands binding mechanism and basic movement commands handlers.



Public Properties
 PropertyDefined by
  accelerated : Boolean
[read-only] The accelerated speed mode flag.
ObjectController
  checkCollisions : Boolean
Enabling and disabling collision detection mode.
ObjectController
  collider : EllipsoidCollider
[read-only] EllipsoidCollider object.
ObjectController
  coords : Point3D
Coordinates of the controller.
ObjectController
  enabled : Boolean
Enabling and disabling controller.
ObjectController
  keyboardEnabled : Boolean
Enabling and disabling processing of keyboard events.
ObjectController
  mouseEnabled : Boolean
Enabling and disabling processing of mouse events.
ObjectController
  mouseSensitivity : Number
Mouse sensitivity — multiplication coefficient of mouseSensitivityX and mouseSensitivityY.
ObjectController
  mouseSensitivityX : Number
Horizontal mouse sensitivity.
ObjectController
  mouseSensitivityY : Number
Vertical mouse sensitivity.
ObjectController
  object : Object3D
Controlled object.
ObjectController
  onStartMoving : Function
Function defined as function():void, which is called when the controlled object starts to move.
ObjectController
  onStopMoving : Function
Function defined as function():void, which is called when the controlled object stops moving.
ObjectController
  pitchSpeed : Number
Pitch angular speed (radians per second).
ObjectController
  speed : Number
Speed of the controlled object in units per second.
ObjectController
  speedMultiplier : Number
Speed multiplier on acceleration.
ObjectController
  yawSpeed : Number
Yaw angular speed (radians per second).
ObjectController
Protected Properties
 PropertyDefined by
  _accelerate : Boolean
Accelerated mode flag.
ObjectController
  actionBindings : Map
Map which binds actions' names and actions' handlers.
ObjectController
  _back : Boolean
Back movement flag.
ObjectController
  _collider : EllipsoidCollider
EllipsoidCollider for collision detection.
ObjectController
  _coords : Point3D
Controller's current coordinates.
ObjectController
  _down : Boolean
Down movement flag.
ObjectController
  _enabled : Boolean = true
Controller's activity flag.
ObjectController
  _eventsSource : DisplayObject
Keyboard and mouse events' source.
ObjectController
  _forward : Boolean
Forward movement flag.
ObjectController
  _isMoving : Boolean
The flag shows if the controlled object moved in the current frame.
ObjectController
  keyBindings : Map
Map which binds key codes with actions' names.
ObjectController
  _keyboardEnabled : Boolean
The flag shows if keyboard is enabled.
ObjectController
  lastFrameTime : uint
The time that passed since the last call of the processInput() method.
ObjectController
  _left : Boolean
Left movement flag.
ObjectController
  _mouseCoefficientX : Number
Resulting horizontal mouse sensitivity.
ObjectController
  _mouseCoefficientY : Number
Resulting vertical mouse sensitivity.
ObjectController
  _mouseEnabled : Boolean
Mouse activity flag.
ObjectController
  _mouseLookActive : Boolean
Mouse look mode activity flag.
ObjectController
  _mouseSensitivity : Number = 1
Mouse sensitivity — multiplication coefficient for horizontal and vertical sensitivities.
ObjectController
  _mouseSensitivityX : Number
Horizontal mouse sensitivity.
ObjectController
  _mouseSensitivityY : Number
Vertical mouse sensitivity.
ObjectController
  _object : Object3D
Controlled object.
ObjectController
  _pitchDown : Boolean
pitch down flag
ObjectController
  _pitchSpeed : Number = 1
Angular speed of revolution around pitch axis.
ObjectController
  _pitchUp : Boolean
Pitch up flag.
ObjectController
  _right : Boolean
Right movement flag.
ObjectController
  _speed : Number = 100
Speed of controller.
ObjectController
  _speedMultiplier : Number = 2
Speed multiplication coefficient in accelerated mode.
ObjectController
  startMouseCoords : Point3D
Starting coordinates of the mouse cursor in mouse look mode.
ObjectController
  _up : Boolean
Up movement flag.
ObjectController
  _yawLeft : Boolean
Yaw left flag.
ObjectController
  _yawRight : Boolean
Yaw right flag.
ObjectController
  _yawSpeed : Number = 1
Angular speed of revolution around yaw axis.
ObjectController
Public Methods
 MethodDefined by
  
ObjectController(eventsSourceObject:DisplayObject)
Creates a new instance of controller.
ObjectController
  
accelerate(value:Boolean):void
Activation of accelerated speed mode.
ObjectController
  
bindKey(keyCode:uint, action:String):void
The method binds a key to an action.
ObjectController
  
moveBack(value:Boolean):void
Activation of back movement.
ObjectController
  
moveDown(value:Boolean):void
Activation of down movement.
ObjectController
  
moveForward(value:Boolean):void
Activation of forward movement.
ObjectController
  
moveLeft(value:Boolean):void
Activation of left movement.
ObjectController
  
moveRight(value:Boolean):void
Activation of right movement.
ObjectController
  
moveUp(value:Boolean):void
Activation of up movement.
ObjectController
  
pitchDown(value:Boolean):void
Activation of pitching down.
ObjectController
  
pitchUp(value:Boolean):void
Activation of pitching up.
ObjectController
  
processInput():void
The method processes all control influences.
ObjectController
  
readCoords(point:Point3D):void
The method stores controller's coordinates in the given variable.
ObjectController
  
The method sets default keys' bindings.
ObjectController
  
setMouseLook(value:Boolean):void
The method enables and disables mouse look mode.
ObjectController
  
unbindAll():void
Clear all key bindings.
ObjectController
  
unbindKey(keyCode:uint):void
Clear key binding.
ObjectController
  
yawLeft(value:Boolean):void
Activation of yawing left.
ObjectController
  
yawRight(value:Boolean):void
Activation of yawing right.
ObjectController
Protected Methods
 MethodDefined by
  
applyDisplacement(frameTime:Number, displacement:Point3D):void
The method applies displacement to the controlled object.
ObjectController
  
The method resets active commands' flags.
ObjectController
  
getDisplacement(frameTime:Number, displacement:Point3D):void
The method calculates potential displacement during the current frame.
ObjectController
  
The method registers necessary keyboard listeners.
ObjectController
  
The method registers necessary mouse listeners.
ObjectController
  
rotateObject(frameTime:Number):void
The method rotates the controlled object according to control influences.
ObjectController
  
The method sets coordinates of the controlled object depending on the controller's coordinates.
ObjectController
  
The method performs the necessary actions when mouse look mode is activated.
ObjectController
  
The method performs the necessary actions when mouse look mode is deactivated.
ObjectController
  
The method removes keyboard listeners when keyboard is deactivated.
ObjectController
  
The method removes mouse listeners when mouse is deactivated.
ObjectController
Public Constants
 ConstantDefined by
  ACTION_ACCELERATE : String = "ACTION_ACCELERATE"
[static] Action name for binding ACCELERATE button.
ObjectController
  ACTION_BACK : String = "ACTION_BACK"
[static] Action name for binding BACK movement button.
ObjectController
  ACTION_DOWN : String = "ACTION_DOWN"
[static] Action name for binding DOWN movement button.
ObjectController
  ACTION_FORWARD : String = "ACTION_FORWARD"
[static] Action name for binding FORWARD movement button.
ObjectController
  ACTION_LEFT : String = "ACTION_LEFT"
[static] Action name for binding LEFT movement button.
ObjectController
  ACTION_MOUSE_LOOK : String = "ACTION_MOUSE_LOOK"
[static] Action name for binding MOUSE_LOOK button.
ObjectController
  ACTION_PITCH_DOWN : String = "ACTION_PITCH_DOWN"
[static] Action name for binding PITCH_DOWN button.
ObjectController
  ACTION_PITCH_UP : String = "ACTION_PITCH_UP"
[static] Action name for binding PITCH_UP button.
ObjectController
  ACTION_RIGHT : String = "ACTION_RIGHT"
[static] Action name for binding RIGHT movement button.
ObjectController
  ACTION_UP : String = "ACTION_UP"
[static] Action name for binding UP movement button.
ObjectController
  ACTION_YAW_LEFT : String = "ACTION_YAW_LEFT"
[static] Action name for binding YAW_LEFT button.
ObjectController
  ACTION_YAW_RIGHT : String = "ACTION_YAW_RIGHT"
[static] Action name for binding YAW_RIGHT button.
ObjectController
Property detail
_accelerateproperty
protected var _accelerate:Boolean

Accelerated mode flag.

acceleratedproperty 
accelerated:Boolean  [read-only]

The accelerated speed mode flag.

Implementation
    public function get accelerated():Boolean
actionBindingsproperty 
protected var actionBindings:Map

Map which binds actions' names and actions' handlers. Handlers must be declared as function(value:Boolean):void. The parameter value shows if the corresponding action key is pressed.

_backproperty 
protected var _back:Boolean

Back movement flag.

checkCollisionsproperty 
public var checkCollisions:Boolean

Enabling and disabling collision detection mode.

_colliderproperty 
protected var _collider:EllipsoidCollider

EllipsoidCollider for collision detection.

colliderproperty 
collider:EllipsoidCollider  [read-only]

EllipsoidCollider object.

Implementation
    public function get collider():EllipsoidCollider
_coordsproperty 
protected var _coords:Point3D

Controller's current coordinates.

coordsproperty 
coords:Point3D  [read-write]

Coordinates of the controller. These coordinates match ellipsoid's center coordinates which is used for collision detection. Coordinates of the controlled object may not match coordinates of the controller.

Implementation
    public function get coords():Point3D
    public function set coords(value:Point3D):void

See also

_downproperty 
protected var _down:Boolean

Down movement flag.

_enabledproperty 
protected var _enabled:Boolean = true

Controller's activity flag.

enabledproperty 
enabled:Boolean  [read-write]

Enabling and disabling controller. Disabled controller skips processInput() method.

The default value is true.

Implementation
    public function get enabled():Boolean
    public function set enabled(value:Boolean):void

See also

_eventsSourceproperty 
protected var _eventsSource:DisplayObject

Keyboard and mouse events' source.

_forwardproperty 
protected var _forward:Boolean

Forward movement flag.

_isMovingproperty 
protected var _isMoving:Boolean

The flag shows if the controlled object moved in the current frame.

keyBindingsproperty 
protected var keyBindings:Map

Map which binds key codes with actions' names.

_keyboardEnabledproperty 
protected var _keyboardEnabled:Boolean

The flag shows if keyboard is enabled.

keyboardEnabledproperty 
keyboardEnabled:Boolean  [read-write]

Enabling and disabling processing of keyboard events. On enabling the registerKeyboardListeners method is called, on disabling — unregisterKeyboardListeners.

Implementation
    public function get keyboardEnabled():Boolean
    public function set keyboardEnabled(value:Boolean):void

See also

lastFrameTimeproperty 
protected var lastFrameTime:uint

The time that passed since the last call of the processInput() method.

_leftproperty 
protected var _left:Boolean

Left movement flag.

_mouseCoefficientXproperty 
protected var _mouseCoefficientX:Number

Resulting horizontal mouse sensitivity.

_mouseCoefficientYproperty 
protected var _mouseCoefficientY:Number

Resulting vertical mouse sensitivity.

_mouseEnabledproperty 
protected var _mouseEnabled:Boolean

Mouse activity flag.

mouseEnabledproperty 
mouseEnabled:Boolean  [read-write]

Enabling and disabling processing of mouse events. On enabling the registerMouseListeners method is called, on disabling — unregisterMouseListeners.

Implementation
    public function get mouseEnabled():Boolean
    public function set mouseEnabled(value:Boolean):void

See also

_mouseLookActiveproperty 
protected var _mouseLookActive:Boolean

Mouse look mode activity flag.

_mouseSensitivityproperty 
protected var _mouseSensitivity:Number = 1

Mouse sensitivity — multiplication coefficient for horizontal and vertical sensitivities.

mouseSensitivityproperty 
mouseSensitivity:Number  [read-write]

Mouse sensitivity — multiplication coefficient of mouseSensitivityX and mouseSensitivityY.

The default value is 1.

Implementation
    public function get mouseSensitivity():Number
    public function set mouseSensitivity(value:Number):void

See also

_mouseSensitivityXproperty 
protected var _mouseSensitivityX:Number

Horizontal mouse sensitivity.

mouseSensitivityXproperty 
mouseSensitivityX:Number  [read-write]

Horizontal mouse sensitivity.

The default value is Math.PI / 360.

Implementation
    public function get mouseSensitivityX():Number
    public function set mouseSensitivityX(value:Number):void

See also

_mouseSensitivityYproperty 
protected var _mouseSensitivityY:Number

Vertical mouse sensitivity.

mouseSensitivityYproperty 
mouseSensitivityY:Number  [read-write]

Vertical mouse sensitivity.

The default value is Math.PI / 360.

Implementation
    public function get mouseSensitivityY():Number
    public function set mouseSensitivityY(value:Number):void

See also

_objectproperty 
protected var _object:Object3D

Controlled object.

objectproperty 
object:Object3D  [read-write]

Controlled object.

Implementation
    public function get object():Object3D
    public function set object(value:Object3D):void
onStartMovingproperty 
public var onStartMoving:Function

Function defined as function():void, which is called when the controlled object starts to move.

onStopMovingproperty 
public var onStopMoving:Function

Function defined as function():void, which is called when the controlled object stops moving.

_pitchDownproperty 
protected var _pitchDown:Boolean

pitch down flag

_pitchSpeedproperty 
protected var _pitchSpeed:Number = 1

Angular speed of revolution around pitch axis.

pitchSpeedproperty 
pitchSpeed:Number  [read-write]

Pitch angular speed (radians per second).

The default value is 1.

Implementation
    public function get pitchSpeed():Number
    public function set pitchSpeed(value:Number):void
_pitchUpproperty 
protected var _pitchUp:Boolean

Pitch up flag.

_rightproperty 
protected var _right:Boolean

Right movement flag.

_speedproperty 
protected var _speed:Number = 100

Speed of controller.

speedproperty 
speed:Number  [read-write]

Speed of the controlled object in units per second. If a negative value is passed, the absolute value is used.

The default value is 100.

Implementation
    public function get speed():Number
    public function set speed(value:Number):void
_speedMultiplierproperty 
protected var _speedMultiplier:Number = 2

Speed multiplication coefficient in accelerated mode.

speedMultiplierproperty 
speedMultiplier:Number  [read-write]

Speed multiplier on acceleration.

The default value is 2.

Implementation
    public function get speedMultiplier():Number
    public function set speedMultiplier(value:Number):void
startMouseCoordsproperty 
protected var startMouseCoords:Point3D

Starting coordinates of the mouse cursor in mouse look mode.

_upproperty 
protected var _up:Boolean

Up movement flag.

_yawLeftproperty 
protected var _yawLeft:Boolean

Yaw left flag.

_yawRightproperty 
protected var _yawRight:Boolean

Yaw right flag.

_yawSpeedproperty 
protected var _yawSpeed:Number = 1

Angular speed of revolution around yaw axis.

yawSpeedproperty 
yawSpeed:Number  [read-write]

Yaw angular speed (radians per second).

The default value is 1.

Implementation
    public function get yawSpeed():Number
    public function set yawSpeed(value:Number):void
Constructor detail
ObjectController()constructor
public function ObjectController(eventsSourceObject:DisplayObject)

Creates a new instance of controller.

Parameters
eventsSourceObject:DisplayObjectMouse and keyboard events' source.

Throws
ArgumentError — throws if eventsSourceObject is null
Method detail
accelerate()method
public function accelerate(value:Boolean):void

Activation of accelerated speed mode.

Parameters
value:Booleantrue to turn on accelerated mode, false to turn it off
applyDisplacement()method 
protected function applyDisplacement(frameTime:Number, displacement:Point3D):void

The method applies displacement to the controlled object. Default implementation does nothing.

Parameters
frameTime:Numberframe length given in seconds
 
displacement:Point3Dthe displacement to apply
bindKey()method 
public function bindKey(keyCode:uint, action:String):void

The method binds a key to an action. One key can have only one action assigned.

Parameters
keyCode:uintkey code
 
action:Stringaction name

See also

clearCommandFlags()method 
protected function clearCommandFlags():void

The method resets active commands' flags.

getDisplacement()method 
protected function getDisplacement(frameTime:Number, displacement:Point3D):void

The method calculates potential displacement during the current frame. Default implementation does nothing.

Parameters
frameTime:Numberframe length given in seconds
 
displacement:Point3Dcalculated displacement is stored in this parameter
moveBack()method 
public function moveBack(value:Boolean):void

Activation of back movement.

Parameters
value:Booleantrue to start movement, false to stop movement
moveDown()method 
public function moveDown(value:Boolean):void

Activation of down movement.

Parameters
value:Booleantrue to start movement, false to stop movement
moveForward()method 
public function moveForward(value:Boolean):void

Activation of forward movement.

Parameters
value:Booleantrue to start movement, false to stop movement
moveLeft()method 
public function moveLeft(value:Boolean):void

Activation of left movement.

Parameters
value:Booleantrue to start movement, false to stop movement
moveRight()method 
public function moveRight(value:Boolean):void

Activation of right movement.

Parameters
value:Booleantrue to start movement, false to stop movement
moveUp()method 
public function moveUp(value:Boolean):void

Activation of up movement.

Parameters
value:Booleantrue to start movement, false to stop movement
pitchDown()method 
public function pitchDown(value:Boolean):void

Activation of pitching down.

Parameters
value:Booleantrue to start movement, false to stop movement
pitchUp()method 
public function pitchUp(value:Boolean):void

Activation of pitching up.

Parameters
value:Booleantrue to start movement, false to stop movement
processInput()method 
public function processInput():void

The method processes all control influences. If controlled object is not set or enabled property equals to false than the method is skipped.

The method implemets the following algorithm:

readCoords()method 
public function readCoords(point:Point3D):void

The method stores controller's coordinates in the given variable.

Parameters
point:Point3Da variable to store controller's coordinates
registerKeyboardListeners()method 
protected function registerKeyboardListeners():void

The method registers necessary keyboard listeners.

See also

registerMouseListeners()method 
protected function registerMouseListeners():void

The method registers necessary mouse listeners.

See also

rotateObject()method 
protected function rotateObject(frameTime:Number):void

The method rotates the controlled object according to control influences. Default implementation does nothing.

Parameters
frameTime:Numberframe length given in seconds
setDefaultBindings()method 
public function setDefaultBindings():void

The method sets default keys' bindings. The default implementation does nothing.

See also

setMouseLook()method 
public function setMouseLook(value:Boolean):void

The method enables and disables mouse look mode. When mouse look mode is activated, the startMouseLook() method is called. When mouse look mode is deactivated, the stopMouseLook() method is called.

Parameters
value:Boolean

See also

setObjectCoords()method 
protected function setObjectCoords():void

The method sets coordinates of the controlled object depending on the controller's coordinates.

startMouseLook()method 
protected function startMouseLook():void

The method performs the necessary actions when mouse look mode is activated. The default implementation stores initial global mouse coordinates in the startMouseCoords variable.

See also

stopMouseLook()method 
protected function stopMouseLook():void

The method performs the necessary actions when mouse look mode is deactivated. The default implementation does nothing.

See also

unbindAll()method 
public function unbindAll():void

Clear all key bindings.

See also

unbindKey()method 
public function unbindKey(keyCode:uint):void

Clear key binding.

Parameters
keyCode:uintkey code

See also

unregisterKeyboardListeners()method 
protected function unregisterKeyboardListeners():void

The method removes keyboard listeners when keyboard is deactivated.

See also

unregisterMouseListeners()method 
protected function unregisterMouseListeners():void

The method removes mouse listeners when mouse is deactivated.

See also

yawLeft()method 
public function yawLeft(value:Boolean):void

Activation of yawing left.

Parameters
value:Booleantrue to start movement, false to stop movement
yawRight()method 
public function yawRight(value:Boolean):void

Activation of yawing right.

Parameters
value:Booleantrue to start movement, false to stop movement
Constant detail
ACTION_ACCELERATEconstant
public static const ACTION_ACCELERATE:String = "ACTION_ACCELERATE"

Action name for binding ACCELERATE button.

ACTION_BACKconstant 
public static const ACTION_BACK:String = "ACTION_BACK"

Action name for binding BACK movement button.

ACTION_DOWNconstant 
public static const ACTION_DOWN:String = "ACTION_DOWN"

Action name for binding DOWN movement button.

ACTION_FORWARDconstant 
public static const ACTION_FORWARD:String = "ACTION_FORWARD"

Action name for binding FORWARD movement button.

ACTION_LEFTconstant 
public static const ACTION_LEFT:String = "ACTION_LEFT"

Action name for binding LEFT movement button.

ACTION_MOUSE_LOOKconstant 
public static const ACTION_MOUSE_LOOK:String = "ACTION_MOUSE_LOOK"

Action name for binding MOUSE_LOOK button.

ACTION_PITCH_DOWNconstant 
public static const ACTION_PITCH_DOWN:String = "ACTION_PITCH_DOWN"

Action name for binding PITCH_DOWN button.

ACTION_PITCH_UPconstant 
public static const ACTION_PITCH_UP:String = "ACTION_PITCH_UP"

Action name for binding PITCH_UP button.

ACTION_RIGHTconstant 
public static const ACTION_RIGHT:String = "ACTION_RIGHT"

Action name for binding RIGHT movement button.

ACTION_UPconstant 
public static const ACTION_UP:String = "ACTION_UP"

Action name for binding UP movement button.

ACTION_YAW_LEFTconstant 
public static const ACTION_YAW_LEFT:String = "ACTION_YAW_LEFT"

Action name for binding YAW_LEFT button.

ACTION_YAW_RIGHTconstant 
public static const ACTION_YAW_RIGHT:String = "ACTION_YAW_RIGHT"

Action name for binding YAW_RIGHT button.