Then, I found a function
Code: Select all
camera->setRotation()
Further poking around in the forum showed that I can manipulate the "UpVector" to tilt the camera. Now, I got the following code with the commented out function below
Code: Select all
// TiltRotation.fromAngleAxis(core::DEGTORAD * (rz / 500), Forwards); // this code will bank the camera all the way around.
The net effect is that I can do one of the three things but not all three at the same time.
It seems that this question has been asked a few times in the past except I do not see a clear answer to it. Could I get a bit of assistance here?
Hiroo
Code: Select all
int lastFPS = -1;
core::vector3df cam_up(0, 1, 0);
core::vector3df cam_lookat(camera->getTarget());
//We will use this to create make the up vector tilt
irr::core::matrix4 TiltMatrix;
//Get the Forwards vector, we will use this for our quat
irr::core::vector3df Forwards = (camera->getTarget() - camera->getPosition()).normalize();
//Create a quat, facing in the same direction as our camera
//with a 45 degree rotation
rx = 0; ry = 0; rz = 0;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0 );
cam_up = core::vector3df(0, 1, 0);
irr::core::quaternion TiltRotation;
// TiltRotation.fromAngleAxis(core::DEGTORAD * (rz / 500), Forwards); // this code will bank the camera all the way around.
TiltRotation.fromAngleAxis(core::DEGTORAD * (rz / 500), cam_up.normalize()); // this code does nothing.
//Now we need to get that rotation in Euler so we can use it
irr::core::vector3df EulerRot;
TiltRotation.toEuler(EulerRot);
//Its stored in radians, convert to a degrees
EulerRot = EulerRot * 57.2957795f;
//Set our tilt matrix to that rotation
TiltMatrix.setRotationDegrees(EulerRot);
//The Upvector tilted
TiltMatrix.transformVect(cam_up);
//Set the upvector for the camera
camera->setUpVector(cam_up);
smgr->drawAll();
env->drawAll();
driver->endScene();
// display frames per second in window title
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
// Also print terrain height of current camera position
// We can use camera position because terrain is located at coordinate origin
str += " Height: ";
str += terrain->getHeight(camera->getAbsolutePosition().X,
camera->getAbsolutePosition().Z);
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
++rz;
if (rz > 180000) rz = -180000;
}