I just must add one more! Last one for a while... promise!
This is the camera function I am currently using... It's not 100% optimized, but better than the horrible inefficient mess of 6 or so IrrRevolveCamera calls I had before:
Code: Select all
declare sub IrrSetCamera alias "IrrSetCamera" ( _
byval camera as irr_camera, _
byval rotx as single, _
byval roty as single, _
byval rotz as single, _
byval x as single, _
byval y as single, _
byval z as single )
Code: Select all
/* ----------------------------------------------------------------------------
Sets the camera to the desired rotx/roty/rotz/x/y/z values.
*/
void DLL_EXPORT IrrSetCamera (irr::scene::ICameraSceneNode* camera,
float rotx, float roty, float rotz,
float x, float y , float z) {
quaternion tempQuaternion;
// Work out the 3 axes for the camera:
// Forward = target (0,0,0) - position -- the position at (x=0, y=0) is (0,0,1).
// Right = -1 * cross-product of up.
// Pos = -forward + x * right + y * up;.
vector3df up(0,1,0);
vector3df forward(0,0,-1);
vector3df pos(x,y,1);
tempQuaternion.fromAngleAxis(rotz, forward);
tempQuaternion.getMatrix().rotateVect(up);
tempQuaternion.fromAngleAxis(rotx, up);
tempQuaternion.getMatrix().rotateVect(forward);
vector3df right = forward.crossProduct (up);
tempQuaternion.fromAngleAxis(roty, right);
tempQuaternion.getMatrix().rotateVect(forward);
tempQuaternion.getMatrix().rotateVect(up);
pos = pos + z * forward;
camera->setUpVector (up);
camera->setTarget (pos + forward);
camera->setPosition (pos);
}