On Wednesday 17 August 2005 03:57, Sergey Plis wrote: > Hi, > > Is there a simple way to transform window coordinates to those of > opengl. I do not need depth - x and y would do.
Good question. The 3d-turtle initialization code takes width and height of the window, near and far distance, and then normalizes these coordinates. Your starting point is at 0 0 0, i.e. in the center of the picture, looking right into the picture (z direction, right hand system: thumb (x) up, index (y) finger right, middle (z) finger into the picture). If you do a <near> FORWARD (with the "near" parameter - FORWARD alone is always in z direction), you can start drawing (everything closer to you is clipped). At this point, a quadrat with side length 2 is fully visible (e.g. try 1e 1e 1e 4 cylinder). If w > h, left and right of this quadrat the background is visible, if h > w, up and down. If you are further away, everything is near/z smaller (the 5 60 near/far relation used in the examples means that at the far point (60), you can go at least 12 units in each direction, or draw a 12e 12e 1e 4 cylinder). If you want an easy trick, use the "scale" operator. Go to the near point first (e.g. by 5 forward), and then scale by <w> <h> min s>f 1/f f2* scale (<w> and <h> are the width and height of the opengl window). Then, you have a one-by-one relation between X pixels and opengl coordinates (x and y). The origin is still the center of the opengl window, but a translation with forward-xyz can change that (anyway, this translation is trivial). If you are deeper down, do a <z> <near> f/ scale to obtain the 1:1 relation. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://www.jwdt.com/~paysan/
pgpnJfRFBEGzU.pgp
Description: PGP signature
