Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


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


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
2 replies to this topic

#1 Enerjak   Members   -  Reputation: 235

Like
0Likes
Like

Posted 11 May 2013 - 07:55 PM

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)

 

 

 



Sponsor:

#2 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 12 May 2013 - 08:00 AM

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


We are now on Tumblr, so please come and check out our site! 

 

http://xpod-games.com


#3 slicer4ever   Crossbones+   -  Reputation: 3991

Like
0Likes
Like

Posted 12 May 2013 - 08:53 AM


    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, 12 May 2013 - 08:54 AM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.




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