🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Implementing Mouse Look

Started by
0 comments, last by Caleb 24 years ago
Hi, Does any one have suggestions for implementing a fast, platform-independent "mouse look" for a 3D engine? ie. the mouse can be used to look around the environment (6 degrees of freedom). I''m currently using C and GLUT to code my engine. I have keyboard implemented but have been thinking about best way to do mouse look. appreciate your help. thanks.
Advertisement
Here''s a fraction of code for how I do it:

void display( void )
{
targetX = eyeX + sin(facing*PI/180.0);
targetY = eyeY + tan(facing2*PI/180.0f);
targetZ = eyeZ + cos(facing*PI/180.0);

gluLookAt( eyeX, eyeY, eyeZ,
targetX, targetY, targetZ,
0.0, 1.0, 0.0);

...
} /* end display */


void mouseFunc( int x, int y )
{
double mouseTurnX = 0.0;
double mouseTurnY = 0.0;


/* make mouse turn variable on how fast mouse is turned */
mouseTurnX = abs((prev_mouse_x - x)*0.5f);
mouseTurnY = abs((prev_mouse_y - y)*0.5f);

if ( mouseTurnX > 40.0 )
mouseTurnX = 40.0; /* don''t let user turn too fast */
if ( mouseTurnY > 40.0 )
mouseTurnY = 40.0; /* don''t let user turn too fast */

if ( x > prev_mouse_x )
{
facing -= mouseTurnX;
if (facing < 0.0) facing += 360.0;
}
if ( x < prev_mouse_x )
{
facing += mouseTurnX;
if (facing > 360.0) facing -= 360.0;
}
if ( y > prev_mouse_y )
{
facing2 -= mouseTurnY;

/* limit user''s range of head movement */
if ( facing2 < 120.0f ) /* 120.0 */
facing2 = 120.0;
}
if ( y < prev_mouse_y )
{
facing2 += mouseTurnY;

/* limit user''s range of head movement */
if ( facing2 > 240.0f )
facing2 = 240.0f;
}

prev_mouse_x = x;
prev_mouse_y = y;
} /* end mouseFunc */

void main()
{
...
glutPassiveMotionFunc(mouseFunc);
glutMotionFunc(mouseFunc);
glutIdleFunc(display);
glutDisplayFunc(display);
...
}

I''ll e-mail you my entire code of a simple 3D environment with mouse movement if you like.

This topic is closed to new replies.

Advertisement