Extracting projected coordinates

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting projected coordinates

Christian Catchpole
I'v been pretty good at the googling and DIY.  I have working out how to switch into 2D mode for rendering 'overlays'.

http://twitpic.com/1pv3oa

Now, what I can't work out, is there a good way to extract the 2D coordinates of a point that has been projected in 3D.  This is obviously so I can line up overlays, calculate mouse coordinates etc.

So even if there is way to get OpenGL to move the overlay automatically, I'm thinking im going to need to the 2D coords back anyway.  For mouse coords especially.

Any good links or advise on the whole interfacing with projection would be good.

Another thing I want to do is render an overlay in 2D and then swing is out in 3D.  Which would obviously require taking the 2D coords and estimating the rotation and scaling values to place it roughly the same place using 3D methods.. if that makes sense.

Thanks,
Christian
Reply | Threaded
Open this post in threaded view
|

Re: Extracting projected coordinates

Demoscene Passivist
Administrator
If u actually are only going for mouse interaction with ur framebuffer, theres already buildin functionality from OpenGL wich helps with that kind of "interactive" tasks. See here: http://www.opengl.org/resources/faq/technical/selection.htm

The functions involved are mainly glInitNames/glPushName/glPopName/glSelectBuffer/glRendeMode/glFeedbackBuffer/gluPickMatrix. I'm sure u will find tons of tutorials doing interactive graphics with OpenGL googling these functions.

Hope that helps ...
Reply | Threaded
Open this post in threaded view
|

Re: Extracting projected coordinates

Michael Bien
In reply to this post by Christian Catchpole
its probably time for a screenshot :)

)
http://people.fh-landshut.de/~mbien/weblog/engine2/screenshot31.png

its old and not ready to be open sourced but I was able to render swing/java2d inside a heavyweight GLCanvas :)
2d and 3d mode, working windows etc

(code was a bit ugly and to integrated with my 3d engine so no tips from my side)
Reply | Threaded
Open this post in threaded view
|

Re: Extracting projected coordinates

Christian Catchpole
Thanks guys.

http://www.twitvid.com/53G7O

This is what I have so far.  I'm using an AWT component I had already written which uses transparency and I rendered it to a BufferedImage, then converted it to OpenGL image.  But the plan is to probably at least use OpenGL to render the transparent panel.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting projected coordinates

Evert B
In reply to this post by Christian Catchpole
I'm not so sure if I understand your question.

If you want to get the 3D world coordinates of a 2D point on the screen: you can use GL selection API's as Demoscene Passivist pointed out or any one of many "picking ray" solutions.

If you want to get the 2D screen coordinates of a point in 3D world space (which is what I think you want): you should be able to just transform your point using the modelview and projection matrices - which you can extract from GL or build yourself - and then multiply with the dimensions of your screen. Ask if you need any more info.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting projected coordinates

Christian Catchpole
Thanks. Yeah, that sounds like the way to go.

What I want to do it draw a 2D window using 2D techniques.  But then when you say "close" the window, it rotates and disappears (swings away off in some direction).  So you now want to start projecting this 2D plane in 3D and swing it out of view.