繁体   English   中英

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

[英]How to define a polygon Vertices to fit the texture?

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

我做了很多研究,但是找不到关于人们如何绘制纹理以使多边形合适的答案或简单的演示。 我所看到的只是浮点数组的直接演示,而不是它们如何得到每个点。

到目前为止,我正在使用大约8个矩形填充我的纹理以进行碰撞检测,这不是很有效。

这是我很久以前写的一些代码的注释,该代码使用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)
             * 
             * */

暂无
暂无

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

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