gpt4 book ai didi

Android OpenGL ES 为纹理生成圆形网格

转载 作者:太空狗 更新时间:2023-10-29 12:50:27 25 4
gpt4 key购买 nike

我是 Android 上 OpenGL-ES 的新手,我有一个关于为表示圆形的纹理生成网格的问题。

左边是我想要的网格,右边是我的纹理:

Desired mesh on the left, and my Texture on the right

如何生成左侧的网格?然后按以下方式渲染它:

triangle1{Centerpoint, WhitePoint, nextpointclockwise(say #1)},
triangle2{Centerpoint, point#1, nextpointclockwise(say #2)},
triangle3{Centerpoint, point#2, nextpointclockwise(say #3)}

最佳答案

这将创建一个半径为 1 的圆的顶点和纹理坐标(但我实际上没有尝试过,所以它可能不起作用:))然后你可以把它们画成 TRIANGLE_FAN

public void MakeCircle2d(int points)
{
float[] verts=new float[points*2+2];
float[] txtcord=new float[points*2+2];


verts[0]=0;
verts[1]=0;
txtcord[0]=0.5f;
txtcord[1]=0.5f;
int c=2;
for (int i = 0; i < points; i++)
{
float fi = 2*Math.PI*i/points;
float x = Math.cos(fi + Math.PI) ;
float y = Math.sin(fi + Math.PI) ;

verts[c]=x;
verts[c+1]=y;
txtcord[c]=x*0.5f+0.5f;//scale the circle to 0.5f radius and plus 0.5f because we want the center of the circle tex cordinates to be at 0.5f,0.5f
txtcord[c+1]=y*0.5f+0.5f;
c+=2;
}
}

关于Android OpenGL ES 为纹理生成圆形网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12626859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com