Jump to content
  • Advertisement
Sign in to follow this  
Enerjak

Little advice on the mouse X and Y and an object's screen space.

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

Ok, well, I think I pretty much know this answer just don't know how to get it to work. Basically I have this:

 

http://puu.sh/2REft.jpg

 

the position of the square is at (x = 100, y = 100). So i tried to check the mouse position this way:

 

void mouseButtons(int button, int state, int x, int y)
{
	if(button == GLUT_LEFT_BUTTON)
	{
		if(state == GLUT_DOWN)
		{
			if(x >= new_game->Xpos && x <= new_game->Xpos)
			{
				if(y >= new_game->Ypos/1 && y <= new_game->Ypos/1)
				{
					std::cout << "Hello";
				}
			}
		}
	}
	glutPostRedisplay();
} 

thought, you know that would work.......of course, it doesn't. there anything special I need to do to get this to work? (I thought simply checking the x and y based on the window position, it would work.) THe drawing area is the size of the window (720x480)

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

Are you sure that the drawing area really is the size of the window, consider the window size in these things sometimes includes the height of the title bar and width of side borders etc... also is your window resizeable, if so you may need to account for scaling coordinates. For example (pseudo code):

 

float scaleX = (float)window->Width / (float)viewport->Width;
float realMouseX = x * scaleX;

 

Aimee

Share this post


Link to post
Share on other sites


    if(x >= new_game->Xpos && x <= new_game->Xpos)
        if(y >= new_game->Ypos/1 && y <= new_game->Ypos/1)


re-read this code very carefully. And think about what it logically means for testing. hell throw in random numbers for the variables, and do the logic yourself. the problem should be very apparent at this point. Edited by slicer4ever

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!