Original Post
Hello, i recently posted about getting a camera algorithm i came up with to work (post), well i finally got it to work (some what), i can look around completly, just like a first person camera, and i didnt have to do any crazy math to get it, i tryed adding a simple function to move the player (or camera), forward and backwords on the Z axis. In my test program i just have a flat square as the ground, with a brick wall sticking up. when i simply (try to) move the camera backwards or forwards, the terrain slides out rather quickly, and the brick wall moves back and forth really slow. This just seemed strange because i used glLoadIdentity(); before calling gluLookAt(), i wouldnt see how it would have any effect on the positioning of objects in the world, i feel like im making a stupid mistake here and im just not seeing it.
You can download the ZIP file (here [1.02 MB]), or take a look at my camera class, and maybe see my stupid mistake?
class cCamera
{
public:
void UpdateCamera();
cCamera();
~cCamera() {};
private:
void m_pUpdateCamera();
};
float PI = 3.14f;
float Radius = 20.0f;
float CameraPosX = 90.0f;
float CameraPosY = 0.0f;
float PlayerX = 0.0;
float PlayerZ = 0.0;
void cCamera::UpdateCamera()
{
int x, y; // mouse pos
int middleX, middleY; // middle of the window
float angleX, angleY;
// get the screen/2
middleX = screen->w >> 1;
middleY = screen->h >> 1;
// get the current mouse position
SDL_GetMouseState(&x, &y);
// if the position is the center, then just stop
if(x==middleX && y==middleY)
{
m_pUpdateCamera();
return;
}
angleX = (float)(middleX - x) / 100.0f;
angleY = (float)(middleY - y) / 100.0f;
CameraPosX -= angleX;
CameraPosY -= angleY;
SDL_WarpMouse(middleX, middleY);
if(CameraPosX > 360.0)
CameraPosX = 0.0;
if(CameraPosX < 0.0)
CameraPosX = 360.0;
if(CameraPosY > 3.0)
CameraPosY = 3.0f;
if(CameraPosY < -3.0)
CameraPosY = -3.0;
m_pUpdateCamera();
}
void cCamera::m_pUpdateCamera()
{
glLoadIdentity();
gluLookAt( PlayerX, 0.0, PlayerZ,
PlayerX + Radius*sin(CameraPosX/PI), Radius*sin(CameraPosY/PI), PlayerZ + Radius*cos(CameraPosX/PI),
0.0, -1.0, 0.0);
}
The error is when I +/- the PlayerZ, it has some strange effect on the world...
---------------------------------------------
"If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside."