English 中文(简体)
露格勒斯世界
原标题:Spinning globe in Opengl-es

我发现,这部法律在开放市场上创造了一个领域。 我无法理解这一逻辑,请允许我就此向我提出一些见解。

private void generateData() {
           
            slicesBuffers = new FloatBuffer[slices];
            normalsBuffers = new FloatBuffer[slices];
            texCoordsBuffers = new FloatBuffer[slices];
         
           
            for (int i = 0; i < slices; i++) {
                   
                    float[] vertexCoords = new float[7 * (stacks + 1)];
                    float[] normalCoords = new float[4* (stacks + 1)];
                    float[] textureCoords = new float[10 * (stacks + 1)];
                    
                    
                   
                    double alpha0 = i * (2 * Math.PI) / slices;
                    double alpha1 = (i + 1) * (2 * Math.PI) / slices;
                   
                    float cosAlpha0 = (float) Math.cos(alpha0);
                    float sinAlpha0 = (float) Math.sin(alpha0);
                    float cosAlpha1 = (float) Math.cos(alpha1);
                    float sinAlpha1 = (float) Math.sin(alpha1);

                    for (int j = 0; j <= stacks; j++) {
                           
                            double beta = j * Math.PI / stacks - Math.PI / 2;
                           
                            float cosBeta = (float) Math.cos(beta);
                            float sinBeta = (float) Math.sin(beta);
                           
                            Utils.setXYZ(vertexCoords, 6 * j,
                                            radius * cosBeta * cosAlpha1,
                                            radius * sinBeta,
                                            radius * cosBeta * sinAlpha1);
                            Utils.setXYZ(vertexCoords, 6 * j + 3,
                                            radius * cosBeta * cosAlpha0,
                                            radius * sinBeta,
                                            radius * cosBeta * sinAlpha0);
                           
                           
                                    Utils.setXYZ(normalCoords, 6 * j,
                                                    cosBeta * cosAlpha1,
                                                    sinBeta,
                                                    cosBeta * sinAlpha1);
                                    Utils.setXYZ(normalCoords, 6 * j + 3,
                                                    cosBeta * cosAlpha0,
                                                    sinBeta,
                                                    cosBeta * sinAlpha0);
                          
                                    Utils.setXY(textureCoords, 4 * j,
                                                    ((float) (i + 1)) / slices,
                                                    ((float) j) / stacks);
                                    Utils.setXY(textureCoords, 4 * j + 2,
                                                    ((float) i) / slices,
                                                    ((float) j) / stacks);
                           
                    }
                   
                    slicesBuffers[i] = FloatBuffer.wrap(vertexCoords);
                    
                            normalsBuffers[i] = FloatBuffer.wrap(normalCoords);
                            texCoordsBuffers[i] = FloatBuffer.wrap(textureCoords);
                  
            }
    }

感谢

问题回答

实地生成理论:

en.wikipedia.org/wiki/Sphere (Vertex)

en.wikipedia.org/wiki/UV_mapping (Texture coordinate) http://groups.google.com/group/android-developers/browse_thread/thread/0030261b82ed71e5/338fc1dcbfe6945f?lnk=raot(Normal surface)

你的法典是正确的,它有几个问题,我做了一些更正:

