• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

GLUT Mouse Question

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

#1shalrath  Members

Posted 23 July 2001 - 01:56 AM

Hi, I use the following code in glutMouseFunc to get the cursor position as a float: case GLUT_LEFT_BUTTON: //code for moving character p.moveto[0] = (float)x; p.moveto[1] = (float)y; break; and then the following code to change the orientation of a player object, (where p is the player), however, when using this the player simply moves eratically, most often on a 45 degree-ish angle in the first Quadrant (where I''m working), the movement code works fine if I give it specific values, but values taken from the mouse cause this error, please examine the code above and below, and if you can help, please do! <**NOTE** This is run every frame...> float len; p.dir[0] = p.moveto[0] - p.pos[0]; p.dir[1] = p.moveto[1] - p.pos[1]; len = sqrtf(p.dir[0] * p.dir[0] + p.dir[1] * p.dir[1]); p.dir[0] /= len; p.dir[1] /= len; p.pos[0] += (p.dir[0] * p.speed); p.pos[1] += (p.dir[1] * p.speed);

#2bobatefrei  Members

Posted 23 July 2001 - 09:53 AM

The mouse pos is in screen coordinate, you must convert it in world coordinate...

Here is a little sample to move the camera with mouse:

static void Mouse(int button, int state, int x, int y)
{
if(state == GLUT_DOWN)
{
Old_Xmouse = x;
Old_Ymouse = y;

mouseButton = button;
}//if(state == GLUT_DOWN)
else if (state == GLUT_UP)
mouseButton = -1;
}//static void Mouse(int button, int state, int x, int y)

static void Motion(int x, int y)
{

if( mouseButton == GLUT_LEFT_BUTTON )
{
camera.Rotate(SIDE_AXIS, ((Old_Ymouse - y) * 2.0f) / 10000.0f);
camera.Rotate(UP_AXIS, ((Old_Xmouse - x) * 2.0f) / 10000.0f);
}

}//static void Motion(int x, int y)

#3shalrath  Members

Posted 23 July 2001 - 08:07 PM

How do I convert a screen co-ord into a world co-ord in glut?

#4shalrath  Members

Posted 23 July 2001 - 08:07 PM

How do I convert a screen co-ord into a world co-ord in glut?

#5bobatefrei  Members

Posted 23 July 2001 - 09:06 PM

It depends of your projection and modelview matrix... A real conversion is complex and slow, just divide the mouse coord by an arbitrary number until you get good results.

#6zedzeek  Members

Posted 24 July 2001 - 09:59 AM

>> How do I convert a screen co-ord into a world co-ord in glut? <<

gluUnProject(..)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.