Cannon Delphi Sample
Cannon sample is available in Enterprise level products only.
The source code is located in Samples\Delphi folder of the installation directory.
Cannon is an advanced sample. It demonstrates calculation on
interentitys on a line with all objects in the model. It also demonstrates
direct user drawing with IDraw interface, Runtime creation and manipulation of
objects, programmatic manipulation of view with ILook interface and
runtime programmatic positioning and arranging objects in the model.
See DG Kernel and Delphi for information about
importing DG Kernel into Borland Developer Studio.
Running the Cannon Sample
By default the application loads Tank model. The user can load any
.mdg model. Location and Direction control groups allow positioning of the
cannon anywhere in 3D space. Pressing "Fire" button executes
calculation of all interentitys of line of fire of the cannon with the model.
"Objects hit" list boxes display all objects of the model, which have
an interentity with the line.
Controls at the bottom of the page (hidden when there is no interentitys)
display information about the current interentity points for the currently
selected object in the "Objects hit" list and normal of the surface at
the point of interentity. This information is immediately updated when a
different object is selected in the list or different point is selected as
current in "Cur Interentity" up/down control.
The current interentity point and normal to the surface at the point are displayed
in 3D with red and black lines.
The application works in two modes, determined by selection in "List
interentity" radio buttons. In the first mode interentity points with all
objects in the model are calculated and displayed. In the second model "Hit
list" list box allows selection of which object in the model interentitys
are displayed for.
"Wire Frame" check box allows changing between surface and wire
frame rendering mode.
Implementation
Calculation of interentitys of each object in the model with the line of
fire is done in OnFire procedure of the MainForm class. The calculation is
performed with
the help of IntersectObject
procedure of ILineMetr interface.
The result of the calculation is an IData interface, which gives access to
array of records one per object interentity.
On start or load of a model InitModelInfo() procedure retrieves array of all
objects in the model irrespectively to child/parent relationship via FlatObjectArray
property of the model.
In addition to the loaded model the DG Kernel Control displays model of a
cannon to visualize location an direction of the line of fire. The Cannon object
is created dynamically at runtime in the CreateCannon procedure. The cannon consists of
four sub-objects. Child objects are added to the cannon object with IArray
queried from m_iCannon ISection interface.
Cannon itself is added to the model with IArray
queried from the model (array of top level objects).
Positioning of the Cannon is done in MoveCannon, the "Apply" button
handler.
Line of fire and normal at the interentity point are visualized in
OnClientDraw DG Kernel event handler. The event is activated with a call
RequestClientDraw(true) in OnFire procedure. The
drawing is performed directly using IDraw interface.
See also: C# Cannon Sample, All Delphi Samples,
C# Samples, All samples
|