Jump to content
  • Advertisement
Sign in to follow this  
x452Alba

FlyPath + up vectors

This topic is 4175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello forum, I'm coding a FlyPath (at least that's what I call it), you know the type where the camera follows a predetermined track. I am currently loading a series of control points from a plain text file. Each control point consists of an eye position, a look-at position and an up vector. To move the camera/eye I use 4 of the control points as input to form a Catmull-Rom Spline and simply interpolate. However, how should I interpolate the up vectors as the camera/eye follows the spline? I want to use the up vector the "roll" the camera/eye.
struct control_point
{
   vec3 position, look_at, up;
};

...

void FlyPath::Animate()
{
   lerp = lerp + MY_CTIME;

   if (lerp > 1.0f)
   {
      lerp = 0.0f;

      if (++index >= count)
      {
         index = 0;
      }
   }

   vec3 p0 = step[(index - 1 + count) % count].position;
   vec3 p1 = step[(index    ) % count].position;
   vec3 p2 = step[(index + 1) % count].position;
   vec3 p3 = step[(index + 2) % count].position;

   current.position = 0.5f * ((2.0f * p1) + 
                              (-p0 + p2) * lerp +
                              (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * pow(lerp, 2.0f) +
                              (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * pow(lerp, 3.0f));

   p0 = step[(index - 1 + count) % count].look_at;
   p1 = step[(index    ) % count].look_at;
   p2 = step[(index + 1) % count].look_at;
   p3 = step[(index + 2) % count].look_at;

   current.look_at = 0.5f * ((2.0f * p1) + 
                             (-p0 + p2) * lerp +
                             (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * pow(lerp, 2.0f) +
                             (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * pow(lerp, 3.0f));

// current.up = ?????????????????????????????????????????????????????????

   return;
}

void FlyPath::Render()
{
   gluLookAt(current.position[x], current.position[y], current.position[z],
             current.look_at[x], current.look_at[y], current.look_at[z],
             current.up[x], current.up[y], current.up[z]);

   return;
}


As always, thanks in advance [Edited by - x452Alba on May 17, 2007 6:20:16 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!