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

Camera Spinning

Started by VanillaSnake21 Jan 5, 2007 at 11:47 AM 3 replies 700+ views
Original Post
VanillaSnake21
VanillaSnake21
Im using my mouse to rotate my 3D camera's on the Pitch and Yaw axii, but for some reason when im turning in both (if I drag the mouse diagonaly) the camera seems to be doing a roll on the LookAt axis. The only thing the the mouse is affecting is the Pitch and Yaw angles. This is my source for the camera update function. Thnx for any help.

void Camera::BuildViewMatrix(D3DXMATRIX * matrix, LPDIRECT3DDEVICE9 device)
{	
	if(is_changed)
	{


	D3DXMATRIX mx_TotalRotation;
	D3DXMATRIX mx_AroundRight;
	D3DXMATRIX mx_AroundUp;
	D3DXMATRIX mx_AroundLook;

	// now we use the angles that we have rotated by and
	// put them into matrices

	// rotate around look at
	D3DXMatrixRotationAxis(&mx_AroundLook, &v_LookAt, rad_angle_aroundLook);
	// rotate around right
	D3DXMatrixRotationAxis(&mx_AroundUp, &v_Up, rad_angle_aroundUp);
	// round right
	D3DXMatrixRotationAxis(&mx_AroundRight, &v_Right,rad_angle_aroundRight);

	

	// combine matrices into 1
	D3DXMatrixMultiply(&mx_TotalRotation, &mx_AroundUp, &mx_AroundRight);
	D3DXMatrixMultiply(&mx_TotalRotation, &mx_TotalRotation,&mx_AroundLook);

	D3DXVec3TransformCoord(&v_Right, &v_Right, &mx_TotalRotation );
	D3DXVec3TransformCoord(&v_Up, &v_Up, &mx_TotalRotation );

	D3DXVec3Cross(&v_LookAt, &v_Up, &v_Right);


	D3DXVec3Normalize(&v_Up, &v_Up);
	D3DXVec3Normalize(&v_Right, &v_Right);
	D3DXVec3Normalize(&v_LookAt, &v_LookAt);

	DrawAxii(device);

	// compute the position of the matrix ( bottom row)

	D3DXMatrixIdentity(matrix);

	float viewX, viewY, viewZ;
	viewX = -D3DXVec3Dot(&v_Right, &v_Eye);
	viewY = -D3DXVec3Dot(&v_Up, &v_Eye);
	viewZ = -D3DXVec3Dot(&v_LookAt, &v_Eye);

	(*matrix) = D3DXMATRIX( v_Right.x, v_Up.x, v_LookAt.x, 0,
							v_Right.y, v_Up.y, v_LookAt.y, 0,
							v_Right.z, v_Up.z, v_LookAt.z, 0,
							viewX    , viewY , viewZ   ,   1
						  );

	
					   
	rad_angle_aroundUp    = 0.0f;
	rad_angle_aroundLook  = 0.0f;
	rad_angle_aroundRight = 0.0f;

	is_changed = false;


	} //end if
	

}



You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts
win_crook
win_crook
Take a look at the third camera tutorial on this site for help:
Link
ShaderDev
ShaderDev
You are probably trying to yaw relative to the local axis. Try to yaw relative to the global axis. I would allso advise you to consider using quaternion rotations...
VanillaSnake21
VanillaSnake21
Quote:
Original post by ShaderDev
You are probably trying to yaw relative to the local axis. Try to yaw relative to the global axis. I would allso advise you to consider using quaternion rotations...


Yeah i figured that would help (using global axes) but it turned out with the same spinn. Will using quaternions solve the problem? Im trying to find some good examples of such 1st person cams.
You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts
ShaderDev
ShaderDev
Well...you need to yaw relative to the global axis and pitch relative to the local axis. If you do them both relative to the global axis you will get pretty much the same bad results. Quaternions won't solve the problem but they are faster (involving less math) and in my opinion easier to understand.

Topic Locked

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

Sign in to reply to this topic.