The MacaoSteeringController can be added to a page to let the user control the "walking" of a vehicle through a net via steering. Steering works by predefining the connection, which the object will use when leaving the next node. See also MacaoObject.setSteeringIndex().
The Steering Controller needs to be registered to the controllenobject by calling MacaoObject.addController(). The object will call the controllers method setControllerSteeringIndex() to set the actual steering index. The steering index is reflected by the steering wheel angle. The user can change the index by using the keys u an o or by clicking the left or right half of the steering wheel. The changed steering index is send back to the object, to predefine the connection, which the object will use, when passing the next node.
The object will also send the current velocity to the steering controller by calling the method steeredVelocityChanged(). If a MacaoAcceleratorController is added to the page and the Accelerator Controller is registered to the Steering Controller calling the method setAcceleratorName(), the velocity is forwarded to the Accelerator Controller. The Accelerator Controller displays the velocity by changing its position.
When the Steering Controller is registered to the Accelerator Controller by calling MacaoAcceleratorController.setSteeringController() and the user clicks the Accelerator Controller, the Accelerator Controller tells the Steering Controller to stop the object.
When the user hits one of the keys u, i or o, the Steering Controller accelerates the object. When the user hits the key k, the Steering Controller stops the object.
Because all information from the object to the Accelerator Controller and back is routed via the Steering Controller, only the Steering Controller has to be registered at the steered object.
The page optional/controllers/controllers.html contains a Steering Controller, an Acceleration Controller and other controllers. You can add this page to a frame in you application. Or you can use the classes MacaoSteeringController and MacaoAcceleratorController to create your own controllers.
The following example adds a Steering Controller and an Accelerator Controller to the page. The Accelerator Controller is optional. So you can add a Steering Controller without an Accelerator Controller.
var controller var accelerator // create steering controller controller = new MacaoSteeringController( "SteeringController", "Accelerator + Key i/- Key k/click to stop", 80, 10 ) // add looks showing the steering wheel in the index angles controller.createLook( "Steering1", "optional/controllers/steering1.gif", 286, 90 ) controller.createLook( "Steering2", "optional/controllers/steering2.gif", 286, 90 ) controller.createLook( "Steering3", "optional/controllers/steering3.gif", 286, 90 ) controller.createLook( "Steering4", "optional/controllers/steering4.gif", 286, 90 ) controller.createLook( "Steering5", "optional/controllers/steering5.gif", 286, 90 ) // set the current index straight ahead controller.setActualLook("Steering3") // link accelerator to steering controller controller.setAcceleratorName("AcceleratorController") // create accelerator controller accelerator = new MacaoAcceleratorController( "AcceleratorController", "Accelerator + Key i/- Key k/click to stop", 380, 70, "optional/controllers/accelerator.gif", 63, 115 ) // set relation beween position and velocity accelerator.setVelocityPosFactor(4) // link steering controller to accelerator accelerator.setSteeringController("SteeringController")
Constructor Summary |
---|
MacaoSteeringController(String name, String title, integer left, integer top)
Use this constructor to create a Steering Controller on the page. |
Method Summary | |
---|---|
integer | getControllerSteeringIndex()
Call this method to get the current Steering Index. |
void | onClick(Event event, integer mouseX, integer mouseY)
This event handler is implemented to get the mouse clicks to change the steering index. |
void | onKeyPress(Event event, integer keyCode, boolean shiftKey, boolean altKey, boolean ctrlKey, String frameName)
This event handler is implemented to get the keystrokes to change the steering index and velocity. |
void | setAcceleratorName(String acceleratorName)
Call this method to register a MacaoAcceleratorController to this Steering Controller. |
void | setVisibility(boolean visibility)
Call this method to show or hide the steering controller and it's assigned accelerator controller. |
void | steer(integer deltaIndex)
Call this method to change the steering index of the controlled object. |
void | stopSteeredObject()
Call this method to stop the controlled object. |
Constructor Details |
---|
Use this constructor to create a Steering Controller on the page.
Method Details |
---|
Call this method to get the current Steering Index.
This event handler is implemented to get the mouse clicks to change the steering index.
You may override this method to change the mouse behavior.
This event handler is implemented to get the keystrokes to change the steering index and velocity.
You may override this method to change the keys, which are used.
Call this method to register a MacaoAcceleratorController to this Steering Controller.
The Accelerator Controller will get the velocity information of the controlled object.
Call this method to show or hide the steering controller and it's assigned accelerator controller.
Call this method to change the steering index of the controlled object.
Calling this value will also accelerate the controlled object.
Call this method to stop the controlled object.