#### Archived

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

# viewport and projection question

This topic is 5786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

my brain is fried. I have allergies and it's making it difficult to think. Anyway, here is my (probably stupid) question. I set glViewport(0,height,width,height) and that works fine and dandy (sets it up so screen coords are same as window coords) then I set glOrtho(0.0,GLdouble(winx),GLdouble(winy),0.0,-1.0,1.0); where winx and winy are x and y window sizes respectively. Nothing weird there. What I'm trying to do is keep the "world" coordinates equal on both axes. For example:
here is a little window- pretend it is 640x480

----------------
|         (1,1)|
|              |
|    (0,0)     |
|              |
|(-1,-1)_______|

You'll notice that the x and y sizes of the window are different.
However, (1,1) in the world is still the upper right
(which is actually 320 pixels away from the center
on the x axis and 240 pixels up from the y axis-
not a 1:1 ratio as is indicated by the world coordinates)
What this all does is make the acceleration on different axes
for my game objects uneven (the object, travelling at equal
horizontal and vertical velocities, travels at about 33 degrees
across the screen, rather than 45 for a square screen).

My first question is this: how can I make coordinate reckoning on both axes equal? Do I need to change something in glOrtho or glViewport or both? My second question (unrelated to the above schematic): how can I make the "camera" move without changing the positions of all the objects? My idea was to do something like this:
// this goes in an input function called every time through the loop
glMatrixMode(GL_PROJECTION);
glPushMatrix();
// see if a camera control key has been pushed, then...
glOrtho(*adjusted coordinates go here*); // ...do this
// would do the above for every camera control key (up,down,left,right)
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

Would that work to give the effect of moving the camera? Or do I have to move every object in the scene? Well, those are all my questions for now. Thanks for any help or input. [edited by - Irrelevant on April 17, 2002 8:21:14 PM]

##### Share on other sites
glViewport sets the physical window coordinates, resizing it.
glOrtho set the logical world coordinates.

If the aspect ratio (w/h) is the same in both cases you''ll have the effect you want.

e.g. either do a gluOrtho2D( -1.33, 1.33, -1, 1 ); or a glViewport(0,0,480,480);

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...

##### Share on other sites
I can't just use glOrtho? I was trying to avoid the glu functions...
I tried those things with regular ortho, and it didn't work. I thought gluOrtho2d was just glOrtho with near and far already defined?
*edit* nevermind, it's working ok now. Instead of using 1.33 for the larger value, I set the larger value to 1.0 and then determined the smaller value in relation to the larger (ex 480/640 = 0.75 = y-axis ranges)
however, i'm still uncertain how to implement a moving camera effect... any ideas?

[edited by - Irrelevant on April 17, 2002 9:28:33 PM]

##### Share on other sites
quote:
Original post by Irrelevant
glPushMatrix();
....
glPopMatrix();

That won''t do anything, because the glPopMatrix() is destroying the changes.

couldn''t you use glTranslate for the moving camera?

##### Share on other sites
q2/
glOrtho(the normal way);
glTranslatef(x,y,0)

http://uk.geocities.com/sloppyturds/gotterdammerung.html

##### Share on other sites
thanks.
and the coordinates are still off. I was celebrating prematurely. Oh well. I''m more awake today, I get it fixed eventually.