From what I can tell, that code gives you the angle between the two vectors. But this angle could be a rotation around any axis, that axis being the cross-product of the two vectors. That axis would most likely not be co-planar with any of the x, y or z axes, making the angle not much use when it comes to making an object look at something.
I'll try to port the C code I gave before to Pascal.
[pascal]procedure BuildLookAtMatrix(var pOut: D3DXMATRIX;
const pEye: D3DXVECTOR3;
const pAt: D3DXVECTOR3;
const pUp: D3DXVECTOR3)
var
vRight: D3DXVECTOR3; // New x basis
vUp: D3DXVECTOR3; // New y basis
vView: D3DXVECTOR3; // New z basis
begin
// Subtract the camera's position from the viewer's position to
// create a direction or view vector for the camera. We'll call
// this vector, vView.
D3DXVec3Subtract(vView, pAt, pEye);
// Normalize our new z basis vector.
D3DXVec3Normalize(vView, vView);
// Take the cross-product of the new direction vector and the
// x axis of the world space to get a right vector.
// We'll call this vector vRight.
D3DXVec3Cross(vRight, pUp, vView);
D3DXVec3Normalize(vRight, vRight);
// The cross-product of the direction vector (vView) and the
// right vector (vRight) will give us our new up vector, which
// we'll call vUp.
D3DXVec3Cross(vUp, vView, vRight);
// We now build the matrix. The first three columns contain the
// basis vectors used to rotate the view to point at the look-at
// point. The fourth row contains the translation values.
// Rotations are still about the eye point.
//
// m11 m12 m13 m14
// m21 m22 m23 m24
// m31 m32 m33 m34
// m41 m42 m43 m44
pOut._11 = vRight.x;
pOut._21 = vRight.y;
pOut._31 = vRight.z;
pOut._41 = -D3DXVec3Dot(vRight, pEye);
pOut._12 = vUp.x;
pOut._22 = vUp.y;
pOut._32 = vUp.z;
pOut._42 = -D3DXVec3Dot(vUp, pEye);
pOut._13 = vView.x;
pOut._23 = vView.y;
pOut._33 = vView.z;
pOut._43 = -D3DXVec3Dot(vView, pEye);
pOut._14 = 0.0;
pOut._24 = 0.0;
pOut._34 = 0.0;
pOut._44 = 1.0;
end;[/pascal]
Bookmarks