82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Hi.Disp;
|
|
using Hi.Geom;
|
|
using Hi.Mech.Topo;
|
|
|
|
namespace Sample.Mech
|
|
{
|
|
public class Test : IDisplayee
|
|
{
|
|
/// <inheritdoc/>
|
|
public void Display(Bind bind)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
/// <inheritdoc/>
|
|
public void ExpandToBox3d(Box3d dst)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <remarks>
|
|
/// ### Source Code
|
|
/// [!code-csharp[SampleCode](~/../Hi.Sample/Mech/DemoTopo1.cs)]
|
|
/// </remarks>
|
|
public static class DemoTopo1
|
|
{
|
|
public static (Asmb asmb,Anchor root) GetDemoAsmb()
|
|
{
|
|
#region DocSite.DemoTopo1
|
|
//build coordinate systems and the assembly.
|
|
Asmb asmb = new Asmb { Name = "Mech" };
|
|
Anchor O = new Anchor(asmb, "O");
|
|
Anchor O1 = new Anchor(asmb, "O1");
|
|
Anchor X = new Anchor(asmb, "X");
|
|
Anchor Z = new Anchor(asmb, "Z");
|
|
Anchor B = new Anchor(asmb, "B");
|
|
|
|
//build kinematic link
|
|
Branch.Attach(O, O1, new StaticTranslation(new Vec3d(0, 0, 80)));
|
|
Branch brnX = Branch.Attach(O1, X, new DynamicTranslation(new Vec3d(1, 0, 0)));
|
|
Branch brnZ = Branch.Attach(X, Z, new DynamicTranslation(new Vec3d(0, 0, 1)));
|
|
Branch brnB = Branch.Attach(Z, B, new DynamicRotation(new Vec3d(0, 1, 0), 0, new Vec3d(-100, 0, 0)));
|
|
|
|
//drive the dynamic transformation by single value for each branch.
|
|
brnX.Step = 200;
|
|
brnZ.Step = 100;
|
|
brnB.Step = MathUtil.ToRad(-60);
|
|
|
|
//Get and show the transform matrices relative to O.
|
|
Dictionary<Anchor, Mat4d> matMap = asmb.GetMat4dMap(O);
|
|
Console.WriteLine("Transform Matrix relative to O:");
|
|
foreach (KeyValuePair<Anchor, Mat4d> keyValue in matMap)
|
|
Console.WriteLine($"{keyValue.Key.Name} : {keyValue.Value}");
|
|
#endregion
|
|
|
|
return (asmb,O);
|
|
}
|
|
public static void SnapshotToFile((Asmb asmb, Anchor root) src)
|
|
{
|
|
//all the drawing function has to call DispEngine.Init() before using.
|
|
DispEngine.Init();
|
|
DispEngine.EnableSuppressDefaultLogo = true;
|
|
|
|
using (DispEngine dispEngine = new DispEngine(
|
|
src.asmb.GetAsmbDraw(src.root)))
|
|
{
|
|
dispEngine.SetViewToIsometricView();
|
|
dispEngine.Snapshot("DemoTopo1.bmp", 680, 480);
|
|
}
|
|
Console.WriteLine("Snapshot file output.");
|
|
|
|
DispEngine.FinishDisp();
|
|
}
|
|
static void Main()
|
|
{
|
|
SnapshotToFile(GetDemoAsmb());
|
|
}
|
|
}
|
|
}
|