Collision Path Native C++ Sample
Description
Implementation
The most important functionality is contained in OnAnimate() handler of the
Animate button, where IMetrics of objects in the
model are added to
Kinematic
Set,, which is a collection of object participated in the detection.
The m_iDetector->Detect(&context, &m_tCollision); line performs
the collision detection and stores collision time in m_tCollision
data member. It will be a large number if there where no collision.
m_iDetector object is created on start of the application in
CollisionPathDlg::OnInitDialog() function.using
IDIObjGenerator::Create( eObjTypePathCollisionDetector ) (See
IDIObjGenerator.Create)
CollisionPathDlg::OnInitDialog() function also creates new
Movement objects and an auxiliary
frame object, which will be used to set / retrieve frames from frame array in
various parts of the program.
SetupDefaultMovement() function, also called from
OnInitDialog(), defines the initial moment paths for each object. The
first object (Cylinder) is translated up by 1 and then is translated to the
right (along x axis) by 3 with rotation around its local y axis. The second
object (Cone) remains in the same position, but rotates by 45 degrees during the
second half of the movement.
Notice also m_iKinematicSet->SetPosition(m_t) call inside
OnTimer handler of timer events, which moves all objects to their
position at the moment m_t.
The
current frame is rendered in OnClientDraw() with
m_iGraphicItemFrame->Draw(); m_iGraphicItemFrame is a
IGraphicItem
implemented by Graphic
Item of the standalone frame CollisionPathDlg::m_iFrame. It is
created in CreateFrameGraphicItem().
|