I've found code in this topic http://irrlicht.sourceforge.net/forum// ... ra&start=0
but I'm encountering a problem: roll occurs while I use pitch and yaw only...
The code of the topic has been adapted because the camera stays at (0, 0, 0).
Code: Select all
void rotate(vector3df rot)
{
matrix4 m;
m.setRotationDegrees(node->getRotation());
matrix4 n;
n.setRotationDegrees(rot);
m *= n;
node->setRotation(m.getRotationDegrees());
node->updateAbsolutePosition();
}
//--- turn ship left or right ---
void turn(f32 rot)
{
rotate(vector3df(0.0f, rot, 0.0f));
}
//--- pitch ship up or down ---
void pitch(f32 rot)
{
rotate(vector3df(rot, 0.0f, 0.0f) );
}
Code: Select all
void makeCockpit()
{
// get transformation matrix of node
matrix4 m;
m.setRotationDegrees(node->getRotation());
// transform forward vector of camera
vector3df frv = vector3df(0.0f, 0.0f, 1.0f);
m.transformVect(frv);
// transform upvector of camera
vector3df upv = vector3df(0.0f, 1.0f, 0.0f);
m.transformVect(upv);
// set camera
camera->setUpVector(upv);
camera->setTarget(frv);
// update absolute position
camera->updateAbsolutePosition();
}
Code: Select all
void update(f32 dtime)
{
// Get rotation angles from relative mouse position
position2d<f32> cursorPos = device->getCursorControl()->getRelativePosition();
// Put back cursor at center of the screen
device->getCursorControl()->setPosition(.5f, .5f);
f32 dx = cursorPos.X - .5f;
if (dx != 0.f)
turn(dx * RADTODEG);
f32 dy = cursorPos.Y - .5f;
if (dy != 0.f)
pitch(-dy * RADTODEG);
makeCockpit();
(...)
}