Results 1 to 10 of 18

Thread: Direction between 2 Vectors

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    Quote Originally Posted by Colin View Post
    the rotation variable is already a vector ?
    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:
    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;
    then you find the "diff" vector just as you do now.
    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:
    Code:
      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);
    and finally convert the Dir vector to rotation angles. I don't know why you are using a 3d vector for rotation
    angles, but here it is:
    Code:
      rotation := D3DXVector3(
        arctan2(Dir.z, Dir.x),
        arcsin(Dir.y),
        0
      );
    overall this approach should work fine. however, there is still a more consistent and reliable way of spherically interpolating quaternions instead of vectors,
    but that is a tale for another time.
    Last edited by Dan; 17-11-2012 at 03:59 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •