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.

# 2D picking theory

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

### #1Yours3!f  Members

Posted 28 October 2012 - 12:01 PM

Hi,

so I'm trying to pick 2D quads. I read this paper (http://www.dyn-lab.c...-selection.html), and I fully understand the theory behind it, however I have a little problem.
All the 2D quads I render start from a quad that is defined like this:

-1, 1..........1, 1
.
.
.
-1,-1..........1,-1

this quad gets translated rotated and scaled, so that it appers on screen where and how I want it. Now the problem is that in the paper, it says that I should do the picking in object space. Now in object space all of the quads are the same right? Because I essentially render the same quad over and over again. So my question is, do I have to transform all the quads into normalized device coordinates, so that I can do picking?
Or is it unnecessary?

Best regards,
Yours3!f

Edited by Yours3!f, 28 October 2012 - 12:02 PM.

### #2sgt_barnes  Members

Posted 29 October 2012 - 02:41 AM

Hello Yours3!f,

yes, that would work. But it makes everything needlessly complicated.

You where right when you said that all your quads are the same in object space. But the picking location isn't... ;-)

So what the article meant, I think, was that you could transform the PICKING LOCATION into the object space FOR EACH OBJECT, then perform a simple min/max test with that object. No need to transform four corners just so you end up with a totally ugly general rectangle inclusion test.

Regards,
Tilmann

### #3Yours3!f  Members

Posted 29 October 2012 - 01:30 PM

Hello Yours3!f,

yes, that would work. But it makes everything needlessly complicated.

You where right when you said that all your quads are the same in object space. But the picking location isn't... ;-)

So what the article meant, I think, was that you could transform the PICKING LOCATION into the object space FOR EACH OBJECT, then perform a simple min/max test with that object. No need to transform four corners just so you end up with a totally ugly general rectangle inclusion test.

Regards,
Tilmann

oh ok
so I just need to perform this:
vec4 objspace_mouse_pos = inv_mvp_of_quad * vec4(mouse_x, mouse_y, 0, 1);
[...]

right?

Edited by Yours3!f, 29 October 2012 - 01:32 PM.

### #4sgt_barnes  Members

Posted 30 October 2012 - 01:58 AM

oh ok
so I just need to perform this:
vec4 objspace_mouse_pos = inv_mvp_of_quad * vec4(mouse_x, mouse_y, 0, 1);
[...]

right?

Exactly!

### #5Yours3!f  Members

Posted 30 October 2012 - 02:02 PM

oh ok
so I just need to perform this:
vec4 objspace_mouse_pos = inv_mvp_of_quad * vec4(mouse_x, mouse_y, 0, 1);
[...]

right?

Exactly!

omg just tried it out, works pixel perfect!!! BIG thank you!

### #6sgt_barnes  Members

Posted 31 October 2012 - 03:00 AM

Hehehe! Very good!
I get this euphoric feeling every time when something involving "heavy math" starts working all of a sudden!

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.