# Camera Interpolation

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

## 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 on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634136
• Total Posts
3015756
×