Hello Dan,
Thanks for the code, and for the explanation, it has helped me to understand the idea behind the method. I have updated the procedure with your code and now it works exactly as it should.
Code:
//
// sets the look at target of the camera
//
procedure TCameraController.setTarget(const targ: TD3DXMatrix);
const
tween = 0.01;
var
pos, diff, Dir: TD3DXVector3;
sh, ch, sv, cv: Extended;
begin
SinCos(rotation.x, sh, ch);
SinCos(rotation.y, sv, cv);
Dir := D3DXVector3(ch * cv, sv, sh * cv);
pos := D3DXVector3(targ._41, targ._42+1, targ._43); // + 1 look slightly above the object
D3DXVec3Subtract(diff, pos, position);
D3DXVec3Normalize(diff, diff);
Dir := D3DXVector3(
Dir.x + (diff.x - Dir.x) * tween,
Dir.y + (diff.y - Dir.y) * tween,
Dir.z + (diff.z - Dir.z) * tween
);
D3DXVec3Normalize(Dir, Dir);
rotation := D3DXVector3(
arctan2(Dir.z, Dir.x),
arcsin(Dir.y),
0
);
end;
Once I finish adding an Actor class, then maybe i will come back to working on the camera class to look into the quaternion alternatives.
Thanks again
Bookmarks