简体   繁体   中英

OpenGl changing the unit of measure for coordinate system

I'm learning OpenGL using the newest blue book, and I was hoping to get a point of clarification. The book says you can use any system of measurement for the coordinate system, however when doing 3d perspective programming, the world coordinates are +1/-1.

I guess where I am a little confused is lets say I want to use feet and inches for my world, and I want to build the interior of my house. Would I just use translates (x(feet), y(feet), z(feet)), extra, or is there some function to change you x,y world coordinates (ie change the default from -1/+1 to lets say (-20/20). I know openGl converts everything unit left.

So i guess My biggest gap of knowledge is how to I model real world objects (lengths) to make sense in OPenGL?

I think the author is referring to normalized coordinates (device coordinates) that appear after the perspective divide.

Typically when you actually manipulate objects in OpenGL you use standard world coordinates which are not limited to -1/+1. These world coordinates can be anything you like and are translated into normalized coordinates by multiplying by the modelview and projection matrices then dividing by the homogeneous coordinate 'w'.

OpenGL will do all this for you (until you get into shaders) so don't really worry about normalized coordinates.

Well its all relative. If you set 1 OpenGL unit to be 1 meter and then build everything perfectly to scale on that basis then you have the scale you want (ie 10 meters would be 10 openGL units and 1 millimeter would be 0.001 OpenGL units.

If, however, you were to then introduce a model that was designed such that 1 OpenGL unit = 1 foot then the object is going to end up being ~3 times too large.

Sure you can change between the various methods but by far the best way to do this is to re-scale your model before loading it into your engine.

…however when doing 3d perspective programming, the world coordinates are +1/-1.

Says who? Maybe you are referring to clip space, however this is just one special space in which all coordinates are after projection.

You world units may be anything. The relevant part is, how those are projected. Say you have a perspective projection of 90°FOV, near clip plane at 0.01, far clip plane at 10.0, quadratic aspect (for simplicity). Then your view volume into the world will resolve a rectangle with side lengths 0.01 and 0.01 distance close to the viewer, and stretch to 10.0 in the distant with the 0.02 side lengths. Reduce the FOV and the lateral lenghts shrink accordingly.

Nevertheless, coordinates in about the range 0.01 to 10. are projected into the +/-1 clip space.

So it's up to you to choose the projection limits to match your scene and units of choice.

Normalized window coordinate range is always -1 to +1. But it can be used as you wish. Suppose we want a range -100 to +100 then divide actual coordinate with 100. In this case use the function glVertex2f or glVertex3f only. eg glVertex2f(10/100,10/100).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM