I used http://www.gamedev.net/community/for...opic_id=468539 to create LookAt function but i'm still not getting results that i need:
[pascal]function LookAt(const eye, target, up: TVector): TMatrix;
var x,y,z,p: TVector;
begin
z:=invert(norm(VectorSub(target,eye)));
x:=norm(crossproduct(norm(up),z));
y:=crossproduct(z,x);
p:=vector(-dot(eye,x),-dot(eye,y),-dot(eye,z));
result:=CreateMatrix(x,y,z,p);
end;[/pascal]
It is short and "simple" but yet it's not working right. I have tried to visualize the matrix vectors in 2D plane but it's hella confusing... And i've tested and tested the math behind tool functions but they should all work correctly. They are used in numerous other 3D functions which behave right, including MatrixToSurface() that is another kind of LookAt formed of pos and normal on a plane, RayTriangleIntersect(), RaySphereIntersect().

This is how it's i've debugged the matrix: http://i49.tinypic.com/fbc9oj.png
Red dot is Eye vector and white is its Invert. Yellow dot is Target vector. Green represent LookAt matrix returned and line drawn is Z-rotation vector of it.

Basically.. i was able with the same functions to point the ship with my mouse and draw another smaller ship on surface of it where cursor ray first crossed, perfectly aligned with the triangle on the point, yet LookAt doesn't work.

Edit2: Getting a little closer, but its upside down and is not directly following target or eye pos http://i45.tinypic.com/2nly2id.png
I drew the matrix-Z vector from eye pos aswell. It's green line that should hit yellow sphere for it to be correct.