3

私は Android で OpenGL-ES を初めて使用します。円を表すテクスチャのメッシュの生成に関して質問があります。

希望のメッシュが左側、テクスチャが右側:

目的のメッシュが左側にあり、テクスチャが右側にある

左側のメッシュを生成するにはどうすればよいですか? 次に、次の方法でレンダリングします。

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

2 に答える 2

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;
    }
}
于 2012-09-28T10:15:51.920 に答える
0


あなたのコードのおかげで、iOS の 2D OGLes1.1 プロジェクトで動作するようになりました。
かなりうまく機能します。少し面倒ですが、学習者には良いかもしれません。
ありがとう。

-(void) MakeCircle2d:(int)points pos:(CGPoint)pos rad:(GLfloat)rad texName:(GLuint)texName
{
float verts[(points*2)+2];
float txtcord[(points*2)+2];
verts[0]=pos.x;
verts[1]=pos.y;
txtcord[0]=0.5f;
txtcord[1]=0.5f;
int c=2;
for (int i = 0; i < points; i++)
{
    float fi = 2.0*M_PI*((float)i/(float)(points-2.0));
    float x = sinf(fi + M_PI) ;
    float y = cosf(fi + M_PI) ;

    verts[c]=pos.x+(x*rad);
    verts[c+1]=pos.y+(y*rad);
    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;
}



glColor4f(1.0,1.0,1.0,1.0);
//glColor4f(0.0,0.0,0.0, 0.0);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glPushMatrix();

glBindTexture(GL_TEXTURE_2D, texName);

glTexCoordPointer(2, GL_FLOAT, 0, txtcord);
glVertexPointer(2, GL_FLOAT, 0, verts);
glDrawArrays(GL_TRIANGLE_FAN, 0, points);

//glBindTexture(GL_TEXTURE_2D, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();


}
于 2013-04-07T21:15:41.493 に答える