Hi,

does anyone know how to transform screencoords(x,y) to coords in the system defined by center as origin and up and an othogonal vector to it as axes?

Thanks.

Fredy

05-06-2001, 09:52 AM

Anyone did understand this question?

I understood the question. He is asking if anyone knows how to convert local window coordinates into OpenGL coordinates. OpenGL places the origion at the center of the window, while regular window coordinates places the origion in the upper left corner. Though I know what the problem is, I don't know how to solve it.

Hello,

its just mapping one line to another (but in two dimensions! Whoo hoo!=)

the simple, generic way of explaining it is like this:

you know the two end points of the source line and the two end points of the end line, right? so, if f() is your function to map source -> end lines, then

f(a)=a'

f(b)=b'

where a & b are the values for the end points of the source line and a' and b' are values the for the end points of the dest line. Since the eqn of the line is f(x)=mx+c, then we can solve for m and c because they're two unknowns with two equations.

Which is a hard way of explaning the following:

the opengl coordinates are bounded by +/-1, with (0,0) in the centre. WEll, it DEPENDS on what you're talking about, of course... but you'll note that the projection matricies will map 3D points in the frustum to points within this +/-1 (irrespective of your parameters for left/right/up/down in glOrtho, for example).

The screen coordinates are bounded by 0..640,0..480, or whatever resolution you have, right?

So, what's the range of the screen? well, if we consider HORIZONTAL range, we have 640 values... which we want to map to opengl coordinates with a range of 2 (since its between -1 and +1). so, how to conver 640 to 2? the answer is to divide it by 320. But that isn't all... we want 0 to map to -1. How do we do THAT? and that's just subtracting 1...

so, the map from 0..640 to -1..+1 is

f(x)=x/320-1

and that's it. we can plug in known points and see that f(0)=0-1=-1 and f(640)=640/320-1=2-1=1

we can do that for the horizontal coordinates and see that g(y)=y/480-1

---

the reader should note, of course, that this isn't strictly what you want to do. 640 shouldn't map to 1, since 1 is on the far right edge of the ogl coordinate system, but 640 is OFF THE SCREEN. what you WANT to be doing is mapping 0..639 to -1..+1. but, its easier for the sake of discussion to talk about 640 =)

cheers,

John

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.