Sad thread, a good idea but little happened. Maybe it was too vague? It would have to be about specific tasks, small code snippets. I mean, things like checking if a line passes through a triangle, to mention one. In many cases, I think we can just look up our respective libraries of reusable code, and that could be interesting enough.

Let me suggest one problem: Inverting a matrix. I have this, which inverts a 3x3 matrix, but only that:


function Invert(m: Matrix3D): Matrix3D;
var
a,b,c,d,e,f,g,h,i,det: GLfloat;
index: Longint;
begin
a := m[0];b := m[3];c := m[6];
d := m[1];e := m[4];f := m[7];
g := m[2];h := m[5];i := m[8];

det := a*(e*i-f*h) - b*(d*i-f*g) + c*(d*h-e*g);

m[0] := (e*i-f*h); m[3] :=-(b*i-c*h); m[6] := (b*f-c*e);
m[1] := (f*g-d*i); m[4] := (a*i-c*g); m[7] := (c*d-a*f);
m[2] := (d*h-e*g); m[5] := (b*g-a*h); m[8] := (a*e-b*d);

for index := 0 to 8 do
m[index] := m[index] / det;

Invert := m;
end;

The obvious improvement would be a general algorithm, or at least 4x4. Can that be made simple?