Skip to main content
gamedev.net
🔒 Locked

fps camera

Started by shakazed Jan 19, 2004 at 2:31 PM 3 replies 1k views
Original Post
shakazed
shakazed
Hi! This is my function for moving in a 3d scene.

HRESULT GetKeyPress(void)
{
	if(GetAsyncKeyState(VK_RIGHT))
	{
		sPlayer.Angle = sPlayer.Angle - 0.05f;
		sPlayer.lx = sPlayer.x + cosf(sPlayer.Angle);
		sPlayer.lz = sPlayer.z + sinf(sPlayer.Angle);
	}

	if(GetAsyncKeyState(VK_LEFT))
	{
		sPlayer.Angle = sPlayer.Angle + 0.05f;
		sPlayer.lx = sPlayer.x - cosf(sPlayer.Angle);
		sPlayer.lz = sPlayer.z - sinf(sPlayer.Angle);	
	}

	if(GetAsyncKeyState(VK_UP))
	{
		sPlayer.x = sPlayer.x + cosf(sPlayer.Angle)*(sPlayer.MoveRate);
		sPlayer.z = sPlayer.z + sinf(sPlayer.Angle)*(sPlayer.MoveRate);
	}
		
	if(GetAsyncKeyState(VK_DOWN))
	{
		sPlayer.x = sPlayer.x - cosf(sPlayer.Angle)*(sPlayer.MoveRate);
		sPlayer.z = sPlayer.z - sinf(sPlayer.Angle)*(sPlayer.MoveRate);
	}

	return S_OK;
}
I can turn around allright though when trying to move in any direction it gets all screwed up. Do you see what the heck I´ve done wrong? Any help apprectiated.
grhodes_at_work
grhodes_at_work
What exactly do you do with the sPlayer.x/y and sPlayer.lx/ly variables? And how large is your move rate, e.g., is it large compared to the size of your game world?

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
shakazed
shakazed
The lx,ly, lz variables are lookat point. x,y,z is the position of the camera. Moverate is 0.5f, which would be fairly small. I´ve loaded a .x model of a landscape which I´m (later on) will implement terrain following on. First I just want the camera to move correct.
The sPlayer struct looks like:


struct Player
{
float Angle,x,y,z,lx,ly,lz,MoveRate;
}


And is defined like this:


Player sPlayer = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};



tri-thanatos
tri-thanatos
have you updated your view matrix after all of this?
shakazed
shakazed
Yes I can rotate my camera around it´s axis. It´s just when I move forward/backwards it gets all wrong.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.