using Hi.Geom;
using Hi.Disp;
namespace Sample.Disp
{
///
/// Demonstrates a simple solar system animation using interface.
/// Shows how to create a hierarchical transform structure with sun, earth and moon using
/// matrices and model matrix stack transformations.
///
///
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Disp/DemoSatellite.cs)]
///
public class DemoSatellite : IDisplayee
{
Drawing sun;
Drawing earth;
Drawing moon;
double angle_earth;
double angle_moon;
DemoSatellite()
{
sun = box3d_t.CenterUnitBox.ScaledFromCenter(4).ToDraw_Face();
earth = box3d_t.CenterUnitBox.ScaledFromCenter(2).ToDraw_Face();
moon = box3d_t.CenterUnitBox.ToDraw_Face();
}
///
public void Display(Bind bind)
{
sun.Display(bind);
bind.ModelMatStack.Push();
bind.ModelMatStack.Mul(new mat4d_t(new AxisAngle4d(new vec3d_t(0, 0, 1), angle_earth += 0.03)));
bind.ModelMatStack.Mul(new mat4d_t(new vec3d_t(12, 0, 0)));
earth.Display(bind);
bind.ModelMatStack.Push();
bind.ModelMatStack.Mul(new mat4d_t(new AxisAngle4d(new vec3d_t(0, 0, 1), angle_moon += 0.02)));
bind.ModelMatStack.Mul(new mat4d_t(new vec3d_t(4, 0, 0)));
moon.Display(bind);
bind.ModelMatStack.Pop();
bind.ModelMatStack.Pop();
}
///
public void ExpandToBox3d(ref box3d_t dst)
{
dst = dst.Expanded(new vec3d_t(-14, -14, -2));
dst = dst.Expanded(new vec3d_t(14, 14, 2));
}
static void Main()
{
DemoUtil.Present("DemoSatellite", new DemoSatellite());
}
}
}