Easy Way To Translate Screen to Ortho/Viewport
Moderator: InsideQC Admins
3 posts
• Page 1 of 1
Easy Way To Translate Screen to Ortho/Viewport
I know how to do the math manually, but I am wondering if anyone knows an easy way to translate screen coordinates (mouse click X, Y) into a 2D glOrtho/Viewport with the matrices by grabbing them and performing a calculation.
I may answer my own question.
I could do it manually, but I am looking for an "elegant" solution.
For example:
If I manually calculate it, I'm only solving this instance of the issue. Should be a way to elegantly translate into or translate out of the viewport.
[Yes, I'm matrix rusty. I bet a year ago I would have solved this one in 10 seconds flat.
]
I may answer my own question.
I could do it manually, but I am looking for an "elegant" solution.
For example:
mouse click at 64, 180 in client window
Where does it hit a viewport from (100,100)-(700,500) scaled with glOrtho to have coordinates of (0,0) through (320,200)
If I manually calculate it, I'm only solving this instance of the issue. Should be a way to elegantly translate into or translate out of the viewport.
[Yes, I'm matrix rusty. I bet a year ago I would have solved this one in 10 seconds flat.
The night is young. How else can I annoy the world before sunsrise?
Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
-

Baker - Posts: 3666
- Joined: Tue Mar 14, 2006 5:15 am
Re: Easy Way To Translate Screen to Ortho/Viewport
gluProject gives you vertex->screen (useful for crosshairs)
gluUnproject gives you screen->vertex (useful for cursors)
both need the viewmodel and projection matricies
so if you want to find what 3d object the user just clicked on, unproject(x,y,0) and unproject(x,y,1), trace a line between them, see what the trace hit.
you can either google the specific formulas that glu uses, or you can rip Matrix4x4_CM_UnProject/Matrix4x4_CM_Project from FTE or qrack or whatever other engines it got copied to. presumably dp has some equivelent somewhere.
gluUnproject gives you screen->vertex (useful for cursors)
both need the viewmodel and projection matricies
so if you want to find what 3d object the user just clicked on, unproject(x,y,0) and unproject(x,y,1), trace a line between them, see what the trace hit.
you can either google the specific formulas that glu uses, or you can rip Matrix4x4_CM_UnProject/Matrix4x4_CM_Project from FTE or qrack or whatever other engines it got copied to. presumably dp has some equivelent somewhere.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Re: Easy Way To Translate Screen to Ortho/Viewport
hmm nope i dont have those either...
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest