OpenGL的坐標(biāo)系統(tǒng)

原文鏈接

OpenGL expects all the vertices, that we want to become visible, to be in normalized device coordinates after each vertex shader run. That is, the x, y and z coordinates of each vertex should be between -1.0 and 1.0; coordinates outside this range will not be visible.

坐標(biāo)系統(tǒng)變換圖解

將坐標(biāo)變換為標(biāo)準(zhǔn)化設(shè)備坐標(biāo),接著再轉(zhuǎn)化為屏幕坐標(biāo)的過(guò)程通常是分步進(jìn)行的,也就是類似于流水線那樣子。在流水線中,物體的頂點(diǎn)在最終轉(zhuǎn)化為屏幕坐標(biāo)之前還會(huì)被變換到多個(gè)坐標(biāo)系統(tǒng)(Coordinate System)。將物體的坐標(biāo)變換到幾個(gè)過(guò)渡坐標(biāo)系(Intermediate Coordinate System)的優(yōu)點(diǎn)在于,在這些特定的坐標(biāo)系統(tǒng)中,一些操作或運(yùn)算更加方便和容易,這一點(diǎn)很快就會(huì)變得很明顯。對(duì)我們來(lái)說(shuō)比較重要的總共有5個(gè)不同的坐標(biāo)系統(tǒng):

  • 局部空間(Local Space,或者稱為物體空間(Object Space))
  • 世界空間(World Space)
  • 觀察空間(View Space,或者稱為視覺(jué)空間(Eye Space))
  • 裁剪空間(Clip Space)
  • 屏幕空間(Screen Space)
  1. Local coordinates are the coordinates of your object relative to its local origin; they're the coordinates your object begins in.
  2. The next step is to transform the local coordinates to world-space coordinates which are coordinates in respect of a larger world. These coordinates are relative to a global origin of the world, together with many other objects also placed relative to the world's origin.
  3. Next we transform the world coordinates to view-space coordinates in such a way that each coordinate is as seen from the camera or viewer's point of view.
  4. After the coordinates are in view space we want to project them to clip coordinates. Clip coordinates are processed to the -1.0 and 1.0 range and determine which vertices will end up on the screen.
  5. And lastly we transform the clip coordinates to screen coordinates in a process we call viewport transform that transforms the coordinates from -1.0 and 1.0 to the coordinate range defined by glViewport. The resulting coordinates are then sent to the rasterizer to turn them into fragments.

You probably got a slight idea what each individual space is used for. The reason we're transforming our vertices into all these different spaces is that some operations make more sense or are easier to use in certain coordinate systems. For example, when modifying your object it makes most sense to do this in local space, while calculating certain operations on the object with respect to the position of other objects makes most sense in world coordinates and so on. If we want, we could define one transformation matrix that goes from local space to clip space all in one go, but that leaves us with less flexibility.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 我一直覺(jué)得聽(tīng)著些安靜的歌,人也會(huì)變得安靜起來(lái)。這樣的安靜不是去尋求,尋不來(lái)的,得等,得遇。如這次的廈門之旅。 這次...
    iZher閱讀 851評(píng)論 0 1
  • 來(lái)源:中國(guó)好案例(ID:ChinaCase) 作為騰訊第二號(hào)人物小T張志東,騰訊產(chǎn)品的架構(gòu)者,除了馬化騰之外最有話...
    STONEPCC閱讀 850評(píng)論 0 0
  • 甭知,從天南地北哪個(gè)方向,刮來(lái)一股斗圖裝逼轟。 然后,社交聊騷軟件就被下面這群人民藝術(shù)家,霸!屏!了! 是滴, 偉...
    古力歐閱讀 66,287評(píng)論 7 7
  • 我不知道咋樣寫文,求大神來(lái)教我 謝謝 我先寫文吧,不要注意標(biāo)點(diǎn)和格式謝謝。 ...
    9420970e9718閱讀 279評(píng)論 2 0

友情鏈接更多精彩內(nèi)容