add docfx samples.
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
using Hi.Geom;
|
||||
using Hi.Disp;
|
||||
using System.Collections.Generic;
|
||||
using Hi.Disp.Treat;
|
||||
using Hi.Coloring;
|
||||
|
||||
namespace Sample.Disp
|
||||
{
|
||||
/// <remarks>
|
||||
/// ### Source Code
|
||||
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoDrawing.cs)]
|
||||
/// </remarks>
|
||||
public static class DemoDrawing
|
||||
{
|
||||
public static void FreeDrawing()
|
||||
{
|
||||
#region DocSite.FreeDrawing
|
||||
double[] vs =
|
||||
{0,0,0
|
||||
,1,0,0
|
||||
,0,0,1};
|
||||
DemoUtil.RunApplication("EasyDraw"
|
||||
, new Drawing(vs, Stamp.V, GL.GL_LINE_STRIP));
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static void DrawLines()
|
||||
{
|
||||
List<Vec3d> ps;
|
||||
double[] vs;
|
||||
int n = 10; //vertex num
|
||||
|
||||
////create drawPoints
|
||||
ps = new List<Vec3d>(n);
|
||||
for (int i = 0; i < n; i++)
|
||||
ps.Add(new Vec3d(i, 0, 0));
|
||||
vs = new double[ps.Count * 3];
|
||||
for (int i = 0; i < ps.Count; i++)
|
||||
{
|
||||
vs[3 * i] = ps[i].x;
|
||||
vs[3 * i + 1] = ps[i].y;
|
||||
vs[3 * i + 2] = ps[i].z;
|
||||
}
|
||||
|
||||
//V means Vertex
|
||||
Drawing drawPoints = new Drawing(vs, Stamp.V, GL.GL_POINTS);
|
||||
|
||||
////create drawLineStrip
|
||||
vs = new double[ps.Count * 3];
|
||||
for (int i = 0; i < ps.Count; i++)
|
||||
{
|
||||
vs[3 * i] = i;
|
||||
vs[3 * i + 1] = 0;
|
||||
vs[3 * i + 2] = 1;
|
||||
}
|
||||
Drawing drawLineStrip = new Drawing(vs, Stamp.V, GL.GL_LINE_STRIP);
|
||||
|
||||
////create drawLineStripWithNormal
|
||||
//the content of vs is Nx,Ny,Nz,Vx,Vy,Vz, Nx,Ny,Nz,Vx,Vy,Vz, ...
|
||||
vs = new double[n * 6];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
//nx,ny,nz
|
||||
vs[6 * i] = 1;
|
||||
vs[6 * i + 1] = 0;
|
||||
vs[6 * i + 2] = 0;
|
||||
//x,y,z
|
||||
vs[6 * i + 3] = i;
|
||||
vs[6 * i + 4] = 0;
|
||||
vs[6 * i + 5] = 2;
|
||||
}
|
||||
//V means Vertex; N means Normal
|
||||
Drawing drawLineStripWithNormal =
|
||||
new Drawing(vs, Stamp.NV, GL.GL_LINE_STRIP);
|
||||
|
||||
////create drawColorLines
|
||||
vs = new double[n * 6];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
//the rgb values set casually.
|
||||
//r,g,b
|
||||
vs[6 * i] = i % 3 / 2D;
|
||||
vs[6 * i + 1] = i % 5 / 4D;
|
||||
vs[6 * i + 2] = i % 7 / 6D;
|
||||
//x,y,z
|
||||
vs[6 * i + 3] = i;
|
||||
vs[6 * i + 4] = 0;
|
||||
vs[6 * i + 5] = 3;
|
||||
}
|
||||
//V means Vertex; C means Color
|
||||
Drawing drawLineStripWithColor = new Drawing(vs, Stamp.CV, GL.GL_LINE_STRIP);
|
||||
|
||||
DemoUtil.RunApplication("DrawLines",
|
||||
new DispList(drawPoints, drawLineStrip
|
||||
, drawLineStripWithNormal, drawLineStripWithColor));
|
||||
}
|
||||
|
||||
public static void DrawTrianglesByPrimitives()
|
||||
{
|
||||
int n = 10;// triangle num
|
||||
double[] vs;
|
||||
|
||||
////create drawTrisCV
|
||||
//each triangle has 3 point; each point has r,g,b,x,y,z, totally 6 doubles.
|
||||
vs = new double[n * 3 * 6];
|
||||
for (int i = 0, k = 0; i < n; i++)
|
||||
{
|
||||
//the rgb values set as casual.
|
||||
Vec3d rgb = ColorUtil.GetDiscreteRgb(i);
|
||||
Tri3d tri = new Tri3d(new Vec3d(i, 0, 0), new Vec3d(i + 1, 0, 0), new Vec3d(i + 0.5, 0, 1));
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
vs[k++] = rgb.x;
|
||||
vs[k++] = rgb.y;
|
||||
vs[k++] = rgb.z;
|
||||
vs[k++] = tri.ps[j].x;
|
||||
vs[k++] = tri.ps[j].y;
|
||||
vs[k++] = tri.ps[j].z;
|
||||
}
|
||||
}
|
||||
//V means Vertex; C means Color
|
||||
Drawing drawTrisCV = new Drawing(vs, Stamp.CV, GL.GL_TRIANGLES);
|
||||
|
||||
////create drawTrisCNV
|
||||
/////each triangle has 3 point; each point has r,g,b,nx,ny,nz,x,y,z, totally 6 doubles.
|
||||
vs = new double[n * 3 * 9];
|
||||
for (int i = 0, k = 0; i < n; i++)
|
||||
{
|
||||
//the rgb values set as casual.
|
||||
Vec3d rgb = ColorUtil.GetDiscreteRgb(i);
|
||||
Tri3d tri = new Tri3d(new Vec3d(i, 0, 3), new Vec3d(i + 1, 0, 3), new Vec3d(i + 0.5, 0, 4));
|
||||
Vec3d nn = tri.GetNormal();
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
vs[k++] = rgb.x;
|
||||
vs[k++] = rgb.y;
|
||||
vs[k++] = rgb.z;
|
||||
vs[k++] = nn.x;
|
||||
vs[k++] = nn.y;
|
||||
vs[k++] = nn.z;
|
||||
vs[k++] = tri.ps[j].x;
|
||||
vs[k++] = tri.ps[j].y;
|
||||
vs[k++] = tri.ps[j].z;
|
||||
}
|
||||
}
|
||||
//V means Vertex; C means Color; N means Normal
|
||||
Drawing drawTrisCNV = new Drawing(vs, Stamp.CNV, GL.GL_TRIANGLES);
|
||||
|
||||
//the color of colorTrisDraw is not influence by outer color setting.
|
||||
DemoUtil.RunApplication("DrawTrianglesByPrimitives",
|
||||
new DispList(new RgbTreat(1, 0, 0), drawTrisCV, drawTrisCNV));
|
||||
}
|
||||
|
||||
public static void DrawTri3d()
|
||||
{
|
||||
int n = 10;
|
||||
List<Tri3d> tris = new List<Tri3d>(n);
|
||||
for (int i = 0; i < n; i++)
|
||||
tris.Add(new Tri3d(new Vec3d(i, 0, 0), new Vec3d(i + 1, 0, 0), new Vec3d(i + 0.5, 0, 1)));
|
||||
|
||||
Drawing faceDraw = tris.GetFaceDrawing();
|
||||
Drawing linesDraw = tris.GetLineDrawing();
|
||||
|
||||
DemoUtil.RunApplication("DrawTri3d",
|
||||
new DispList(new RgbTreat(0, 0, 1), linesDraw
|
||||
, new RgbTreat(1, 0, 0), faceDraw));
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
//FreeDrawing();
|
||||
//DrawLines();
|
||||
//DrawTrianglesByPrimitives();
|
||||
DrawTri3d();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user