PDA

View Full Version : Prob with cam



08-17-2004, 07:30 AM
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 :)

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

ZbuffeR
08-17-2004, 10:03 AM
You know you can do that with a simple glRotate ? Put it right after setting the modelview matrix (no sure).

08-17-2004, 10:32 AM
I don't wanna use glRotate. Thanks anyway.

ZbuffeR
08-17-2004, 10:41 AM
(why don't you want glRotate ?)

Anyway, you can look at the glRotate doc (http://pyopengl.sourceforge.net/documentation/manual/glRotate.3G.html) and work out the math from the matrix definition, or even have a look at the Mesa GL software implementation (http://www.mesa3d.org/) .