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?
Camera rotation?
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:
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
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();
}
Regards - Xaron