Camera problems

Started by
-1 comments, last by griffenjam 20 years, 6 months ago
I am having camera problems. When I try to turn left and right my camera just kind of doubles back on itself. I guess one of the biggest problems is that I didn't write most of the camera code invloved. Here is a download link for an executable and the source for the relevant code

void CCamera::SetViewByMouse()
{
	POINT mousePos;
	int middleX = 320  >> 1;   //TODO replace with function to get current resolution
	int middleY = 240 >> 1;
	float angleX = 0.0f;
	float angleY = 0.0f;
	static float currentRotX = 0.0f;
	
	GetCursorPos(&mousePos);						
	
	if( (mousePos.x == middleX) && (mousePos.y == middleY) ) return;

	SetCursorPos(middleX, middleY);							

	angleX = (float)( (middleX - mousePos.x) ) / 50.0f;		
	angleY = (float)( (middleY - mousePos.y) ) / 50.0f;		

	//currentRotX -= angleX;  
   currentRotX += angleY;

	if(currentRotX > 1.0f)
		currentRotX = 1.0f;
	else if(currentRotX < -1.0f)
		currentRotX = -1.0f;
   else
	{
		CVector3 vAxis = CrossProduct(vView - vPosition, vUpVector);
		vAxis = Normalize(vAxis);

		// Rotate around our perpendicular axis and along the y-axis
		RotateView(angleY, vAxis.x, vAxis.y, vAxis.z);
		RotateView(angleX, 0, 1, 0);
	}
}


void CCamera::RotateView(float fAngle, float rx, float ry, float rz)
{
  quaternion temp, quat_view, result;

  temp.x = rx * sin(fAngle/2);
  temp.y = ry * sin(fAngle/2);
  temp.z = rz * sin(fAngle/2);
  temp.w = cos(fAngle/2);

  quat_view.x = vView.x;
  quat_view.y = vView.y;
  quat_view.z = vView.z;
  quat_view.w = 0;

  result = mult(mult(temp, quat_view), conjugate(temp));

  vView.x = result.x;
  vView.y = result.y;
  vView.z = result.z;
}

  
Edit: if you run the executable press l to turn off lighting, it's not working right now. [edited by - griffenjam on October 8, 2003 3:05:32 PM]
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery

This topic is closed to new replies.

Advertisement