Archived

This topic is now archived and is closed to further replies.

jonassen

coordination problem

Recommended Posts

Hey, I would like to ask one thing... The OGL coordination system is pretty easy, but how do I place something on the sides of the screen, so if you maximize or minimize/change resolutions its still in on the side of the screen... Is there any good way to solve this? // Jonas Ericsson

Share this post


Link to post
Share on other sites
Well, if I''m understanding your question right, what you''re wanting to do is keep the screen the same even when resized? This presents kind of a problem, because if you try to keep everything on the screen that was there before when you resize the window, you aspect ratio gets screwed up. If you keep the same aspect ratio, then when you make the window smaller, items will disappear from the screen. I suggest just changing your viewport and keeping the same aspect ratio, so that things in your scene do not get distorted. If you don''t know how viewports work (you probably do, but I''ll assume you don''t), then look at this.


(sx - vl)/(vr - vl) = (x - wl)/(wr - wl)
this is how viewports work to keep everything in the same aspect. That part is for changing in x. Y is the same


(sy - vb)/(vr - vl) = (y - wb)/(wt - wb)


If you rearrange these two equations, you get


sx = (vr - vl)/(wr - wl)*x + (vl - (vr - vl)/(wr - wl)*wl)
and
sy = (vt - vb)/(wt - wb)*y + (vb - (vt - vb)/(wt - wb)*wb)


sx = scale in x
sy = scale in y
vt = viewport top
vb = viewport bottom
vl = viewport left
vr = viewport right
wt = window top
wb = window bottom
wl = window left
wr = window right


opengl actually does this with matrices, but has the same effect. You''ll notice that this is in the form of an ordinary linear equation, y = mx + b. For the first equation call it
sx = Ax + D
where A = (vr - vl)/(wr - wl), x of course equals x still, and
D = (vl - A * wl). The same goes for y of course. Call it
sy = By + C
and do exactly the same thing. Maybe you can figure out exactly what route you want to go by looking at that. Gives you an idea of how your scene will be resized, based on what you put in. You want to make sure and get the same aspect ratio no matter what you do, that is the important thing.

Share this post


Link to post
Share on other sites
Since all OpenGL coords are relative, from -1 to 1, your question is pointless since when you change your window size -1 is still the left hand side and 1 is still the right and size and 0 is still the middle.

Actually everthing I just said is actually to do with the viewport. When your window is first created the viewport is set to it''s dimensions. If you change the window as your going you need to make sure you update the size of the viewport with glViewport


OMG. It''s him again. Call the SHRINK!!!
rambo_bones@hotmail.com
WebSite: http://www.illicitdev.net/~rambobones
GlRott Page: http://www.glrott.tk

Share this post


Link to post
Share on other sites
What do you mean all opengl coordinates are relative to 1 and -1?? That isn''t true at all. It depends on how you set your frustum if you''re using perpective projection, or your orthographic projection is you''re not. You can set your coordinate system to whatever you want. By default your viewport will be your entire window. You can change this with a call to glViewport, but if you don''t set your aspect ratio to 4/3 for most monitors (unless you have a really weird one) then distrotion will occur when you draw. You could set up ortho like this


glOrtho(-100, 100, -75, 75, -1, 1);


that will set your coordinate system from -100 to positive 100 in the x direction, -75 to 75 in the y direction, and -1 and 1 in the z direction. That gives you a 4/3 aspect ratio, and on most monitors, you''re drawing will not be distorted. In perspective


gluPerspective(45.0f, 4/3, 1, 150);


would set up a window with a 45 degree opening in the y direction, set up a 4/3 aspect ration, and set your near clipping plane to 1 and far clipping to 150. Maybe you''re talking about something else, but you can set your own coordinate system (many with coordinate frames if you like). You specify your own origin and clipping planes. If your window is fullscreen and you have an aspect ratio of 4/3 you should be fine, but what if your aspect ratio is 3/3 (a perfect square). Your drawing would be messed up. You need to change your viewport with respect to what you''re trying to draw in the window.

Share this post


Link to post
Share on other sites