public Sphere(int slices,int stacks, float radius, float H,float K,float Z, Bitmap image,Bitmap first,Bitmap second){


    FloatBuffer[] slicesBuffers = new FloatBuffer[slices];
    FloatBuffer[] normalsBuffers = new FloatBuffer[slices];
    FloatBuffer[] texCoordsBuffers = new FloatBuffer[slices];

    float[] total_vertexBuff;
    float[]  total_normalsBuff;
    float[]  total_textCoordsBuff;
    int vertex_counter = 0;
    int normals_counter = 0;
    int texCoords_counter = 0;
    int position_dst;
    float tmp[];

    for (int i = 0; i < slices; i++) {
      float[] vertexCoords = new float[  2 * 3 * (stacks + 1)];
            float[] normalCoords = new float[  2 * 3 *(stacks + 1)];
            float[] textureCoords = new float[ 4 * (stacks + 1) ];
            double alpha0 = i * (2 * Math.PI) / slices;
            double alpha1 = (i + 1) * (2 * Math.PI) / slices;
            float cosAlpha0 = (float) Math.cos(alpha0);
            float sinAlpha0 = (float) Math.sin(alpha0);
            float cosAlpha1 = (float) Math.cos(alpha1);
            float sinAlpha1 = (float) Math.sin(alpha1);

            for (int j = 0; j <= stacks; j++) {

                    double beta = j * Math.PI / stacks - Math.PI / 2;
                    float cosBeta = (float) Math.cos(beta);
                    float sinBeta = (float) Math.sin(beta);
                    setXYZ(vertexCoords, 6 * j,    radius * cosBeta * cosAlpha1,   radius * sinBeta,   radius * cosBeta * sinAlpha1   );
                    setXYZ(vertexCoords, 6 * j + 3,radius * cosBeta * cosAlpha0,radius * sinBeta,radius * cosBeta * sinAlpha0);
                    vertex_counter +=  2;

                    Log.d(TAG, "j:"+j);

                    setXYZ(normalCoords, 6 * j,cosBeta * cosAlpha1,sinBeta,cosBeta * sinAlpha1);
                    setXYZ(normalCoords, 6 * j + 3,cosBeta * cosAlpha0,sinBeta,cosBeta * sinAlpha0);
                    normals_counter += 2;
                    setXY(textureCoords, 4 * j,((float) (i + 1)) / slices,((float) j) / stacks);
                    setXY(textureCoords, 4 * j + 2,((float) i) / slices,((float) j) / stacks);
                    texCoords_counter += 2;
            iii

            slicesBuffers[i] = FloatBuffer.wrap(vertexCoords);
            normalsBuffers[i] = FloatBuffer.wrap(normalCoords);
            texCoordsBuffers[i] = FloatBuffer.wrap(textureCoords);

    iii



    total_vertexBuff = new float[vertex_counter * 3];
    total_normalsBuff = new float[normals_counter * 3];
    total_textCoordsBuff = new float[texCoords_counter * 2];
    position_dst = 0;
    // ricopio vertici
    for (int i = 0; i < slicesBuffers.length; i++) {
     for(int j = 0; j < slicesBuffers[i].capacity();j++,position_dst++)
      total_vertexBuff[position_dst] = slicesBuffers[i].get(j);

 iii
    position_dst = 0;
 // ricopio normali
    for (int i = 0; i < normalsBuffers.length; i++) {
     for(int j = 0; j < normalsBuffers[i].capacity();j++,position_dst++)
      total_normalsBuff[position_dst] = normalsBuffers[i].get(j);

 iii


    position_dst = 0;
    // ricopio coordinate texture
    for (int i = 0; i < texCoordsBuffers.length; i++) {
     for(int j = 0; j < texCoordsBuffers[i].capacity();j++,position_dst++)
      total_textCoordsBuff[position_dst] = texCoordsBuffers[i].get(j);

 iii




    this.image = image;
    this.half_first = first;
    this.half_second = second;
    this.vertexBuffer = FloatBuffer.wrap(total_vertexBuff);
    this.normalsBuffer = FloatBuffer.wrap(total_normalsBuff);
    this.texCoordsBuffer = FloatBuffer.wrap(total_textCoordsBuff);
    Log.d(TAG, "vertex_counter:"+vertex_counter);
    Log.d(TAG, "texCoords_counter:"+texCoords_counter);
    Log.d(TAG, "vertexBuffer:"+this.vertexBuffer.capacity());
    Log.d(TAG, "texCoordsBuffer:"+this.texCoordsBuffer.capacity());

    this.textures_ids = IntBuffer.allocate(2);
    this.totalVertexCount = vertex_counter;

    this.setPlaneBuffer();
    return;

iii

我确实希望我帮助你。

页: 1

页: 1





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签