Android的OpenGL ES的生成质地的圆形网状 [英] Android OpenGL ES generate a circular mesh for texture
本文介绍了Android的OpenGL ES的生成质地的圆形网状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的OpenGL ES在Android上,和我有一个关于生成的纹理重新presents了一圈网状的问题。
期望中的左侧网格,和我的纹理右:
如何生成左边的目?然后使其在下面的方式:
triangle1 {中心点,白点,nextpointclockwise(例如#1)},
triangle2 {中心点,点#1,nextpointclockwise(例如#2)},
triangle3 {中心点,点#2,nextpointclockwise(比如#3)}
解决方案
这将创建一个半径1圈的顶点和纹理坐标(但我没有真正尝试过,因此它可能无法正常工作:))
然后,你可以画出它们作为TRIANGLE_FAN
公共无效MakeCircle2d(INT分)
{
浮动[] =绿党新的浮动[点* 2 + 2];
浮动[] = txtcord新的浮动[点* 2 + 2];
绿党[0] = 0;
绿党[1] = 0;
txtcord [0] = 0.5F;
txtcord [1] = 0.5F;
INT C = 2;
的for(int i = 0; I<点;我++)
{
科幻浮= 2 * Math.PI * I /分;
浮动X = Math.cos(FI + Math.PI);
浮Y = Math.sin(FI + Math.PI); 绿党[C] = X;
绿党[C + 1] = Y;
txtcord [C] = X * 0.5F + 0.5F; //缩放圈0.5F半径,加上0.5F,因为我们想圆TEX cordinates的中心是在0.5F,0.5F
txtcord [C + 1] = X * 0.5F + 0.5F;
C + = 2;
}
}
I'm new to OpenGL-ES on Android, and I have a question regarding generating a mesh for a texture that represents a circle.
Desired mesh on the left, and my Texture on the right:
How do i generate the mesh on the left? and then render it in the following way:
triangle1{Centerpoint, WhitePoint, nextpointclockwise(say #1)},
triangle2{Centerpoint, point#1, nextpointclockwise(say #2)},
triangle3{Centerpoint, point#2, nextpointclockwise(say #3)}
解决方案
This will create the vertices and texture coordinates of a 1 radius circle(but i didnt actually tried it so it may not work :) ) Then you can draw them as 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]=x*0.5f+0.5f;
c+=2;
}
}
这篇关于Android的OpenGL ES的生成质地的圆形网状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文