简体   繁体   English

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

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

I have not done much maths in my high school but after much research I understand that to draw a polygon we need to define an array of float as its vertices. 我在高中时并没有做太多的数学运算,但是经过大量研究,我了解到要绘制多边形,我们需要定义一个float数组作为其顶点。 However I don't understand how to get the polygon to fit the texture. 但是我不明白如何使多边形适合纹理。

I did a lot of research but couldn't find answer or simple demonstration as to how as to how do people map their texture so that the polygon fits right. 我做了很多研究,但是找不到关于人们如何绘制纹理以使多边形合适的答案或简单的演示。 All I can see is direct demonstration of array of float but not how they got each point. 我所看到的只是浮点数组的直接演示,而不是它们如何得到每个点。

As for now I am using about 8 rectangles to fill my texture for collision detection which is not very efficient. 到目前为止,我正在使用大约8个矩形填充我的纹理以进行碰撞检测,这不是很有效。

This is a comment from some code I wrote a long time ago for binding a texture to a rectangle using lwjgl (which uses Java OpenGL) 这是我很久以前写的一些代码的注释,该代码使用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