在六边形上映射纹理
我正在尝试将纹理映射到六边形上,但我无法弄清楚纹理坐标。
These are my vertices:
private float vertices[] = { 0.0f, 0.0f, 0.0f, //center
0.0f, 1.0f, 0.0f, // top
-1.0f, 0.5f, 0.0f, // left top
-1.0f, -0.5f, 0.0f, // left bottom
0.0f, -1.0f, 0.0f, // bottom
1.0f, -0.5f, 0.0f, // right bottom
1.0f, 0.5f, 0.0f}; // right top
六边形的“底面”是垂直的。 (主要是因为我懒得去弄清楚如何旋转该死的东西XD) 现在的问题是,我不知道如何计算出纹理坐标。我查遍了整个网络,但仍然没有成功。
如果有人能向我解释如何计算出纹理坐标,我真的很感激,因为除了对一个简单的正方形进行纹理处理之外,我恐怕无法弄清楚。
注意:这是一个“方形”六边形,因此不是基于圆形。 编辑:六边形是使用 LG_TRIANGLE_STRIP 绘制的。
问题解决了。我现在明白如何找出这些坐标。以下是对我有用的:
private float texture[] = { 0.5f, 0.5f,
0.5f, 0.0f,
0.0f, 0.25f,
0.0f, 0.75f,
0.5f, 1.0f,
1.0f, 0.75f,
1.0f, 0.25f };
I'm trying to map a texture onto a hexagon, but I can't figure out the texture coordinates.
These are my vertices:
private float vertices[] = { 0.0f, 0.0f, 0.0f, //center
0.0f, 1.0f, 0.0f, // top
-1.0f, 0.5f, 0.0f, // left top
-1.0f, -0.5f, 0.0f, // left bottom
0.0f, -1.0f, 0.0f, // bottom
1.0f, -0.5f, 0.0f, // right bottom
1.0f, 0.5f, 0.0f}; // right top
The hexagon's "base" is vertical. (Mainly because I couldn't be bothered to figure out how to rotate the damn thing XD)
Now the thing is, I have no idea how to figure out the texture coordinates. I've looked all over the web, but still wasn't succesful.
I'd really appreciate if someone could explain to me how to figure out texture coordinates, because apart from texturing a simple square I just cannot figure it out I'm afraid.
Note: It's a "square" hexagon, so not based on a circle.
EDIT: The hexagon is drawn using LG_TRIANGLE_STRIP.
PROBLEM SOLVED. I now understand how to figure out these coordinates. Here are the ones that worked for me:
private float texture[] = { 0.5f, 0.5f,
0.5f, 0.0f,
0.0f, 0.25f,
0.0f, 0.75f,
0.5f, 1.0f,
1.0f, 0.75f,
1.0f, 0.25f };
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
纹理坐标的工作方式几乎类似于从 0.0 到 1.0 的百分比,其中 (0.0, 0.0) 位于左下角。如果纹理图像为 128 x 128 像素,则点 (0.25, 0.25) 距左侧和底部 32 像素。使用你那里的东西,如果你试图将六边形精确地刻在方形纹理图形内,你的坐标应该看起来像这样:
如果我没记错的话,你还希望图像垂直翻转。
Texture coordinates work almost like percentages from 0.0 to 1.0 where (0.0, 0.0) is in the lower left. If your texture image is 128 x 128 pixels, then the point (0.25, 0.25) would be 32 pixels in from the left and bottom. Working with what you had there, if you were trying to have the hexagon inscribed exactly inside a square texture graphic, your coordinates should look something like this:
If I recall correctly, you also want the image flipped vertically.
几天来我一直在努力解决同样的问题,我想我已经解决了这个问题。如果您将六边形上的点想象为 A(和 DGJ)位于中心,B 位于 12 点钟方向,CEFHIK 则其他点绕中心逆时针旋转。
您的顶点需要按顺序列出 - ABC DEF GHI JA、D、G 和 J 都是相同的坐标(您的中心点)您的纹理需要按此顺序缝合 - AEF DCB GIH JKA、D、G 和 J 再次成为您的中心点。 K 应与 E 相同,以便纹理与其自身正确对齐。
编辑:回顾一下,我认为仅交换第二个和第三个坐标并从 1.0f 中减去每个 y 坐标可能更有意义。
编辑2:是的,我现在有时间检查一下。只需将每个纹理 y 坐标设置为“-(顶点/多边形高度)”似乎就可以了。您甚至不必交换第二个和第三个点。您仍然需要在纹理坐标数组的末尾添加额外的点;设置为与第二点相同。
I've been struggling with this same problem for a few days now and I think I've just about got my head around it. If you imagine the points on your hexagon as A(and DGJ) in the centre, B at 12 o'clock and CEFHIK the other points rotating anti-clockwise around the centre.
Your vertices need to be listed in the order - ABC DEF GHI JA, D, G and J are all the same coordinates (your center point)Your texture needs to be stitched in this order - AEF DCB GIH JKA, D, G and J are again your centre point. K should be the same as E so the texture lines up with itself correctly.
edit: Looking at this back, I think it may make more sense to only swap each second and third coordinate and subtract each y coord from 1.0f.
edit 2: Yeah I've had time to check now. Simply setting each texture y coordinate to be "-(vertices/polygon height)" seems to work. You don't have to even swap each second and third point. You still need to add the extra point on the end of the texture coords array; set to the same as the second point.