Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Surface3DPainter.cs
1using System;
2using System.Numerics;
4
6{
11 {
23 public void DrawGraph(Graphs3D.Canvas3D Canvas, Vector4[,] Points, Vector4[,] Normals,
24 object[] Parameters, Vector4[,] PrevPoints, Vector4[,] PrevNormals,
25 object[] PrevParameters, DrawingVolume DrawingVolume)
26 {
27 int i, c = Points.GetLength(0);
28 int j, d = Points.GetLength(1);
29 I3DShader Shader = Graph3D.ToShader(Parameters[0]);
30 bool TwoSided = Expression.ToDouble(Parameters[1]) != 0;
31 Vector4[] Nodes = new Vector4[4];
32 Vector4[] NodeNormals = new Vector4[4];
33
34 c--;
35 d--;
36
37 if (Normals is null)
38 {
39 Vector4[,] N = new Vector4[c + 1, d + 1];
40 Vector4 P1, P2, P3;
41 int n;
42
43 for (i = 0; i < c; i++)
44 {
45 for (j = 0; j < d; j++)
46 {
47 P1 = Points[i, j];
48 P2 = Points[i + 1, j];
49 if (P1 == P2)
50 P2 = Points[i + 1, j + 1];
51 P3 = Points[i, j + 1];
52 if (P1 == P3)
53 P3 = Points[i + 1, j + 1];
54
55 N[i, j] = Graphs3D.Canvas3D.CalcNormal(P1, P2, P3);
56 }
57
58 if (Vector4.Distance(Points[i, d], Points[i, 0]) < 1e-10f)
59 N[i, d] = N[i, 0];
60 else
61 N[i, d] = N[i, d - 1];
62 }
63
64 for (j = 0; j <= d; j++)
65 {
66 if (Vector4.Distance(Points[c, j], Points[0, j]) < 1e-10f)
67 N[c, j] = N[0, j];
68 else
69 N[c, j] = N[c - 1, j];
70 }
71
72 Normals = new Vector4[c + 1, d + 1];
73
74 for (i = 0; i <= c; i++)
75 {
76 for (j = 0; j <= d; j++)
77 {
78 P1 = N[i, j];
79 n = 1;
80
81 if (i > 0)
82 {
83 P1 += N[i - 1, j];
84 n++;
85
86 if (j > 0)
87 {
88 P1 += N[i - 1, j - 1];
89 n++;
90 }
91 }
92
93 if (j > 0)
94 {
95 P1 += N[i, j - 1];
96 n++;
97 }
98
99 Normals[i, j] = P1 / n;
100 }
101 }
102 }
103
104 for (i = 0; i < c; i++)
105 {
106 for (j = 0; j < d; j++)
107 {
108 Nodes[0] = Points[i, j];
109 Nodes[1] = Points[i + 1, j];
110 Nodes[2] = Points[i + 1, j + 1];
111 Nodes[3] = Points[i, j + 1];
112
113 NodeNormals[0] = Normals[i, j];
114 NodeNormals[1] = Normals[i + 1, j];
115 NodeNormals[2] = Normals[i + 1, j + 1];
116 NodeNormals[3] = Normals[i, j + 1];
117
118 Canvas.Polygon(Nodes, NodeNormals, Shader, TwoSided);
119 }
120 }
121 }
122 }
123}
Class managing a script expression.
Definition: Expression.cs:39
static double ToDouble(object Object)
Converts an object to a double value.
Definition: Expression.cs:4824
Contains information about the current drawing area.
void DrawGraph(Graphs3D.Canvas3D Canvas, Vector4[,] Points, Vector4[,] Normals, object[] Parameters, Vector4[,] PrevPoints, Vector4[,] PrevNormals, object[] PrevParameters, DrawingVolume DrawingVolume)
Draws the graph on a canvas.
Handles three-dimensional graphs.
Definition: Graph3D.cs:28
static I3DShader ToShader(object Argument)
Gets a shader object from an argument.
Definition: Graph3D.cs:1414
Interface for 3D shaders.
Definition: I3DShader.cs:11
Interface for 3D graph drawing functions.
Definition: IPainter3D.cs:11