Metrics C++ Sample
Metrics C++ sample demonstrates calculation
of distances, and nearest points between two objects and usage of
IMetrics2.Dist method. The sample is a
simplified version of Metrics2 sample.
See also All samples,
Collision detection,
Collision Sample
Running the application
The application expects the model to have at least two top level objects.
Names of the first and the second objects are displayed on the right hand side
of the form. The Calculate button calculates distances between the two objects
and displays the result in 3D view.
By default pairs of nearest points are rendered connected with a red segment
in 3D view. Check boxes in the Display group allow to turning on and off
rendering shortest distances, nearest points and normals.
The Move Object control group allows changing position and orientation of
either of the two objects. The movement is performed relative to the current
location and orientation of the local frame of the object. Show check box
displays or hides the local frame.
The "Is Closer Than" controls allow to determine whether the objects are
closer than the distance specified in the edit box.
File menu allows loading new and saving the current model.
Implementation
All DG Kernel related functionality is implemented inside the MetricsDlg
class. The DG Kernel related data is initialized inside InitModelInfo()
method, which uses GetModel
method of the DG Kernel control to obtain the root
interface of the hierarchy. ISection
interfaces, representing generic DG Kernel object, are obtained for the first
two top level objects of the model with the help of
IModel.GetEntity and stored in
m_iEntityFrom and m_iEntityTo member variables.
In MetricsDlg::InitModelInfo() called on start of the application
IMetrics2
interfaces are queried from relevant ISection
Calculation of distance is performed in OnCalculate() handler,
where
and
IMetrics2.Dist is called.
In this application the calculated nearest points are displayed in 3D view
with line segments and points.
The application uses ClientDraw
event, requested in OnInitDialog(), to add custom drawing of shortest
segments and other elements to the scene. The drawing is performed inside
OnClientDraw handler. In the OnClientDraw method the coordinates of each
vertex are obtained via IVertex.GetVertexCoord.
When rendering of normals, is requested they are obtained with a
IVertex.GetNormal call in
DrawNormals().
Work related to the "Is Closer than" group of controls is done in
OnCalculateCloserThan handler with the help of
IMetrics.IsCloserThan method.
Note that movements of the current object are performed in OnMoveObject
via IFrame2
rather than IFrame
to make movements relative to the current axes.
|