2014-10-01 70 views
0

我在高中時沒有做過很多數學,但經過大量研究後,我明白要繪製一個多邊形,我們需要定義一個浮點數組作爲其頂點。但我不明白如何讓多邊形適應紋理。如何定義多邊形頂點以適應紋理?

我做了大量的研究,但無法找到答案或簡單的演示,以瞭解人們如何映射其紋理,使多邊形符合要求。我能看到的只是直接演示浮點數組,而不是他們如何得到每個點。

至於現在我使用大約8個矩形填充我的紋理進行碰撞檢測,效率不高。

+0

你可能想看看此相關的問題將紋理綁定到一個矩形評論:HTTP: //stackoverflow.com/questions/5532595/how-do-opengl-texture-coordinates-work。 – 2014-10-01 17:07:06

回答

0

這是一些代碼,我寫了一個很久以前使用LWJGL(它使用Java的OpenGL)

/* For each corner of the quad we define the coordinates of both the texture 
      * and the vertex. 
      * 
      * - The vertex coordinates are the coordinates on the screen that 
      *  they are drawn to. 
      * - The texture coordinates tell which portion of the texture is used. 
      * 
      * Texture coordinates are represented in the textureBounds array as follows: 
      * [<leftmost x>, <bottommost y>, <rightmost x>, <topmost y>] 
      * 
      * - Texture coordinates [0.0, 0.0, 1.0, 1.0] mean the whole texture is drawn. 
      * 
      * - [0.0f, 0.0f, 0.5f, 1.0f] means that only the left half of texture is drawn. 
      * 
      * - [0.0f, 0.5f, 2.0f, 1.0f] means that the top half (y is from 0.5 to 1.0) 
      *  of the texture is drawn side-by-side twice (x is from 0.0 to 2.0) 
      * 
      * */