【问题标题】:How to define a polygon Vertices to fit the texture?如何定义多边形顶点以适应纹理?
【发布时间】:2014-10-01 07:58:21
【问题描述】:
我在高中时没有做太多数学,但经过大量研究后,我了解到要绘制多边形,我们需要定义一个浮点数组作为其顶点。但是我不明白如何让多边形适合纹理。
我做了很多研究,但找不到答案或简单的演示来说明人们如何映射他们的纹理以使多边形适合。我所能看到的只是浮点数组的直接演示,而不是它们如何得到每个点。
目前我使用大约 8 个矩形来填充我的纹理以进行碰撞检测,这不是很有效。
【问题讨论】:
标签:
java
android
libgdx
collision-detection
polygon
【解决方案1】:
这是我很久以前编写的一些代码的注释,用于使用 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)
*
* */