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 > .NET Samples > C# Samples > Collision
Collision C# Sample

Collision C# Sample

Source code for Collision sample is available in Samples\NET\C# folder of the installation directory. It is recommended to copy the folder to location outside of the installation folder.

See also Collision detection, Metrics Sample, All samples

Implementation

All KernelCAD related functionality is implemented inside the CollisionForm class. The KernelCAD related data is initialized inside InitModelInfo() method, which uses GetModel method of the KernelCAD control to obtain the root interface of the hierarchy. ISection interfaces, representing generic KernelCAD object, are obtained for the first two top level objects of the model with the help of IModel.GetSection and stored in m_iSectionFrom and m_iSectionTo member variables.

OnMoveObject() Move button handler sets up timer for animation and calculates step vector for each animation step and stores it in m_dAnimationStep variable. On every animation step OnTimer timer event handler increments the current object position and calls IMetrics.IsCloserThan to check whether the collision situation occurred. If IMetrics.IsCloserThan has retuned true, the handler stops animation with a line animationTimer.Enabled = False and calls CalculateDist Sub to process collision situation.

Inside the CalculateDist Sub, identical to one from Metrics Sample, exact distance between the objects and two nearest points are calculated using IMetrics.Dist. The calculated nearest points are displayed in 3D view with red points. To improve performance of rendering IRelation obtained in CalculateDist is converted once to a list and stored in m_pairList member. This work is done by CompileNearestData method, where pairs of the relation are iterated through, correspondent elements of the each per object list are retrieved and converted to the actual type of IVertex.

The application uses ClientDraw event, requested in OnFormLoad(), to add custom drawing of nearest points to the scene. The drawing is performed inside OnClientDraw handler. In the OnClientDraw method the coordinates of each vertex are obtained via IVertex.GetVertexCoord.