![]() |
VR-Vantage 3.2 API Documentation
|
This example creates a new driver. On start, this driver will load the Ground_DB II terrain database if it is not already loaded; create and initialize an example sim engine; and attach the main observer to the entity created by the sim engine. On tick, the driver will tick the sim engine. On stop, it will destroy the sim engine.
The example driver's onStart() method loads the database first.
It then creates the example sim engine and initializes it.
Finally, it attaches the current observer to the entity that the sim engine will create by calling attachObserverToEntity.
attachObserverToEntity fills out a DtObserverStateRecord by getting the current state of the current observer, changing the attached state, and then calling DtObserver::setFromRecord on the same observer. setFromRecord has the special property that if an attachment is specified and the entity indicated is not yet available to attach to, the observer listen for signals that elements have been added, until the desired element is created.
The example driver's onTick() method calls the sim engine's tick function, providing the current simulation time from the display engine.
The example driver's onStop() method call's the sim engine's uninit method and then deletes the sim engine if the sim engine exists (it may not, since onStop() may be called multiple times).
The example sim engine creates and updates an entity that includes an entity indicator and a height-above-terrain (HAT) line. The sim engine is constructed with a reference to the display engine (DtDe) which provides access to the agent manager for creating distributed objects; a coordinate system object for converting locations and orientations to the current coordinate system is use; the databank, so that the engine can report element creation and attribute changes; and the main event queue, to listen for mouse over signals for the entity indicator.
The init() method is responsible for creating and initializing the entity, entity indicator, entity information widget, and HAT line.
First, the sim engine creates a new entity facade and tells it to use the F16 Visual Definition.
It creates the entity indicator, and adds the new model agent to the existing entity facade's scene object (so that it will be positioned in the same place).
It creates a HAT line using the DtEntityHATLineFacade, which will create the necessary models and attach to the entity's scene object.
init() then connects to the selection manager's signal_entityInfoToggled.
As labels are pinned or unpinned, this will cause slot_toggleLabelPinnedState to be called. This method updates the visibility of both the indicator and the info label, and also tells the sim to listen or stop listening to the mouse hover signals (detailed below).
The example driver updates the sim engine by calling its tick() method. The sim engine's tick() method updates the F16's position using updatePosition(), and updates the text displayed on the F16's entity info label.
The driver's generateInfoString() method essentially performs some formatting and unit conversion on the information it has about the aircraft's position and orientation in the scene. The value returned from this method is then simply set on the entity info widget (if there is one present - if the mouse isn't hovering, there won't be an info widget).
The driver's updatePosition() method first determines how long it's been since the last update, and updates the aircraft's clock angle based on its angular velocity. The clock angle is the bearing to the aircraft from the point at the center of the aircraft's orbit (0 for north, and increasing in the clockwise direction). It then determines the aircraft's offset from the center of its orbit.
The aircraft's orbit is circular, so computing the heading is as easy as adding 90 degrees (Pi/2) to the clock angle. Once this has been done, the heading and roll can be used to determine the net orientation of the F16.
Now that the F16's position and orientation have been computed, the aircraft can be repositioned in the scene.
Finally, the current time is set as the last update time in preparation for the next update.
Positioning the aircraft takes place in the repositionAircraft(..) method. This method first determines the type of coordinate system using the DtCoordinateConverter, then converts the position and orientation to local database (CIG) coordinates. Finally, the CIG coordinates are set on the entity facade, performing the actual reposition.
The sim engine is unitialized by calling its uninit() method. This cleans up the entity facade, indicator, info widget, and HAT line allocated on the heap. It also tells the DataBank that the element has been destroyed.
The example driver is created, added to the driver manager, and started in the main program.
VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
This example is an application. You can run it by running ./bin64/exampleDistributedObject.exe (on Windows) or ./bin64/exampleDistributedObject (on Linux). Press the "s" key to get away from the entity and see the HAT line. For more information about running examples, please see Running Applications and Examples.
[<< Examples] [Home] [Top of Page]