I am trying to make a class which controls a camera. It's pretty basic right now, it looks like this:
class HoveringCameraController
{
public:
void init(Ogre::Camera & camera, AnimatedBody & target, Ogre::Real height);
void update(Ogre::Real time_delta);
private:
Ogre::Camera * camera_;
AnimatedBody * target_;
Ogre::Real height_;
};
HoveringCameraController.cpp
void HoveringCameraController::init(Ogre::Camera & camera, AnimatedBody & target, Ogre::Real height)
{
camera_ = &camera;
target_ = ⌖
height_ = height;
update(0.0);
}
void HoveringCameraController::update(Ogre::Real time_delta)
{
auto position = target_->getPosition();
position.y += height_;
camera_->setPosition(position);
camera_->lookAt(target_->getPosition());
}
AnimatedBody is just a class that encapsulates an entity, it's animations and a scene node. The getPosition function is simply forwarded to it's scene node.
What I want(for now) is for the camera to simply follow the AnimatedBody overhead at the distance given(the height parameter), and look down at it. It follows the object around, but it doesn't look straight down, it's tilted quite a bit in the positive Z direction. Does anybody have any idea why it would do that?
If I change this line:
position.y += height_;
to this:
position.x += height_;
or this:
position.z += height_;
it does exactly what I would expect. It follows the object from the side or front, and looks directly at it.