I understand the issue yes, this is the problem that i have been mainly trying to solve.
What do you mean by "convert the rotation variable angles into a vector" ? the rotation variable is already a vector ?
I understand the issue yes, this is the problem that i have been mainly trying to solve.
What do you mean by "convert the rotation variable angles into a vector" ? the rotation variable is already a vector ?
Download the Ziron Assembler
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
no it's not=) you just store the angles it in a vector format that's it. what you need to do is convert these angles into a 3d direction vector.
ok, here's how you do it:
then you find the "diff" vector just as you do now.Code:var Dir: TD3DXVector3; sh, ch, sv, cv: Single; ... SinCos(rotation.x, sh, ch); SinCos(rotation.y, sv, cv); Dir.x := ch * cv; Dir.y := sv; Dir.z := sh * cv;
interpolate between the Dir and diff vector (Dir is the old camera direction, diff is the new camera direction).
so you might want to do something like this:
and finally convert the Dir vector to rotation angles. I don't know why you are using a 3d vector for rotationCode:Dir.x := Dir.x + (diff.x - Dir.x) * tween; Dir.y := Dir.y + (diff.y - Dir.y) * tween; Dir.z := Dir.z + (diff.z - Dir.z) * tween; D3DXVec3Normalize(Dir, Dir);
angles, but here it is:
overall this approach should work fine. however, there is still a more consistent and reliable way of spherically interpolating quaternions instead of vectors,Code:rotation := D3DXVector3( arctan2(Dir.z, Dir.x), arcsin(Dir.y), 0 );
but that is a tale for another time.
Last edited by Dan; 17-11-2012 at 03:59 PM.
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.
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.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;
Thanks again
Download the Ziron Assembler
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Bookmarks