Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
5 replies to this topic

#1 shalrath   Members   -  Reputation: 128

Like
Likes
Like

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

Sponsor:

#2 bobatefrei   Members   -  Reputation: 122

Like
Likes
Like

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)


#3 shalrath   Members   -  Reputation: 128

Like
Likes
Like

Posted 23 July 2001 - 08:07 PM

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

#4 shalrath   Members   -  Reputation: 128

Like
Likes
Like

Posted 23 July 2001 - 08:07 PM

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

#5 bobatefrei   Members   -  Reputation: 122

Like
Likes
Like

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.

#6 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

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.



PARTNERS