Jump to content
  • Advertisement

Archived

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

Caleb

Implementing Mouse Look

This topic is 6607 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

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

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!