if you want some detail, you can only draw triangles which are actually visable, this is fairly simple, because if you devine all the points of the triangles clockwise, they will be visable when the 2d triangle is clockwise, if it is counterclockwise, it is on the back side of the object
SCAR Code:
Function Det3X3(Mat : Array of Array of Integer) : integer;
var
v1, v2, v3, v4, v5, v6 : integer;
begin
v1 := Mat[0][0] * Mat[1][1] * Mat[2][2];
v2 := Mat[0][2] * Mat[2][0] * Mat[2][1];
v3 := Mat[0][1] * Mat[1][2] * Mat[2][0];
v4 := Mat[0][2] * Mat[1][1] * Mat[2][0];
v5 := Mat[0][0] * Mat[1][2] * Mat[2][1];
v6 := Mat[0][1] * Mat[1][0] * Mat[2][2];
Result := v1 + v2 + v3 - (v4 + v5 + v6);
end;
Function GetCircumCenter(Triangle : Array of TPoint) : TPoint;
var
a : Integer;
b : TPoint;
Mat : Array of Array of Integer;
begin
SetLength(Mat, 3);
For a := 0 to 2 do
SetLength(Mat[a], 3);
Mat[0] := [Triangle[0].x,Triangle[0].y,1];
Mat[1] := [Triangle[1].x,Triangle[1].y,1];
Mat[2] := [Triangle[2].x,Triangle[2].y,1];
a := Det3X3(Mat);
Mat[0][0] := Round(sqr(Triangle[0].x) + sqr(Triangle[0].y));
Mat[1][0] := Round(sqr(Triangle[1].x) + sqr(Triangle[1].y));
Mat[2][0] := Round(sqr(Triangle[2].x) + sqr(Triangle[2].y));
Mat[0][1] := Triangle[0].y;
Mat[1][1] := Triangle[1].y;
Mat[2][1] := Triangle[2].y;
b.x := - Det3X3(Mat);
Mat[0][1] := Triangle[0].x;
Mat[1][1] := Triangle[1].x;
Mat[2][1] := Triangle[2].x;
b.y := Det3X3(Mat);
result.x := - Round(b.x / (2*a));
result.y := - Round(b.y / (2*a));
end;
Procedure ClockTriangle(var Triangle : Array of TPoint);
var
Mat : Array of Array of Integer;
a : integer;
P : TPoint;
begin
SetLength(Mat, 3);
For a := 0 to 2 do
SetLength(Mat[a], 3);
p := GetCircumCenter(Triangle);
Mat[0] := [Triangle[0].x - P.x, Triangle[0].y - P.y, (Triangle[0].x - P.x)*(Triangle[0].x - P.x) + (Triangle[0].y - P.y)*(Triangle[0].y - P.y)];
Mat[1] := [Triangle[1].x - P.x, Triangle[1].y - P.y, (Triangle[1].x - P.x)*(Triangle[1].x - P.x) + (Triangle[1].y - P.y)*(Triangle[1].y - P.y)];
Mat[2] := [Triangle[2].x - P.x, Triangle[2].y - P.y, (Triangle[2].x - P.x)*(Triangle[2].x - P.x) + (Triangle[2].y - P.y)*(Triangle[2].y - P.y)];
if (Det3X3(Mat) <= 0) then
begin
P := Triangle[0];
Triangle[0] := Triangle[2];
Triangle[2] := P;
end;
end;
The det3x3 is just the determinant of a 3 x 3 matrix
, if it does the opposite of what it is supposed to be doing, change Det3X3(Mat) > 0 to Det3X3(Mat) =< 0, the rest of it should be alright, but can't be arsed to check it out:P Btw, it crashed on me aswell, i think it is the form part though oh and for my stuff to work you'd need to work with triangles(go figure) but that'd be something you want to do anyways, if you want detail, btw, try to make the rendering in a plugin, it will GREATLY enhance the speed, believe me lol