如何定义多边形顶点以适应纹理?

时间:2014-10-01 07:58:21

标签: java android libgdx collision-detection polygon

我在高中时没有做太多数学,但经过大量研究后我明白要绘制一个多边形,我们需要定义一个浮点数组作为它的顶点。但是,我不明白如何使多边形适合纹理。

我进行了大量的研究,但无法找到答案或简单演示如何人们如何绘制纹理以使多边形适合。我所能看到的只是浮动数组的直接演示,而不是他们如何获得每一点。

至于现在,我使用大约8个矩形来填充我的纹理以进行碰撞检测,效果不是很好。

1 个答案:

答案 0 :(得分: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)
             * 
             * */