First Person Rolling problem

Started by
5 comments, last by Norman Barrows 10 years, 8 months ago

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);
	}
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky
Advertisement

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

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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

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

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

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

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky


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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement