Jump to content
  • Advertisement
Sign in to follow this  
livingaftermidnight

Camera Interpolation

This topic is 4867 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

I'm working on a intro for my game. It involves me scripting a camera (in OpenGL) somehow that'll follow something and then once that object hits it's destination then the camera will zoom far out revealing this even bigger object. Would anybody have any idea how to run this? I have camerapos and camerarotation vectors. I just need some interpolation functions or something to get me started. Any pitfalls people have come under while doing this? Any information will help! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
If you want the camera position to interpolate from one point to another in a straight line.

Will do an exaple here of moving from 0,0,0 to 10,10,10 - You will need a little bit of vector mathematics here


Vector3 destinationPos(10.0f, 10.0f, 10.0f);
Vector3 sourcePos(0.0f, 0.0f, 0.0f);
float speed = 0.1f;

while (moving)
{
// speedup/slow down on user input
if (key == speedup)
speed += 0.1f;
else if (key == slowdown)
speed -= 0.1f

Vector3 vecDifference = destinationPos - sourcePos;
// check if we reached the destination
if (vecDifference.Length() < EPSILON)
moving = false;

// update position
sourcePos += vecDifference * speed; // multiply by a scalar not a vector
}



If you dont want it to follow a straight line, you will need to step along a spline of some kind, just increasing t as you go. You can do exactly the same thing with the cameras look at position.

Share this post


Link to post
Share on other sites
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!