Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OpenGL 3.x-将方形纹理应用于圆形模型_Java_Opengl_Textures_Geometry - Fatal编程技术网

Java OpenGL 3.x-将方形纹理应用于圆形模型

Java OpenGL 3.x-将方形纹理应用于圆形模型,java,opengl,textures,geometry,Java,Opengl,Textures,Geometry,我有一种在OpenGL中生成圆形对象的方法。它是通过一个可变的数字来实现的,如果这个数字是360,那么360个单独的三角形将组成这个圆 我的问题是,如何将方形纹理应用于整个圆,使其挤压纹理以适合圆 编辑代码: LoD=>详细程度 public static float[] getVerts( int LoD ){ float[] _spokeArray = new float[ (LoD*2) ]; double rad = (360.0d / LoD) * (Math.PI /

我有一种在OpenGL中生成圆形对象的方法。它是通过一个可变的数字来实现的,如果这个数字是360,那么360个单独的三角形将组成这个圆

我的问题是,如何将方形纹理应用于整个圆,使其挤压纹理以适合圆

编辑代码:

LoD
=>详细程度

public static float[] getVerts( int LoD ){
    float[] _spokeArray = new float[ (LoD*2) ];
    double rad = (360.0d / LoD) * (Math.PI / 180.0d);
    for ( int i = 0 ; i < LoD ; i++ ) {
        _spokeArray[ i*2 + 0 ] = (float) Math.cos( rad*i );
        _spokeArray[ i*2 + 1 ] = (float) Math.sin( rad*i );
    }
    float[] _vertArray = new float[ (LoD*9) ];
    for ( int i = 0 ; i < LoD ; i++ ) {
        _vertArray[ i*9 + 0 ] = 0.0f;
        _vertArray[ i*9 + 1 ] = 0.0f;
        _vertArray[ i*9 + 2 ] = 0.0f;

        _vertArray[ i*9 + 3 ] = _spokeArray[ i*2 + 0 ];
        _vertArray[ i*9 + 4 ] = _spokeArray[ i*2 + 1 ];
        _vertArray[ i*9 + 5 ] = 0.0f;

        if ( (i+1) == LoD ){
            _vertArray[ i*9 + 6 ] = 1.0f;
            _vertArray[ i*9 + 7 ] = 0.0f;
            _vertArray[ i*9 + 8 ] = 0.0f;
            break;
        }

        _vertArray[ i*9 + 6 ] = _spokeArray[ (i+1)*2 + 0 ];
        _vertArray[ i*9 + 7 ] = _spokeArray[ (i+1)*2 + 1 ];
        _vertArray[ i*9 + 8 ] = 0.0f;
    }

    return _vertArray;
}

public void setUpTexture() throws GLException, IOException {
    texture = TextureIO.newTexture( imagePath, true );
}

public void draw(GL gl) {
    gl.glBindBuffer( GL3.GL_ARRAY_BUFFER, Main._scene.indexOf( this ) );

    texture.enable( gl );
    texture.bind(   gl );
            // The indices are just: 0, 1, 2, 3, 4, 5 ... LoD*3
    gl.glDrawElements( GL.GL_TRIANGLES, indBuffer.capacity(), GL.GL_UNSIGNED_SHORT, 0 );
}
publicstaticfloat[]getVerts(intlod){
浮点[]_辐条阵列=新浮点[(LoD*2)];
双rad=(360.0d/LoD)*(Math.PI/180.0d);
对于(int i=0;i
将纹理正方形映射到磁盘将导致严重失真

通常,仅使用纹理正方形的内部圆盘部分(浪费一些空间),纹理坐标将是单位圆盘顶点坐标(从[-1,1]调整为[0,1])。顶点
i
示例:

float u = _vertArray[i*9 + 0] * .5f + .5f;
float v = _vertArray[i*9 + 1] * .5f + .5f;
为了仍然扭曲方形纹理以完全映射磁盘,可能的扭曲是使用高
p
Lp
-Norm来模拟无限:

float const p = 30.f; // to adjust
float const epsilon = 0.00001f; // to adjust
float x  = _vertArray[i*9 + 0];
float y  = _vertArray[i*9 + 1];
float l2 = sqrt(x*x + y*y);
float lp = pow( pow(abs(x),p) + pow(abs(y),p), 1.f/p);
float xp = 0.f;
float yp = 0.f;
if( lp > epsilon )
{
    xp = x * l / lp;
    yp = y * l / lp;
}
float u  = xp * .5f + .5f;
float v  = yp * .5f + .5f;

显示您的代码…到目前为止您所做的工作。。。