02-04-2004, 09:30 AM
I'm having a real hard time trying to figure out how units work in this game. What defines the distance from origin? Is it based on the type of projection you're using? (i.e. What makes 1.0 to the right of the origin look like an inch or cm on your screen?) Does it have anything to do with the size of the GL window? I've been hardcoding the position of my objects up to now (insert laugh). And would really like to understand how GL uses/defines coordinates. Anyways I would love any help.
02-04-2004, 09:55 AM
How OpenGL rasterizes verteces (coverts to 2D) does indeed depend on projection.
If your using a 3D projection, positioning things such as health bars will be nigh on impossible.
If you use glOrtho( ... ) you can set up OpenGL for 2D rendering with a given scale. You can use OpenGL in 2D and 3D modes at the same time.
Note: Even in "2D" mode, OpenGL is still in 3D mode, only the projection matrix doesn't add any perspective to the coords
02-04-2004, 11:36 AM
First openGL units are not inches, meters or miles.
OpenGL units are relative, 1 openGL unit can be = to a inch, mile or meters, etc.
ALso openGL units are relative to how you have setup your projection.
Once you learn more about projection and how it relates to unit size, the more it will help with objects size and location.
[This message has been edited by nexusone (edited 02-04-2004).]
02-04-2004, 01:12 PM
Your question is badly phrased, so let's rephrase it:
When you place an object in the world, what governs where it will appear on your screen and how big it is in pixels?
Your first mistake, talking in inches or cm of screen, obviously does not take into account different sized screens of the same resolution. I will leave that one, as generally, the application doesn't care about such things. I think you mean, transforming your object in physical space into screen pixels, and letting the user decide how big a monitor they want to buy.
Even so, there isn't a single answer to this question.
If you use glOrtho, then the projection is parallel:
I purposely made the z range big so you can forget it.
In this projection, if you plot a line:
It will go from the left edge to halfway across the screen at the bottom.
Next, you can set the viewport with glViewpoint, which would limit which area of the screen your transform should apply.
would draw exactly the same thing as before, except that the "window" is now actually a 100x100 pixel square at the lower-left of your window.
Last, if you use gluLookat, glPerspective, etc, the object will be projected using 3d perspective onto the screen, so obviously the farther away it is, the smaller it gets. Yes, for the same perspective, if you have a wider window you will get a different number, and so yes, you do have to take the aspect ratio into account. See the red book for the canonical example, or for that matter most demos use gluLookat or gluPerspective. But the transformation is mapped onto the viewport, so it does in fact depend on window size.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.