3DBugger VB .NET Tutorial
See Overview for general description
and initial steps of the tutorial.
Overview of implementation
Initial tasks for starting the application are performed in
DebuggerForm.Init() called from DebuggerForm.OnFormLoad().
GetVertices() method sets coordinates of the pyramid object
stored in m_vert array of the form.
After that CreateGenerator() method loads DG Kernel component
and obtains IDIObjGenerator
interface from DIObjGenerator COM class
created as new object. The interface is stored in
m_iDIObjGenerator variable. The main debugging related interface
I3DBugger
is queried from
m_iDIObjGenerator and stored as m_i3DBugger.
Notice also Plane and Segment classes in the
project. They are responsible for managing and dumping relevant geometric objects.
Segment object will be used to represent a single shared edge of a flat face of the
pyramid.
The calculation: The algorithm will calculate interentity of all six
segments of the pyramid object with the plane The interentity points will be
stored in m_interentity array. These points are corners of the
interentity polygon, which can also become a segment, a point or an empty set
depending on position and orientation of the plane.
It is convenient to position Visual Studio and 3DBugger windows side by side
as shown on picture below
Debugging the application
- Put break point on the DumpModel() line of DebuggerForm.Calculate()
method. Start the application and press Calculate button
- Step into the DumpModel() call. This method uses
IModel
and IModelEx to load 3Dbugger.mdg model file,
which contains model of the pyramid
- Step Over the m_i3DBugger.DumpObject(iModel, 0, true, false) line and notice the pyramid object, which appeared in
3DBugger window. Notice the name of the object displayed in explorer window.
You can view the object is 3D with all functionality of 3D Debugger
available.
- Step out of the DumpModel() method, step into m_plane.Dump(m_i3DBugger) call. and have a look
at implementation of the Dump method of the Plane
object. The method uses
indirect dump
technique. The dump is performed via
IDrawUtil.Disk, at the line iDrawUtil.Disk(0, 3) Most of the code in
the method is devoted to positioning and orienting the current rendering
frame for IDraw because
IDrawUtil.Disk renders a disk at a
standard location (0,0) of the x and y axes of the current frame.
- Notice how name of the dumped object is set at Util.SetCurrentName(strName, iDraw) line. The
Util.SetCurrentName uses
IKCContext to set the current
Name property of the debugger to
"Plane.." string. The actual dump will be performed at the
i3DBugger.Dump() line of the Plane.Dump()
- Step out of the Plane.Dump() and notice the disk representing the plane
to appear in the debugger window. Name of the object containing hash of the
Plane object is displayed in the Explorer
- In DebuggerForm.Calculate() method step through several lines and step
into the first call of the AddSegmentInterentity() line
- This method calculates interentity of a segment with the plane.
Step over two lines and stop at the segment.Dump()
- Try very useful technique, which sometimes allows debugging without
adding any extra code to the application: Open Debug > Quick Watch
window in Visual Studio and paste segment.Dump() into the expression line.
Press Recalculate button. The segment will appear in the 3D view. Close the
quick watch window
- Step into the segment.Dump() line of DebuggerForm.AddSegmentInterentity().
The method demonstrates
indirect dump using IDraw interface. Notice
the iKCContext.SetBoolParam(0, true) line, which indicates the the
segment must be dumped as a
transient object.
Notice also usage of IKCStack to save the state before the above change
and restore it after the dump.
- Step out up the call stack two times to reach the DebuggerForm.Calculate()
method. Step through the repetitive loops while watching the dumped
segments. Notice how previous segments are removed by the m_i3DBugger.BeginDump
in the start of each loop. It is important that the segment was dumped
as a transient object.
- Notice that when the segment intersects the plane the interentity point
appears in debugger window. This is accomplished in
DebuggerForm.DumpPoint method.
- Let the application to continue (Debug > Continue in
Visual Studio). The final scene displayed in debugger window should look
like:
- :
- The Interentity face is dumped by DebuggerForm.DumpInterentity() using
IDraw
|