Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Camera problems

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
	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;
		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]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!