Prob with cam

Hi all!

Im having a little problem with my camera. I want it to rotate 360º in all direction but it isnt rotating in the y coord… I know that the way Im calculating it is wrong… could any gimme an hand please :slight_smile:

Thanks

 		POINT mousePos;
		int center_x = GetSystemMetrics(SM_CXSCREEN)  >> 1;
		int center_y = GetSystemMetrics(SM_CYSCREEN) >> 1;
		float theta,phi,d;

		GetCursorPos(&mousePos);						
		
		if( (mousePos.x == center_x) && (mousePos.y == center_y) )
		{
			gluLookAt(c_Pos.x,c_Pos.y,c_Pos.z,
		c_Pos.x+c_View.x,c_Pos.y+c_View.y,c_Pos.z+c_View.z,
		c_Up.x ,c_Up.y ,c_Up.z );
			return;
		}

		SetCursorPos(center_x, center_y);							

		theta = (float)(center_x - mousePos.x) / 100.0f * 0.5f;
		c_View.x = c_View.x * (float)cos(theta) + c_View.z * (float)sin(theta);
		c_View.z = c_View.z * (float)cos(theta) - c_View.x * (float)sin(theta);
			
		theta = (float)sqrt(c_View.x * c_View.x + c_View.z * c_View.z);
		d=1/theta;

		c_View.x *= d;
		c_View.z *= d;

		phi = (float)(center_y - mousePos.y)/100.0f * 0.5f;
		c_View.y += phi;

		gluLookAt(c_Pos.x,c_Pos.y,c_Pos.z,
		c_Pos.x+c_View.x,c_Pos.y+c_View.y,c_Pos.z+c_View.z,
		c_Up.x ,c_Up.y ,c_Up.z ); 

You know you can do that with a simple glRotate ? Put it right after setting the modelview matrix (no sure).

I don’t wanna use glRotate. Thanks anyway.

(why don’t you want glRotate ?)

Anyway, you can look at the glRotate doc and work out the math from the matrix definition, or even have a look at the Mesa GL software implementation .