0

I asked a question about how to add camera damping in Ogre but didnt get any answer so here is a more vague question.

How would you add camera damping?

I googled this question and got answers in XNA and Unity and each is different than the other so I cant even figure out what technique, function or maths they are using.

I have a camera and its position, I have an object and the position where I want the camera to be and slowly move it to that position, how can I do this?

I tried using lerp but it didnt work, I dont know if that is the wrong way of doing it or my lerp function might be wrong so I dont know.

Can someone please help me out. Thanks

user1281566
  • 133
  • 1
  • 3
  • 15

3 Answers3

0

Here is my lerp function

Ogre::Vector3 lerp (Ogre::Vector3 &sourceLocation, Ogre::Vector3 &destLocation, Ogre::Real Time)

        {
            return sourceLocation+ (destLocation - sourceLocation) * Time;
        }

in cpp file

this->camPos = this->lerp(this->camPos, this->playerNode->getSceneNode()->getPosition() + Ogre::Vector3(0,60,-100), 1000.0f);

this->getCamera()->setPosition(this->camPos);

but the camera just ends up miles away from the object

user1281566
  • 133
  • 1
  • 3
  • 15
0

Your calculation for lerp is the issue, your getting the vector between dest and source and massively scaling it up. Your lerp time should not be constant, it should be scaling from 0 to 1 based on the time period you want to go from source to dest.

Before moving:

float length= (dest -start).Length();

Update ()

float distancedTravelled = (CurrentTime - StartTime) * cameraSpeed;

float lerp = distanceTravelled /length;

Pass lerp to function.

Faster camera speed is the quicker you go

0

Thanks for answering Peter. Makes a bit more sense now, the lerp function is just returning a long vector since the time is constant however Im not sure about the second part.

I need to have a variable that increments with the frame?

Ogre::Real frametime += frame_event.timeSinceLastFrame * 0.01;

    this->camPos = this->lerp(this->camPos, this->playerNode->getSceneNode()->getPosition() + Ogre::Vector3(0,60,-100), frametime);

this does slowly move the camera towards the target and then stop but since the frametime is increasing, the time it takes to get to the target destination gets quicker as well. do I just set the frametime to 0 when it reaches destination?

can you please explain a bit more about the second part. I would really really appreciate your help.

Thanks

user1281566
  • 133
  • 1
  • 3
  • 15