This is the code for IsTriangleVisible:
Basically first eliminate them if they are too far, then check if inside FOV. I have no idea how to check for obstruction, if I could there would be no need for the rest of the code after this.
private static bool IsTriangleVisible(Triangle<Vertex> check, SharpCamera camera = null)
if (camera != null)
Camera = camera;
Vector3 face = Vector3.Transform(AbsoluteVectors.Look, Camera.GetRotation);
double FOVCOS = Math.Cos((double)FieldOfView);
Distance = Vector3.Distance(check.MiddlePoint, Camera.GetPosition);
if (Distance > MaxDistance || Distance < MinDistance)
if (Vector3.Dot(face, Vector3.Normalize(check.MiddlePoint - Camera.GetPosition)) >= FOVCOS)
For the sort, I chek distance between two Triangle middle points:
Middle point is simply a Vector3 with
private static int Closer(Triangle<Vertex> one, Triangle<Vertex> two)
float plusone = Vector3.Distance(two.MiddlePoint, Camera.GetPosition);
float minusone = Vector3.Distance(one.MiddlePoint, Camera.GetPosition);
if (plusone > minusone)
if (minusone > plusone)
SharpCamera is a class I made that lets you rotate around relative axis and get precise view matrices without gimbal locks or quaternion related problems.
I'm quite new in graphics programming, so maybe I don't know some of the language features I should know >.<. If that's the case please do give me a hint and what kind of class I should use.