• 12
• 12
• 9
• 10
• 13

# First Person Rolling problem

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

## Recommended Posts

Hey GameDev :)

My first person camera is rolling when I move the mouse in circles. I don't know what's wrong with it, please help me.

	void Pitch(float angle)
{
D3DXMATRIX T;
D3DXMatrixRotationAxis(&T, &right, angle);

D3DXVec3TransformCoord(&up, &up, &T);
D3DXVec3TransformCoord(&lookDirection, &lookDirection, &T);
}

void Yaw(float angle)
{
D3DXMATRIX T;
D3DXMatrixRotationAxis(&T, &up, angle);

D3DXVec3TransformCoord(&lookDirection, &lookDirection, &T);
D3DXVec3TransformCoord(&right, &right, &T);
}


##### Share on other sites

if this is like a first person shooter where you just want to pitch and yaw, then the yaw axis you want is your world up axis ( 0,1,0  if using a Y up sys).

D3DXMatrixRotationAxis(&T, &worldUp, angle); //use the world up instead of camera up here in the yaw method

##### Share on other sites

My first person camera is rolling when I move the mouse in circles.

if this is like a first person shooter where you just want to pitch and yaw, then the yaw axis you want is your world up axis

your code sample rotates around LOCAL axes (like a fighter plane sim). for 1st person shooter, you want to rotate around WORLD axes. local axis rotation is only really required with true 3 degree of rotational freedom flight simulations.

as for "roll"....

if by that you mean the ship starts to roll as you yaw and pitch, this is most likely due to floating point imprecision, and not re-ortho-normalizing your forward, up, and right unit vectors.

as you apply successive incremental rotations to your local axes, they skew due to floating point imprecision. gramm-shmidt  LARGELY fixes that:  up=fwd X right, right=fwd X up. need to keep them all unit vectors as well, as i recall. its also possible to use other methods of storing orientation that don't have the precision problem of floating point mats and quats.

as stated above, if you want first person shooter type rotations, you want PAN and TILT (rotations around global y and x respectively, left hand coordinate system), not YAW and PITCH (rotations around local y [up] and x

axes respectively, LH coord sys).

try D3DXMatrixRotationX(&T,&T,pitch_angle) and D3DXMatrixRotationY(&T,&T,yaw_angle).  note that call order is important. you can call in either order, RotX then RotY, or vice verse, but you must use that same order everywhere in your code for consistent results. Xrot followed by Yrot gives you pan and tilt behavior like a camera, which is what FPS shooters do.

##### Share on other sites

I was able to fix the issue by using D3DXMatrixRotationY instead of D3DXMatrixRotationAxis in the Yaw function. Thanks, guys.

##### Share on other sites

now for the REAL question:

do you understand WHY you can combine a local X and global Y rotation and get the same desired result as combining a global X and global Y rotation?

BTW, you might want to rename Yaw() to Pan() as that's what it actually does now. even if its just you and you know what it does, code clarity is always a good practice.

##### Share on other sites

I'm not sure I understand the question to begin with

##### Share on other sites

I'm not sure I understand the question to begin with

why (in this case) does local x followed by global y rotation = global x followed by global y rotation ?

answer: because when you start, your right vector (local x) is pointing down (coincident with) the global x axis. so at that point, they're the same axis of rotation.

here's another one:

why (in this case) didn't local X followed by local Y work?

answer: because the rotation around local x rotates the local y axis so its no longer coincident with (pointing down the) global y axis. so instead of spinning around with respect to the x-z plane, it spins with respect to an x-z plane tilted by your local x rotation.