Packagealternativa.engine3d.controllers
Classpublic class WalkController
InheritanceWalkController Inheritance ObjectController

The class provides FPS-like control of an object's movement in the scene's root object's coordinate system.

The are two control modes: walk mode with gravity imitation and fly mode in which gravity isn't taken into account. If collision detection is disabled, then the gravity also ignored in walk mode. In this case the controlled object gets an ability to move along vertical axis.

For objects that are not of class Camera3D the "forward" direction mathes the direction of local Y axis, the "up" direction matches the direction of Z axis. For objects of class Camera3D the "forwrad" direction matches the direction of local Z axis and the "up" direction is opposite to the direction of local Y axis.

Regardless, whether collision detection is enabled or not, coordinates are calculated for an ellipsoid, which parameters are set via collider property. The controlled object's coordinates are calculated depending on the ellipsoid's center position and the object's position on the vertical axis of the ellipsoid, determined by objectZPosition parameter.

The ACTION_UP command in walk mode with non-zero gravity makes a jump, in other cases it starts upward movement.



Public Properties
 PropertyDefined by
 Inheritedaccelerated : Boolean
The accelerated speed mode flag.
ObjectController
  airControlCoefficient : Number
Coefficient of efficiency of the movement controls in walk mode while in the air.
WalkController
 InheritedcheckCollisions : Boolean
Enabling and disabling collision detection mode.
ObjectController
 Inheritedcollider : EllipsoidCollider
EllipsoidCollider object.
ObjectController
 Inheritedcoords : Point3D
Coordinates of the controller.
ObjectController
  currentSpeed : Number
[read-only] The current speed.
WalkController
  enabled : Boolean
[write-only]
WalkController
  flyMode : Boolean
Enabling and disabling fly mode.
WalkController
  gravity : Number = 0
Acceleration of gravity.
WalkController
  groundMesh : Mesh
[read-only] If the gravity isn't zero, this property references the object, on which the ellipsoid stands.
WalkController
  jumpSpeed : Number = 0
Vertical speed in the moment of jump.
WalkController
 InheritedkeyboardEnabled : Boolean
Enabling and disabling processing of keyboard events.
ObjectController
  maxGroundAngle : Number
Maximum angle of surface inclination in radians, by which jumps are still possible and the object remains motionless without controller's influence.
WalkController
  maxPitch : Number
maximum pitch angle in radians
WalkController
  minPitch : Number
minimum pitch angle in radians
WalkController
 InheritedmouseEnabled : Boolean
Enabling and disabling processing of mouse events.
ObjectController
 InheritedmouseSensitivity : Number
Mouse sensitivity — multiplication coefficient of mouseSensitivityX and mouseSensitivityY.
ObjectController
 InheritedmouseSensitivityX : Number
Horizontal mouse sensitivity.
ObjectController
 InheritedmouseSensitivityY : Number
Vertical mouse sensitivity.
ObjectController
 Inheritedobject : Object3D
Controlled object.
ObjectController
  objectZPosition : Number
Position of the controlled object on Z axis of the ellipsoid.
WalkController
  onGround : Boolean
[read-only] In the walk mode this property shows if the ellipsoid is on a ground.
WalkController
 InheritedonStartMoving : Function
Function defined as function():void, which is called when the controlled object starts to move.
ObjectController
 InheritedonStopMoving : Function
Function defined as function():void, which is called when the controlled object stops moving.
ObjectController
 InheritedpitchSpeed : Number
Pitch angular speed (radians per second).
ObjectController
 Inheritedspeed : Number
Speed of the controlled object in units per second.
ObjectController
 InheritedspeedMultiplier : Number
Speed multiplier on acceleration.
ObjectController
  speedThreshold : Number = 1
Speed measurement threshold.
WalkController
 InheritedyawSpeed : Number
Yaw angular speed (radians per second).
ObjectController
Protected Properties
 PropertyDefined by
 Inherited_accelerate : Boolean
Accelerated mode flag.
ObjectController
 InheritedactionBindings : Map
Map which binds actions' names and actions' handlers.
ObjectController
 Inherited_back : Boolean
Back movement flag.
ObjectController
 Inherited_collider : EllipsoidCollider
EllipsoidCollider for collision detection.
ObjectController
 Inherited_coords : Point3D
