KernelCAD Documentation

DInsight Home
Skip Navigation Links.
Start page
Quick Start
Installation
Overview of the software
What is new
Collapse KernelCAD ModelsKernelCAD Models
Collapse KernelCAD ComponentsKernelCAD Components
KernelCAD Control
KernelCAD .NET Control
Methods and Properties
Menu
Model Explorer
Birds Eye View
Programming
Direct User Access
Direct Operations
Interface Queries
Printing Support
Data Types
Modes of KernelCAD Control
DIObjectGenerator class
Properties
FlatObjectArray Poperty
Context
64 bit development
Dual Mode
Initialisation Context
Overlay Editor
Memory Management
Input validation
Collapse Advanced functionalityAdvanced functionality
Collapse InterfacesInterfaces
Alphabetical list
I3DGrid
I3DBugger
I3Dpt
IAxiBase
IAxis
IBoolSection
IBoolSectionEx
IBoundary
IColor
IConstraint
IData
IDiffSurface_KC
IDIFont
IDraw
IDrawUtil
IDraw2
IElem
IElement
IKCLine
ILightSource
ILocation
ILocationEx
IMaterial
IMetrics
IMetrics2
IModel
IModel2
IModelEx
IPatch
IKCPathCollisionDetector
IProfiles
IPropertyArray
IPropertyArray2
IStdShape
IStrip
ISurface
IText
ITexture
ITransform
IUnknown
Collapse Open Cascade TechnologyOpen Cascade Technology
Collapse DataData
Collapse MovementMovement
Collapse FramesFrames
Collapse Oriented ObjectsOriented Objects
Collapse SectionsSections
Collapse GeneralGeneral
Collapse Topological InterfacesTopological Interfaces
Collapse Viewing InterfacesViewing Interfaces
Collapse Lines And CurvesLines And Curves
Collapse Symmetry InterfacesSymmetry Interfaces
Collapse Clipping plane interfacesClipping plane interfaces
Collapse AlgorithmsAlgorithms
Collapse 2D Geometry2D Geometry
Collapse Programming Samples and TutorialsProgramming Samples and Tutorials
Collapse OverviewOverview
Collapse DeploymentDeployment
Collapse .NET Samples.NET Samples
Collapse C++ SamplesC++ Samples
Collapse Visual Basic SamplesVisual Basic Samples
Collapse Delphi SamplesDelphi Samples
Collapse 3D Debugger3D Debugger
Collapse DeploymentDeployment
Licensing
Model Viewer
Open C++ Source
Technical Support
Skip Navigation LinksHome Page > Programming Samples and Tutorials > Delphi Samples > Cannon
Cannon Delphi Sample

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 intersections 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 KernelCAD and Delphi for information about importing  KernelCAD into Borland Developer Studio. 

Running the Cannon Sample

By default the application loads Tank model. The user can load any .glm model. Location and Direction control groups allow positioning of the cannon anywhere in 3D space. Pressing "Fire" button executes calculation of all intersections of line of fire of the cannon with the model. "Objects hit" list boxes display all objects of the model, which have an intersection with the line. 

Controls at the bottom of the page (hidden when there is no intersections) display information about the current intersection points for the currently selected object in the "Objects hit" list and normal of the surface at the point of intersection. This information is immediately updated when a different object is selected in the list or different point is selected as current in "Cur Intersection" up/down control.

The current intersection 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 intersection" radio buttons. In the first mode intersection 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 intersections are displayed for.

"Wire Frame" check box allows changing between surface and wire frame rendering mode.

Implementation

Calculation of intersections 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 intersection. 

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 KernelCAD 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 intersection point are visualized in OnClientDraw KernelCAD 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