Camera rotation?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
mystic jimbo
Posts: 8
Joined: Fri Oct 13, 2006 3:12 pm

Camera rotation?

Post by mystic jimbo »

Greetings,

Am I doing something wrong or is it so that you can't rotate a camera with setRotation? Or should I do something extra after I call setRotation?
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

You are right. You can't rotate the camera using setRotation. A camera has a target (the direction it looks to) and an up vector. You need to set these two vectors to rotate a camera.

Here some code:

Code: Select all

void Camera::update( core::vector3df& offset, const core::vector3df& position, const core::vector3df& rotation )
{
  assert( _camera );
  if( !_camera )
    return;

  core::matrix4 rotMatrix;
  rotMatrix.setRotationDegrees( rotation );

  // Set up vector for the camera
  core::vector3df camUpVector = core::vector3df( 0.0f, 1.0f, 0.0f );
  rotMatrix.transformVect( camUpVector );

  // Set target vector for the camera
  core::vector3df targetVector = core::vector3df( 0.0f, 0.0f, 1.0f );
  rotMatrix.transformVect( targetVector );
  core::vector3df camTarget = position + targetVector;

  rotMatrix.transformVect( offset );

  _camera->setPosition( position + offset );
  _camera->setUpVector( camUpVector );
  _camera->setTarget( camTarget + offset );
  _camera->updateAbsolutePosition();
}
Please note, that this call updateAbsolutePosition() after all is very important to avoid some jitter. The problem is, that Irrlicht updates its positions _after_ rendering...

Regards - Xaron
mystic jimbo
Posts: 8
Joined: Fri Oct 13, 2006 3:12 pm

Post by mystic jimbo »

OK, thanks for the code Xaron!
Post Reply