Controller's current coordinates.
ObjectController
 Inherited_down : Boolean
Down movement flag.
ObjectController
 Inherited_enabled : Boolean = true
Controller's activity flag.
ObjectController
 Inherited_eventsSource : DisplayObject
Keyboard and mouse events' source.
ObjectController
 Inherited_forward : Boolean
Forward movement flag.
ObjectController
 Inherited_isMoving : Boolean
The flag shows if the controlled object moved in the current frame.
ObjectController
 InheritedkeyBindings : Map
Map which binds key codes with actions' names.
ObjectController
 Inherited_keyboardEnabled : Boolean
The flag shows if keyboard is enabled.
ObjectController
 InheritedlastFrameTime : uint
The time that passed since the last call of the processInput() method.
ObjectController
 Inherited_left : Boolean
Left movement flag.
ObjectController
 Inherited_mouseCoefficientX : Number
Resulting horizontal mouse sensitivity.
ObjectController
 Inherited_mouseCoefficientY : Number
Resulting vertical mouse sensitivity.
ObjectController
 Inherited_mouseEnabled : Boolean
Mouse activity flag.
ObjectController
 Inherited_mouseLookActive : Boolean
Mouse look mode activity flag.
ObjectController
 Inherited_mouseSensitivity : Number = 1
Mouse sensitivity — multiplication coefficient for horizontal and vertical sensitivities.
ObjectController
 Inherited_mouseSensitivityX : Number
Horizontal mouse sensitivity.
ObjectController
 Inherited_mouseSensitivityY : Number
Vertical mouse sensitivity.
ObjectController
 Inherited_object : Object3D
Controlled object.
ObjectController
 Inherited_pitchDown : Boolean
pitch down flag
ObjectController
 Inherited_pitchSpeed : Number = 1
Angular speed of revolution around pitch axis.
ObjectController
 Inherited_pitchUp : Boolean
Pitch up flag.
ObjectController
 Inherited_right : Boolean
Right movement flag.
ObjectController
 Inherited_speed : Number = 100
Speed of controller.
ObjectController
 Inherited_speedMultiplier : Number = 2
Speed multiplication coefficient in accelerated mode.
ObjectController
 InheritedstartMouseCoords : Point3D
Starting coordinates of the mouse cursor in mouse look mode.
ObjectController
 Inherited_up : Boolean
Up movement flag.
ObjectController
 Inherited_yawLeft : Boolean
Yaw left flag.
ObjectController
 Inherited_yawRight : Boolean
Yaw right flag.
ObjectController
 Inherited_yawSpeed : Number = 1
Angular speed of revolution around yaw axis.
ObjectController
Public Methods
 MethodDefined by
  
WalkController(eventSourceObject:DisplayObject, object:Object3D = null)
Creates a new instance of controller.
WalkController
 Inherited
accelerate(value:Boolean):void
Activation of accelerated speed mode.
ObjectController
 Inherited
bindKey(keyCode:uint, action:String):void
The method binds a key to an action.
ObjectController
  
lookAt(point:Point3D):void
Aiming object to the point.
WalkController
 Inherited
moveBack(value:Boolean):void
Activation of back movement.
ObjectController
 Inherited
moveDown(value:Boolean):void
Activation of down movement.
ObjectController
 Inherited
moveForward(value:Boolean):void
Activation of forward movement.
ObjectController
 Inherited
moveLeft(value:Boolean):void
Activation of left movement.
ObjectController
 Inherited
moveRight(value:Boolean):void
Activation of right movement.
ObjectController
  
moveUp(value:Boolean):void
Activation of up movement.
WalkController
 Inherited
pitchDown(value:Boolean):void
Activation of pitching down.
ObjectController
 Inherited
pitchUp(value:Boolean):void
Activation of pitching up.
ObjectController
 Inherited
processInput():void
The method processes all control influences.
ObjectController
 Inherited
readCoords(point:Point3D):void
The method stores controller's coordinates in the given variable.
ObjectController
  
The method clears all keys' bindings and sets the default bindings:
КлавишаДействие
WACTION_FORWARD
SACTION_BACK
AACTION_LEFT
DACTION_RIGHT
SPACEACTION_UP
ZACTION_DOWN
SHIFTACTION_ACCELERATE
UPACTION_PITCH_UP
DOWNACTION_PITCH_DOWN
LEFTACTION_YAW_LEFT
RIGHTACTION_YAW_RIGHT
MACTION_MOUSE_LOOK
WalkController
 Inherited
