Skip to main content
GameDev.net gamedev.net
🔒 Locked

Camera rotation control

Started by MARS_999 Aug 8, 2006 at 1:46 AM 2 replies 400+ views
Original Post
MARS_999
MARS_999
I am trying to stop my camera from rotating to far up and down and can't get this to work...

if(rotate)
	{
		GetCursorPos(&mousePos);
		unsigned int x = unsigned int(screenwidth * .5f);
		unsigned int y = unsigned int(screenheight * .5f);
		static float lastPitch = 0.0f;
		static float currentPitch = 0.0f;

        SetCursorPos(x, y);
      
		float pitch  = directInput.mouseDY() / ROTATEMOUSE_SPEED;
		float yAngle = directInput.mouseDX() / ROTATEMOUSE_SPEED;

		lastPitch = currentPitch;
		currentPitch += pitch;

		if(currentPitch > pitchRangeMax)
			pitch = pitchRangeMax;
		if(currentPitch < pitchRangeMin)
			pitch = pitchRangeMin;

		D3DXMATRIX R;
		D3DXMatrixRotationAxis(&R, &mRightWS, pitch);
		D3DXVec3TransformCoord(&mLookWS, &mLookWS, &R);
		D3DXVec3TransformCoord(&mUpWS, &mUpWS, &R);

		D3DXMatrixRotationY(&R, yAngle);
		D3DXVec3TransformCoord(&mRightWS, &mRightWS, &R);
		D3DXVec3TransformCoord(&mUpWS, &mUpWS, &R);
		D3DXVec3TransformCoord(&mLookWS, &mLookWS, &R);
	}


Thanks
nini
nini
i've made this mistake once , in fact if you want to use your pitch variable like you do , you must restart from the initial condition , that's to say :
your camera direction should be vDir0 and not your actual vDir...

// this is false :
D3DXVec3TransformCoord(&mLookWS, &mLookWS, &R);

// this is right :
D3DXVec3TransformCoord(&mLookWS, &mLookWS0, &R);
with mLookWS0 being your initial Direction.

if you want to use mLookWS instead , then you have to treat pitch like a volatile variable and store a TotalPitch variable that you increment:

pitch=something;
do your rotation and TotalPitch+=pitch if TotalPitchpitch=0;

hope this helps...
JohnBolton
JohnBolton
I think you want the code to look like this:
    if(currentPitch + pitch > pitchRangeMax)        pitch = pitchRangeMax - currentPitch;    if(currentPitch + pitch < pitchRangeMin)        pitch = pitchRangeMin - currentPitch;    currentPitch += pitch; 

John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
MARS_999
MARS_999
Thanks John that worked.

Topic Locked

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

Sign in to reply to this topic.