Class DemoPick2
Demonstrates advanced object picking with multiple pickable objects. Shows how to create and manage multiple pickable objects with different visual appearances. Implements proper resource cleanup through the IDisposable interface.
public class DemoPick2 : IDisplayee, IExpandToBox3d, IDisposable
- Inheritance
-
DemoPick2
- Implements
- Inherited Members
Remarks
Source Code
using Hi.Geom;
using Hi.Disp;
using System;
using Hi.Coloring;
namespace Sample.Disp
{
/// <summary>
/// Demonstrates advanced object picking with multiple pickable objects.
/// Shows how to create and manage multiple pickable objects with different visual appearances.
/// Implements proper resource cleanup through the IDisposable interface.
/// </summary>
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoPick2.cs)]
/// </remarks>
public class DemoPick2 : IDisplayee, IDisposable
{
readonly Pickable pickableA = new ShowEventPickable { Tag = "A" };
readonly Pickable pickableB = new ShowEventPickable { Tag = "B" };
readonly Pickable pickableC = new ShowEventPickable { Tag = "C" };
/// <inheritdoc/>
public void Display(Bind bind)
{
bind.PickID = pickableA.PickingID;
bind.Rgb = ColorUtil.GetDiscreteRgb(1);
new Box3d(0, 0, 0, 1, 1, 1).DisplayFace(bind);
bind.PickID = pickableB.PickingID;
bind.Rgb = ColorUtil.GetDiscreteRgb(2);
new Box3d(0, 0, 1, 1, 1, 2).DisplayFace(bind);
bind.PickID = pickableC.PickingID;
bind.Rgb = ColorUtil.GetDiscreteRgb(3);
new Box3d(0, 0, 2, 1, 1, 3).DisplayFace(bind);
bind.PickID = 0;
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
dst.Expand(new Vec3d(0, 0, 0));
dst.Expand(new Vec3d(1, 1, 3));
}
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
/// <inheritdoc/>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
pickableA.Dispose();
pickableB.Dispose();
pickableC.Dispose();
}
disposedValue = true;
}
}
/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
}
#endregion
/// <summary>
/// Entry point for the DemoPick2 example.
/// Creates and displays multiple pickable objects with distinct colors and positions.
/// Demonstrates separation of picking behavior from visual representation.
/// </summary>
static void Main()
{
DemoUtil.RunApplication("DemoPick2", new DemoPick2());
}
}
}
Methods
Display(Bind)
Display function called in DispEngine rendering loop.
public void Display(Bind bind)
Parameters
bindBindBind with DispEngine. See Bind.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
ExpandToBox3d(Box3d)
Expands the destination box. This function is usually used to compute the bounding box of elements.
public void ExpandToBox3d(Box3d dst)
Parameters
dstBox3dDestination box