So I've been messing around with 3D - 2D vector transformations and would like to start writing some fun, simple programs to interact with simple quadric surfaces and such. My question is this:
What are some good ways to make my code more efficient? Are there other C# based programs that I can use for graphics?
I'm working in C# (and definitely want to stay that way), and I realize that I have been doing this in a pretty inefficient way so far.
I don't know if I can improve my looping, or the fact that I calculate the transformations every time I move the camera, or what, but any help would be awesome!
Here is some example code (draws the surface pictured in image: https://i.stack.imgur.com/zi1ZQ.png)
void ColorSurface(Point3[] S)
{
List<Panel> f = new List<Panel>();
try
{
for (int x = 0; x < 9; x++)
{
for (int y = 0; y < 9; y++)
{
f.Add(new Panel(S[(10 * x) + y], S[(10 * x) + y + 1], S[(10 * x) + y + 11], S[(10 * x) + y + 10], View));
}
}
}
catch { }
for (int sort = 0; sort < f.Count - 1; sort++)
{
Panel temp;
if (f[sort] > f[sort + 1])
{
temp = f[sort + 1];
f[sort + 1] = f[sort];
f[sort] = temp;
}
}
using (var g = this.CreateGraphics())
{
for (int i = 0; i < f.Count; i++)
{
double dev = f[i].PM.Z;
PointF[] R = new PointF[4];
R[0] = Transform32(f[i].P1);
R[1] = Transform32(f[i].P2);
R[2] = Transform32(f[i].P3);
R[3] = Transform32(f[i].P4);
try
{
SolidBrush G = new SolidBrush(Color.FromArgb(235, (int)(((255 / Math.PI) * (Math.Atan((dev / 10) + 0.2) + (Math.PI / 2)))), 0, 255 - (int)(((255 / Math.PI) * (Math.Atan((dev / 10) + 0.2) + (Math.PI / 2))))));
g.FillPolygon(G, R);
g.DrawPolygon(new Pen(Color.Black, 1), R);
DrawPoint(f[i].PM, new Pen(Color.Black, 3));
}
catch { }
}
}
}