Skip to main content
GameDev.net gamedev.net
🔒 Locked

Mouse input

Started by Ructions Jan 8, 2004 at 9:53 AM 7 replies 700+ views
Original Post
Ructions
Ructions
i was wondering is there any good tutorials on mouse input.
Tree Penguin
Tree Penguin
You could use the standard window messages like WM_MOUSEMOVE, WM_LBUTTONDOWN, etc..
They are easy to use and sufficient for most purposes.
Ructions
Ructions
Do you have any code examples of how to use them
Tree Penguin
Tree Penguin
Well, if you are using the NeHe basecode or some other code using a WndProc function to handle window messages:
LRESULT CALLBACK WndProc(HWND hWnd,UINT	uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg) {
case WM_MOUSEMOVE:
{
int x = MAKEPOINTS(lParam).x;
int y = MAKEPOINTS(lParam).y;
return 0;
}
};
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

WM_MOUSEMOVE if the mouse has moved, WM_LBUTTONDOWN/UP for left button (specifies if the left mousebutton has been pressed or released, use R/M instead of L for the right/middle), the x and y coordinates always work with these messages.
Lookup the windows header for more messages.

[edited by - Tree Penguin on January 8, 2004 11:40:04 AM]
Ructions
Ructions
i am using the mouse to move a object using

glTexCoord2f(0.0f, 1.0f);
glVertex3f(1.0f + paddle.x , 1.0f, 1.0f);

glTexCoord2f(1.0f, 1.0f);
glVertex3f(-1.0f + paddle.x , 1.0f, 1.0f);

glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.0f + paddle.x , -1.0f, 1.0f);

glTexCoord2f(0.0f, 0.0f);
glVertex3f(1.0f + paddle.x , -1.0f, 1.0f);

using the x position as i only want it to move on the x axis but it only let me move it half way across the screen.

Any suggestions
Tree Penguin
Tree Penguin
Store the old x value so you can get the delta x:
int x = MAKEPOINTS(lParam).x;
paddle.x += (float)( x - oldx ) * amount;
oldx=x;

Where amount is a float to specify the amount of movement per pixel that the mouse moved.
Luke Miklos
Luke Miklos
Ructions,

It only lets move on the right half of the screen doesn''t it? You know why? Cus your vertexes are always based on a reference point. When drawing vertices, the default reference point is in the center of the screen (assuming you clear the screen every frame & reset the modelview matrix). So you have to translate over to the left edge of the screen (this translation depends where at on the Z axis you are, assuming no rotations have been done yet) & then you can use your code. Good luck.

Luke
Whatsoever you do, do it heartily as to the Lord, and not unto men.
Luke Miklos
Luke Miklos
hey man, try this....


//NEW CODE:

GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
//viewport[0] = x position of window in screen (0 if full screen?)

//viewport[0] = y position of window in screen (0 if full screen?)

//viewport[2] = width of window

//viewport[3] = height of window


//subtract half of the screen width from the paddle's X coordinate

//this is assuming that the paddle's X coordinate is directly related the mouse position (referenced from left side of screen)

float RealPaddleX = paddle.x - viewport[2]/2.0f;

//now your code (modified)...

glTexCoord2f(0.0f, 1.0f);
glVertex3f(1.0f + RealPaddleX , 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-1.0f + RealPaddleX , 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.0f + RealPaddleX , -1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(1.0f + RealPaddleX , -1.0f, 1.0f);


The only thing I'm not sure about is exaclty what X & Y from the viewport mean & what X & Y of the mouse mean... you might need to do a small conversion before actually drawing your vertices.
I also am not sure what this:

WndProc(HWND hWnd,UINT uMsg/*==WM_MOUSEMOVE*/,WPARAM wParam,LPARAM lParam)
{
int x = MAKEPOINTS(lParam).x;
int y = MAKEPOINTS(lParam).y;
.....
}

would end up setting X & Y equal to. So check on that.
Check out glviewport too. You need to know if the X&Y values you recieve are windows coordinates, normalized device coordinates, or coordinates that apply to the modelview matrix.

good luck


[edited by - Luke Miklos on January 9, 2004 3:00:32 PM]
Whatsoever you do, do it heartily as to the Lord, and not unto men.
guigui
guigui
nevermind

[edited by - guigui on January 9, 2004 10:02:53 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.