Class DemoPick1
Demonstrates basic object picking with mouse interaction in the HiAPI system. Shows how to create a pickable 3D object that responds to mouse events by changing its appearance. Implements the Pickable base class to enable mouse event handling.
public class DemoPick1 : Pickable, IGetPickable, IDisposable, IDisplayee, IExpandToBox3d
- Inheritance
-
DemoPick1
- Implements
- Inherited Members
Remarks
Source Code
using Hi.Geom;
using Hi.Disp;
using Hi.Native;
namespace Sample.Disp
{
/// <summary>
/// Demonstrates basic object picking with mouse interaction in the HiAPI system.
/// Shows how to create a pickable 3D object that responds to mouse events by changing its appearance.
/// Implements the Pickable base class to enable mouse event handling.
/// </summary>
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoPick1.cs)]
/// </remarks>
public class DemoPick1 : Pickable, IDisplayee
{
bool isMouseOver = false;
/// <inheritdoc/>
public void Display(Bind bind)
{
bind.PickID = PickingID;
bind.Rgb = new Vec3d(isMouseOver ? 0 : 1, 1, 1);
new Box3d(0, 0, 0, 1, 1, 1).DisplayFace(bind);
bind.PickID = 0;
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
dst.Expand(new Vec3d(0, 0, 0));
dst.Expand(new Vec3d(1, 1, 1));
}
/// <inheritdoc/>
public override void OnMouseEnter(ui_event_type e, DispEngine dispEngine)
{
isMouseOver = true;
}
/// <inheritdoc/>
public override void OnMouseLeave(ui_event_type e, DispEngine dispEngine)
{
isMouseOver = false;
}
/// <summary>
/// Entry point for the DemoPick1 example.
/// Creates and displays a simple pickable object that changes color on mouse hover.
/// </summary>
static void Main()
{
DemoUtil.RunApplication("DemoPick1", new DemoPick1());
}
}
}
Methods
Display(Bind)
Display function called in DispEngine rendering loop.
public void Display(Bind bind)
Parameters
bindBindBind with DispEngine. See Bind.
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
OnMouseEnter(ui_event_type, DispEngine)
Behavior on mouse enter
public override void OnMouseEnter(ui_event_type e, DispEngine dispEngine)
Parameters
eui_event_typeevent type
dispEngineDispEnginedisplay engine
OnMouseLeave(ui_event_type, DispEngine)
Behavior on mouse leave
public override void OnMouseLeave(ui_event_type e, DispEngine dispEngine)
Parameters
eui_event_typeevent type
dispEngineDispEnginedisplay engine