Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

26. May 2012, 10:51:21 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Screen coordinate "picking"
Pages: [1] 2
Print
Author Topic: Screen coordinate "picking"  (Read 2629 times)
slade
Just dropped in

Offline Offline

Posts: 7


View Profile
« on: 13. June 2007, 05:11:57 pm »

Is there a way to pick from a 3-dimensional point in space to a 2-dimensional point on the screen?  Sort of a reverse pick?
Logged
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #1 on: 13. June 2007, 08:21:31 pm »

I haven't really had to solve this problem, but I think you could investigate with the transform of the view...
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #2 on: 13. June 2007, 08:51:02 pm »

In principle you would have to multiply something with the inverse of the view's matrix. Have a look at org.xith3d.picking.PickRay.recalculate(). You would have to invert the whole calculation, and especially the view-transform-matrix.

Hope, this helps.

Marvin
Logged
slade
Just dropped in

Offline Offline

Posts: 7


View Profile
« Reply #3 on: 13. June 2007, 09:16:02 pm »

Am I missing something?  The recalculate calls all have 2-dimensional coordinates... we are starting with a 3D coordinate and trying to come back to an x,y on the screen.  Thanks...
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 13. June 2007, 10:02:04 pm »

Am I missing something?  The recalculate calls all have 2-dimensional coordinates... we are starting with a 3D coordinate and trying to come back to an x,y on the screen.  Thanks...

As I said. You have to invert the calculation. So it's not a wonder, that the parameters are what you want to retrieve.

btw. What do you need this for?

Marvin
Logged
Arne Müller
Enjoying the stay
*
Offline Offline

Posts: 32

340473970
View Profile
« Reply #5 on: 13. June 2007, 10:38:33 pm »

I have no idea how to do this, but it never the less should be easy and actually be very fast, because I think, thats one of the things your gpu is doing all the time...

my guess:
dig in View, probably even in the underlying renderer stuff. There should be something. Simply keep in mind, when searching, what you need to compute those coordinates.
- your world coordinate
- your screen position and rotation in the 3d world
- your screen resolution, field of view (view angle)
- Projection-Type

Arne
Logged

42.
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #6 on: 13. June 2007, 11:01:48 pm »

I have no idea how to do this, but it never the less should be easy and actually be very fast, because I think, thats one of the things your gpu is doing all the time...

Yeah, it is done by the GPU. But this is exactly the reason, why you won't find any code for this in xith.

What you would need is the code to transform world coordinates to rasterization coordinates. And this is done transparently by the GPU. Though you should find documentation about this calculation somewhere in OpenGL.

Marvin
Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #7 on: 13. June 2007, 11:18:13 pm »

Isn't this just applying the current ModelView and Projection Matrix to the 3D coordinate?
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #8 on: 14. June 2007, 07:52:38 am »

Isn't this just applying the current ModelView and Projection Matrix to the 3D coordinate?

Yeah. But I'm pretty sure, that there's an additional step to rasterize them (produce pixel coordinates).

Marvin
Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #9 on: 14. June 2007, 08:14:11 am »

Should be a simple projection to from viewport space to window coordinates.
Logged

slade
Just dropped in

Offline Offline

Posts: 7


View Profile
« Reply #10 on: 14. June 2007, 05:56:51 pm »

btw. What do you need this for?

Well I'd like to be able to, say, pick on an object, and then using this projection I'd like to have a window, perhaps a HUD display, pop up next to it at an appropriate screen x,y.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #11 on: 14. June 2007, 07:15:35 pm »

Well I'd like to be able to, say, pick on an object, and then using this projection I'd like to have a window, perhaps a HUD display, pop up next to it at an appropriate screen x,y.

So wouldn't it suffice to take the initial picking x,y coordinates to popup the widget at?

Marvin
Logged
slade
Just dropped in

Offline Offline

Posts: 7


View Profile
« Reply #12 on: 14. June 2007, 07:35:52 pm »

So wouldn't it suffice to take the initial picking x,y coordinates to popup the widget at?

Marvin

Nope...  I want to be able to move my View around and have that widget follow the object's relative position unless the object (or some arbitrary point on the object) leaves the screen.
Logged
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #13 on: 14. June 2007, 07:46:27 pm »

Could you maybe, instead of using a HUD display, just use a automatic billboard floating over the object and then use normal picking to emulate buttons, etc.?  Just an idea.
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
slade
Just dropped in

Offline Offline

Posts: 7


View Profile
« Reply #14 on: 14. June 2007, 09:09:49 pm »

Could you maybe, instead of using a HUD display, just use a automatic billboard floating over the object and then use normal picking to emulate buttons, etc.?  Just an idea.

I'm not sure if this is an option or not.  Some of the HUD widgets look pretty convenient, such as Image.  If I can fake these in other ways, I might go that direction.
Logged
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic