Problem with Ogre::Camera lookAt function when target is directly below.
Posted
by
PigBen
on Game Development
See other posts from Game Development
or by PigBen
Published on 2011-02-22T00:31:57Z
Indexed on
2011/02/22
7:33 UTC
Read the original article
Hit count: 320
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.
© Game Development or respective owner