简体   繁体   English

OpenGl更改坐标系的度量单位

[英]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. 我正在使用最新的蓝皮书学习OpenGL,希望能对此有所澄清。 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. 该书说您可以将任何测量系统用于坐标系,但是在进行3D透视编程时,世界坐标为+ 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. 我会只使用转换(x(feet),y(feet),z(feet)),其他功能,还是有一些功能可以更改x,y世界坐标(即将默认值从-1 / + 1更改为例如(-20/20)我知道openGl会将剩下的所有单位都转换。

So i guess My biggest gap of knowledge is how to I model real world objects (lengths) to make sense in OPenGL? 因此,我想我最大的知识空白是如何为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. 通常,当您在OpenGL中实际操作对象时,使用的标准世界坐标不限于-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'. 这些世界坐标可以是您喜欢的任何东西,通过乘以模型视图和投影矩阵,然后除以齐次坐标“ w”,可以转换为归一化坐标。

OpenGL will do all this for you (until you get into shaders) so don't really worry about normalized coordinates. OpenGL将为您完成所有这些工作(直到您进入着色器),因此不必担心标准化坐标。

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. 如果将1个OpenGL单位设置为1米,然后在此基础上完美构建所有东西以进行缩放,那么您将拥有所需的比例(即10米将是10个openGL单位,而1毫米将是0.001个OpenGL单位。

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. 但是,如果要引入一个设计为1 OpenGL单位= 1英尺的模型,则该对象最终将变得太大〜3倍。

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. …但是,在进行3D透视编程时,世界坐标为+ 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). 假设您有一个90°FOV的透视投影,靠近剪辑平面为0.01,远离剪辑平面为10.0,为二次方(为简单起见)。 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. 然后,您进入世界的视图体积将解析为一个边长为0.01且与观察者接近0.01距离的矩形,并在边长为0.02的远处拉伸到10.0。 Reduce the FOV and the lateral lenghts shrink accordingly. 降低FOV,横向长度相应缩小。

Nevertheless, coordinates in about the range 0.01 to 10. are projected into the +/-1 clip space. 尽管如此,大约在0.01到10范围内的坐标会投影到+/- 1剪辑空间中。

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. 归一化窗口坐标范围始终为-1到+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. 假设我们希望范围是-100到+100,然后将实际坐标除以100。在这种情况下,请仅使用函数glVertex2f或glVertex3f。 eg glVertex2f(10/100,10/100). 例如glVertex2f(10 / 100,10 / 100)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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