#### Archived

This topic is now archived and is closed to further replies.

# strange camera behavior...

This topic is 5248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 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()
{
gluLookAt(	PlayerX,		0.0,		PlayerZ,
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."

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009811
• ### Who's Online (See full list)

There are no registered users currently online

×