I've been playing around, and I'm trying to make a first person camera view. I set up a camera to track the position of a node (the player). I want a camera similar to games like half-life, where you can rotate with the mouse, and move with the keys, but the camera only moves on a 2d axis despite it's orientation.
This is the code i have so far to limit the view vertically (so you can't spin backwards upside-down. The constant is a fraction of a full revolution.
Code: Select all
void MyListener::moveCamera()
{
// Make all the changes to the camera
// Note that YAW direction is around a fixed axis (freelook style) rather than a natural YAW (e.g. airplane)
mCamera->yaw(mRotX);
mCamera->pitch(mRotY);
//Limit pitch vertically
Real mViewLimit = Vars.getRealVariable("ViewYLimit");
if (mCamera->getOrientation().getPitch().valueRadians() > (Math::PI - mViewLimit))
{
mCamera->pitch( -mRotY );
mRotY = 0;
}
if (mCamera->getOrientation().getPitch().valueRadians() < -(Math::PI - mViewLimit))
{
mCamera->pitch( -mRotY );
mRotY = 0;
}
mCamera->moveRelative(mTranslateVector);
}
My other major problem will be physics.. detecting collision between the player and the world. Would I just use a few rays around the player in different directions and integrate 1 step ahead, then if a collision is found, move out of the wall to the polygon's plane?