setMouseLook(value:Boolean):void
The method enables and disables mouse look mode.
ObjectController
 Inherited
unbindAll():void
Clear all key bindings.
ObjectController
 Inherited
unbindKey(keyCode:uint):void
Clear key binding.
ObjectController
 Inherited
yawLeft(value:Boolean):void
Activation of yawing left.
ObjectController
 Inherited
yawRight(value:Boolean):void
Activation of yawing right.
ObjectController
Protected Methods
 MethodDefined by
  
applyDisplacement(frameTime:Number, displacement:Point3D):void
The method applies specified displacement vector to ellipsoid considering collision detection if needed.
WalkController
 Inherited
The method resets active commands' flags.
ObjectController
  
getDisplacement(frameTime:Number, displacement:Point3D):void
The method calculates potential displacement of the ellipsoid, taking into account control mode, movement commands and gravity.
WalkController
 Inherited
The method registers necessary keyboard listeners.
ObjectController
 Inherited
The method registers necessary mouse listeners.
ObjectController
  
rotateObject(frameTime:Number):void
The method rotates the controlled object.
WalkController
  
The method sets the controlled object's coordinates depending on value of objectZPosition property.
WalkController
  
The method performs necessary actions when mouse is enabled.
WalkController
 Inherited
The method performs the necessary actions when mouse look mode is deactivated.
ObjectController
 Inherited
The method removes keyboard listeners when keyboard is deactivated.
ObjectController
 Inherited
The method removes mouse listeners when mouse is deactivated.
ObjectController
Public Constants
 ConstantDefined by
 InheritedACTION_ACCELERATE : String = "ACTION_ACCELERATE"
[static] Action name for binding ACCELERATE button.
ObjectController
 InheritedACTION_BACK : String = "ACTION_BACK"
[static] Action name for binding BACK movement button.
ObjectController
 InheritedACTION_DOWN : String = "ACTION_DOWN"
[static] Action name for binding DOWN movement button.
ObjectController
 InheritedACTION_FORWARD : String = "ACTION_FORWARD"
[static] Action name for binding FORWARD movement button.
ObjectController
 InheritedACTION_LEFT : String = "ACTION_LEFT"
[static] Action name for binding LEFT movement button.
ObjectController
 InheritedACTION_MOUSE_LOOK : String = "ACTION_MOUSE_LOOK"
[static] Action name for binding MOUSE_LOOK button.
ObjectController
 InheritedACTION_PITCH_DOWN : String = "ACTION_PITCH_DOWN"
[static] Action name for binding PITCH_DOWN button.
ObjectController
 InheritedACTION_PITCH_UP : String = "ACTION_PITCH_UP"
[static] Action name for binding PITCH_UP button.
ObjectController
 InheritedACTION_RIGHT : String = "ACTION_RIGHT"
[static] Action name for binding RIGHT movement button.
ObjectController
 InheritedACTION_UP : String = "ACTION_UP"
[static] Action name for binding UP movement button.
ObjectController
 InheritedACTION_YAW_LEFT : String = "ACTION_YAW_LEFT"
[static] Action name for binding YAW_LEFT button.
ObjectController
 InheritedACTION_YAW_RIGHT : String = "ACTION_YAW_RIGHT"
[static] Action name for binding YAW_RIGHT button.
ObjectController
Property detail
airControlCoefficientproperty
airControlCoefficient:Number  [read-write]

Coefficient of efficiency of the movement controls in walk mode while in the air. Zero means the controls are completely disabled, 1 means that the controls are so efficient as if the object would be on a ground.

The default value is 1.

Implementation
    public function get airControlCoefficient():Number
    public function set airControlCoefficient(value:Number):void
currentSpeedproperty 
currentSpeed:Number  [read-only]

The current speed.

Implementation
    public function get currentSpeed():Number
enabledproperty 
enabled:Boolean  [write-only]

Implementation
    public function set enabled(value:Boolean):void
flyModeproperty 
flyMode:Boolean  [read-write]

Enabling and disabling fly mode.

The default value is false.

Implementation
    public function get flyMode():Boolean
    public function set flyMode(value:Boolean):void
