Advertisement

Mouse

Started by January 24, 2001 04:35 PM
1 comment, last by The Kid 23 years, 9 months ago
Hey, does anyone know how to rotate around an object, using the mouse ? Or do you know of any info that may help me out ? Thanx. The Kid I don''''t know what the future holds, but I know who holds the future.
I don''t know what the future holds, but I know who holds the future.
There''s people far more qualified than I am to answer this, but I''ll have a go...

I''m assuming you want to rotate the camera around the Y axis, looking at an object at position (ox,oy,oz). Basically you need to read the X position of the mouse and convert this to a rotation angle (a). Then place your camera at the point:

POINT pt;
GetCursorPos(&pt);

float ang = ((float)pt.x / (float)ScreenWidth) * (2*PI);

camerax = ox + (cosf(ang) * dist);
cameray = oy;
cameraz = oz + (sinf(ang) * dist);

// Position the camera...
glLoadIdentity();
gluLookAt(camerax, cameray, cameraz, ox, oy, oz, 0.0f, 1.0f, 0.0f);

// Position the object and draw it...
glPushMatrix();
glTranslatef(ox, oy, oz);
glCallList(object_list);
glPopMatrix();


If you want to rotate around the X axis as well using the mouse''s Y coordinate, the maths would be slightly more involved, and if I thought about it there''s probably an easier way using GL''s transformations to position the camera.

Anyway, hope this helps... :-)

Al.
Advertisement
Thanks a bunch, man. I will be expanding on this code. You gave me ideas. Muchos gracias.

The Kid

I don''''t know what the future holds, but I know who holds the future.
I don''t know what the future holds, but I know who holds the future.

This topic is closed to new replies.

Advertisement