502 lines
17 KiB
HTML
502 lines
17 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Class DemoDrawing | HiAPI-C# 2025 </title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="title" content="Class DemoDrawing | HiAPI-C# 2025 ">
|
|
|
|
<meta name="description" content="Demonstrates various drawing techniques using the HiAPI graphics system. Provides examples of primitive drawing, attribute specification, and rendering options. Includes methods for drawing lines, points, triangles, and other geometric primitives.">
|
|
<link rel="icon" href="../img/HiAPI.favicon.ico">
|
|
<link rel="stylesheet" href="../public/docfx.min.css">
|
|
<link rel="stylesheet" href="../public/main.css">
|
|
<meta name="docfx:navrel" content="../toc.html">
|
|
<meta name="docfx:tocrel" content="toc.html">
|
|
|
|
<meta name="docfx:rel" content="../">
|
|
|
|
|
|
|
|
<meta name="loc:inThisArticle" content="In this article">
|
|
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
|
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
|
<meta name="loc:tocFilter" content="Filter by title">
|
|
<meta name="loc:nextArticle" content="Next">
|
|
<meta name="loc:prevArticle" content="Previous">
|
|
<meta name="loc:themeLight" content="Light">
|
|
<meta name="loc:themeDark" content="Dark">
|
|
<meta name="loc:themeAuto" content="Auto">
|
|
<meta name="loc:changeTheme" content="Change theme">
|
|
<meta name="loc:copy" content="Copy">
|
|
<meta name="loc:downloadPdf" content="Download PDF">
|
|
|
|
<script type="module" src="./../public/docfx.min.js"></script>
|
|
|
|
<script>
|
|
const theme = localStorage.getItem('theme') || 'auto'
|
|
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
|
|
<header class="bg-body border-bottom">
|
|
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
|
<div class="container-xxl flex-nowrap">
|
|
<a class="navbar-brand" href="../index.html">
|
|
<img id="logo" class="svg" src="../img/HiAPI.logo.png" alt="">
|
|
|
|
</a>
|
|
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
|
<i class="bi bi-three-dots"></i>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navpanel">
|
|
<div id="navbar">
|
|
<form class="search" role="search" id="search">
|
|
<i class="bi bi-search"></i>
|
|
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-xxl">
|
|
<div class="toc-offcanvas">
|
|
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
|
<div class="offcanvas-header">
|
|
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
|
</div>
|
|
<div class="offcanvas-body">
|
|
<nav class="toc" id="toc"></nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="actionbar">
|
|
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
|
<i class="bi bi-list"></i>
|
|
</button>
|
|
|
|
<nav id="breadcrumb"></nav>
|
|
</div>
|
|
|
|
<article data-uid="Sample.Disp.DemoDrawing">
|
|
|
|
|
|
|
|
<h1 id="Sample_Disp_DemoDrawing" data-uid="Sample.Disp.DemoDrawing" class="text-break">
|
|
Class DemoDrawing
|
|
</h1>
|
|
|
|
<div class="facts text-secondary">
|
|
<dl><dt>Namespace</dt><dd><a class="xref" href="Sample.html">Sample</a>.<a class="xref" href="Sample.Disp.html">Disp</a></dd></dl>
|
|
<dl><dt>Assembly</dt><dd>Hi.Sample.Wpf.dll</dd></dl>
|
|
</div>
|
|
|
|
<div class="markdown summary"><p>Demonstrates various drawing techniques using the HiAPI graphics system.
|
|
Provides examples of primitive drawing, attribute specification, and rendering options.
|
|
Includes methods for drawing lines, points, triangles, and other geometric primitives.</p>
|
|
</div>
|
|
<div class="markdown conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static class DemoDrawing</code></pre>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<dl class="typelist inheritance">
|
|
<dt>Inheritance</dt>
|
|
<dd>
|
|
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
|
|
<div><span class="xref">DemoDrawing</span></div>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
<dl class="typelist inheritedMembers">
|
|
<dt>Inherited Members</dt>
|
|
<dd>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
|
|
|
|
|
|
<h2 id="Sample_Disp_DemoDrawing_remarks">Remarks</h2>
|
|
<div class="markdown level0 remarks"><h3 id="source-code">Source Code</h3>
|
|
<pre><code class="lang-csharp" name="SampleCode">using Hi.Geom;
|
|
using Hi.Disp;
|
|
using System.Collections.Generic;
|
|
using Hi.Disp.Treat;
|
|
using Hi.Coloring;
|
|
|
|
namespace Sample.Disp
|
|
{
|
|
/// <summary>
|
|
/// Demonstrates various drawing techniques using the HiAPI graphics system.
|
|
/// Provides examples of primitive drawing, attribute specification, and rendering options.
|
|
/// Includes methods for drawing lines, points, triangles, and other geometric primitives.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// ### Source Code
|
|
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoDrawing.cs)]
|
|
/// </remarks>
|
|
public static class DemoDrawing
|
|
{
|
|
/// <summary>
|
|
/// Demonstrates simple line drawing using raw vertex coordinates.
|
|
/// Creates a basic line strip from three vertices and displays it using DemoUtil.
|
|
/// </summary>
|
|
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
|
|
}
|
|
|
|
/// <summary>
|
|
/// Demonstrates various types of line drawing techniques.
|
|
/// Shows how to create points, line strips, line strips with normals, and colored line strips.
|
|
/// Illustrates different ways to specify vertex attributes like position, color, and normal.
|
|
/// </summary>
|
|
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));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Demonstrates drawing triangles using OpenGL primitives.
|
|
/// Shows how to create colored triangles (CV) and colored triangles with normals (CNV).
|
|
/// Illustrates packing of vertex attributes (color, normal, position) into arrays for rendering.
|
|
/// </summary>
|
|
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));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Demonstrates drawing 3D triangles using the Tri3d helper class.
|
|
/// Creates a series of triangles and renders them as both face (filled) and line (wireframe) drawings.
|
|
/// Shows how to apply different colors to faces and lines of the same geometry.
|
|
/// </summary>
|
|
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.ToLineDrawing();
|
|
|
|
DemoUtil.RunApplication("DrawTri3d",
|
|
new DispList(new RgbTreat(0, 0, 1), linesDraw
|
|
, new RgbTreat(1, 0, 0), faceDraw));
|
|
}
|
|
|
|
static void Main()
|
|
{
|
|
//FreeDrawing();
|
|
//DrawLines();
|
|
//DrawTrianglesByPrimitives();
|
|
DrawTri3d();
|
|
}
|
|
}
|
|
}
|
|
</code></pre></div>
|
|
|
|
|
|
<h2 class="section" id="methods">Methods
|
|
</h2>
|
|
|
|
|
|
<a id="Sample_Disp_DemoDrawing_DrawLines_" data-uid="Sample.Disp.DemoDrawing.DrawLines*"></a>
|
|
|
|
<h3 id="Sample_Disp_DemoDrawing_DrawLines" data-uid="Sample.Disp.DemoDrawing.DrawLines">
|
|
DrawLines()
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Demonstrates various types of line drawing techniques.
|
|
Shows how to create points, line strips, line strips with normals, and colored line strips.
|
|
Illustrates different ways to specify vertex attributes like position, color, and normal.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static void DrawLines()</code></pre>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="Sample_Disp_DemoDrawing_DrawTri3d_" data-uid="Sample.Disp.DemoDrawing.DrawTri3d*"></a>
|
|
|
|
<h3 id="Sample_Disp_DemoDrawing_DrawTri3d" data-uid="Sample.Disp.DemoDrawing.DrawTri3d">
|
|
DrawTri3d()
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Demonstrates drawing 3D triangles using the Tri3d helper class.
|
|
Creates a series of triangles and renders them as both face (filled) and line (wireframe) drawings.
|
|
Shows how to apply different colors to faces and lines of the same geometry.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static void DrawTri3d()</code></pre>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="Sample_Disp_DemoDrawing_DrawTrianglesByPrimitives_" data-uid="Sample.Disp.DemoDrawing.DrawTrianglesByPrimitives*"></a>
|
|
|
|
<h3 id="Sample_Disp_DemoDrawing_DrawTrianglesByPrimitives" data-uid="Sample.Disp.DemoDrawing.DrawTrianglesByPrimitives">
|
|
DrawTrianglesByPrimitives()
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Demonstrates drawing triangles using OpenGL primitives.
|
|
Shows how to create colored triangles (CV) and colored triangles with normals (CNV).
|
|
Illustrates packing of vertex attributes (color, normal, position) into arrays for rendering.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static void DrawTrianglesByPrimitives()</code></pre>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="Sample_Disp_DemoDrawing_FreeDrawing_" data-uid="Sample.Disp.DemoDrawing.FreeDrawing*"></a>
|
|
|
|
<h3 id="Sample_Disp_DemoDrawing_FreeDrawing" data-uid="Sample.Disp.DemoDrawing.FreeDrawing">
|
|
FreeDrawing()
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Demonstrates simple line drawing using raw vertex coordinates.
|
|
Creates a basic line strip from three vertices and displays it using DemoUtil.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static void FreeDrawing()</code></pre>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</article>
|
|
|
|
<div class="contribution d-print-none">
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="affix">
|
|
<nav id="affix"></nav>
|
|
</div>
|
|
</main>
|
|
|
|
<div class="container-xxl search-results" id="search-results"></div>
|
|
|
|
<footer class="border-top text-secondary">
|
|
<div class="container-xxl">
|
|
<div class="flex-fill">
|
|
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|