Cannon Sample
Source code for Cannon sample is available in Samples\NET\C# folder of the installation directory. If you are going to compile
the project we suggest to
copy whole VC directory to location outside of the installation folder.
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.
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 method of the MainForm class. The calculation is
performed with
the help of IntersectObject method 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() method 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 visualise location an direction of the line of fire. The Cannon object
is created dynamically at runtime in the CreateCannon method. 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 method. The
drawing is performed directly using IDraw interface.
See also: Delphi Cannon Sample, All C# Samples, All samples
|