gravityproperty 
public var gravity:Number = 0

Acceleration of gravity. Positive value means the gravity force is directed opposite to the global Z axis.

groundMeshproperty 
groundMesh:Mesh  [read-only]

If the gravity isn't zero, this property references the object, on which the ellipsoid stands. If this property is null, then the ellipsod is in the air.

Implementation
    public function get groundMesh():Mesh
jumpSpeedproperty 
public var jumpSpeed:Number = 0

Vertical speed in the moment of jump.

maxGroundAngleproperty 
maxGroundAngle:Number  [read-write]

Maximum angle of surface inclination in radians, by which jumps are still possible and the object remains motionless without controller's influence. If the inclination angle is greater than given maximum, the onGround property will be set to false.

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

See also

maxPitchproperty 
public var maxPitch:Number

maximum pitch angle in radians

The default value is Math.PI / 2.

See also

minPitch
minPitchproperty 
public var minPitch:Number

minimum pitch angle in radians

The default value is -Math.PI / 2.

See also

maxPitch
objectZPositionproperty 
objectZPosition:Number  [read-write]

Position of the controlled object on Z axis of the ellipsoid. Value of zero means that the object is at the lowest point of the ellipsoid, 1 means that the object is at the highest point of the ellipsoid.

Implementation
    public function get objectZPosition():Number
    public function set objectZPosition(value:Number):void
onGroundproperty 
onGround:Boolean  [read-only]

In the walk mode this property shows if the ellipsoid is on a ground. The ellipsoid is on a ground when angle of inclination of the surface beneath the ellipsoid is less than value of the maxGroundAngle property.

Implementation
    public function get onGround():Boolean

See also

speedThresholdproperty 
public var speedThreshold:Number = 1

Speed measurement threshold. In fly mode or in walk mode when the ellipsoid is on the ground, velocity is set to zero if it's magnitude doesn't exceed given threshold.

Constructor detail
WalkController()constructor
public function WalkController(eventSourceObject:DisplayObject, object:Object3D = null)

Creates a new instance of controller.

Parameters
eventSourceObject:DisplayObjectMouse and keyboard events' source.
 
object:Object3D (default = null)controlled object

Throws
ArgumentError — throws if eventsSourceObject is null
Method detail
applyDisplacement()method
protected override function applyDisplacement(frameTime:Number, displacement:Point3D):void

The method applies specified displacement vector to ellipsoid considering collision detection if needed.

Parameters
frameTime:Numberframe length given in seconds
 
displacement:Point3Dthe ellipsoid's displacement vector
getDisplacement()method 
protected override function getDisplacement(frameTime:Number, displacement:Point3D):void

The method calculates potential displacement of the ellipsoid, taking into account control mode, movement commands and gravity.

Parameters
frameTime:Numberframe length given in seconds
 
displacement:Point3Dcalculated displacement is stored in this parameter
lookAt()method 
public function lookAt(point:Point3D):void

Aiming object to the point. The "forward" axis of the object becomes directed to the specified point. Angle of rotation around "forward" axis is set to zero.

Parameters
point:Point3Dcoordinates of the target point
moveUp()method 
public override function moveUp(value:Boolean):void

Activation of up movement.

Parameters
value:Booleantrue to start movement, false to stop movement
rotateObject()method 
protected override function rotateObject(frameTime:Number):void

The method rotates the controlled object. Pitch angle is restricted to interval [-90, 90] in degrees.

Parameters
frameTime:Numberframe length given in seconds

See also

minPitch
maxPitch
setDefaultBindings()method 
public override function setDefaultBindings():void

The method clears all keys' bindings and sets the default bindings:

КлавишаДействие
WACTION_FORWARD
SACTION_BACK
AACTION_LEFT
DACTION_RIGHT
SPACEACTION_UP
ZACTION_DOWN
SHIFTACTION_ACCELERATE
UPACTION_PITCH_UP
DOWNACTION_PITCH_DOWN
LEFTACTION_YAW_LEFT
RIGHTACTION_YAW_RIGHT
MACTION_MOUSE_LOOK

setObjectCoords()method 
protected override function setObjectCoords():void

The method sets the controlled object's coordinates depending on value of objectZPosition property.

See also

startMouseLook()method 
protected override function startMouseLook():void

The method performs necessary actions when mouse is enabled.