动态绘制立方体的问题

时间:2010-07-14 11:22:56

标签: java android arrays opengl-es floating-point

我有一个浮点数组camObjCoord声明为..

public static float camObjCoord[] = new float[8000];

然后我将其索引填充到类似以下内容的类中。

                      public void addcube(float highx, float lowx, float highz, float lowz){
    //Constructing new cube...
    System.out.println("f = " + f);
    Global.cubes++;
    float y = 1.5f;
    System.out.println("highx = " + highx + "lowx = " + lowx + "highz = " + highz + "lowz = " + lowz);
    //FRONT
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = highz;
    //BACK
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    //LEFT
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    //RIGHT
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = highz;
     i++;
    //TOP
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = y; 
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    //BOTTOM
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = lowx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = lowz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = highz;
     i++;
    camObjCoord[i] = highx;
     i++;
    camObjCoord[i] = -y;
     i++;
    camObjCoord[i] = lowz;

    i++;
    int p = 0;
    System.out.println("FULL ARRAY");
    while(p < 72){
        System.out.println(camObjCoord[p]);
        p++;
    }
}

然后我打电话给makeview()

    public void makeview() {
     Intent myIntent = new Intent(this, GLCamTest.class);

        Bundle b = new Bundle();
        b.putFloatArray("tweets", camObjCoord);
        myIntent.putExtras(b);
    this.startActivity(myIntent);
}

然后在新课程中它正在......

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle b = this.getIntent().getExtras();
    float original[] = b.getFloatArray("tweets");
    camObjCoord = original;
    counter++;
}   

然后我有了另一个类class GLLayer,它看起来像以下.. http://pastebin.org/394884在这个类里面我从浮点数组中绘制了多维数据集,我检查了它们的值对于立方体确实存在,当我在其中编码数组时,但是当我动态构建数组然后传递它时,立方体不会绘制。我这样叫这个班......

           glView=new GLLayer(this);
           mPreview = new CamLayer(this, glView); 

任何人都知道为什么?我该如何解决我的问题?只是添加,我在动态绘制时给完全相同的索引

          final static float camObjCoord[] = new float[] {
            // FRONT
             -2.0f, -1.5f,  2.0f,
              2.0f, -1.5f,  2.0f,
             -2.0f,  1.5f,  2.0f,
              2.0f,  1.5f,  2.0f,
             // BACK
             -2.0f, -1.5f, -2.0f,
             -2.0f,  1.5f, -2.0f,
              2.0f, -1.5f, -2.0f,
              2.0f,  1.5f, -2.0f,
             // LEFT
             -2.0f, -1.5f,  2.0f,
             -2.0f,  1.5f,  2.0f,
             -2.0f, -1.5f, -2.0f,
             -2.0f,  1.5f, -2.0f,
             // RIGHT
              2.0f, -1.5f, -2.0f,
              2.0f,  1.5f, -2.0f,
              2.0f, -1.5f,  2.0f,
              2.0f,  1.5f,  2.0f,
             // TOP
             -2.0f,  1.5f,  2.0f,
              2.0f,  1.5f,  2.0f,
             -2.0f,  1.5f, -2.0f,
              2.0f,  1.5f, -2.0f,
             // BOTTOM
             -2.0f, -1.5f,  2.0f,
             -2.0f, -1.5f, -2.0f,
              2.0f, -1.5f,  2.0f,
              2.0f, -1.5f, -2.0f,
        };

然后它将呈现此立方体。它似乎不喜欢我正在制作数组然后动态添加索引。为什么?我该如何解决?对于赏金,我也会接受适用于Android的适当解决方法。

感谢。

edit1:我尝试了各种各样的事情,如果我要像这样声明数组那么,这不是导致问题的数组传递......

edit2:我也尝试打印数组,因为它进入GLLayer(呈现立方体的类),一切都如你所料。我不知道为什么这些立方体不会出现:(

edit3:我已经添加了如何构建浮点数组。

edit4:我也尝试将数组的大小设置为等于我输入的值的数量。不起作用。

2 个答案:

答案 0 :(得分:2)

我会稍微减少这个问题。如果你要使数组足够大,只能容纳一个立方体,并以相同的方式填充它(但只是一次),它会起作用吗?如果你把它做得足够大以容纳两个立方体,并给它两个立方体的数据呢?

答案 1 :(得分:1)

这基本上不是一个答案,而是需要检查的一些事项:

  • 数据是否按正确的顺序排列?启用双面渲染,然后查看它是否有效。
  • 您确定生成的数据是否在视口中?
  • 您确定生成的数据是否是正确的多维数据集?
  • 也许立方体的大小为0?
  • 你是如何渲染数组的? 8000似乎有点多。

整个代码和示例数据在这里可能会有所帮助,因为狙击手可能不包含错误。