有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

动态绘制多维数据集的java问题

我有一个浮点数组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在这个类中,我从float数组中绘制立方体,我已经检查了立方体的值是否确实存在,当我在其中编码数组时,它工作,但当我动态构建数组,然后传递它时,立方体不会绘制。我这样给全班打电话

           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) 个答案

  1. # 1 楼答案

    这基本上不是一个答案,但有几件事需要检查:

    • 数据的缠绕顺序是否正确?启用双面渲染,然后查看它是否有效
    • 您确定生成的数据在视口中吗
    • 你确定生成的数据是正确的吗
    • 也许立方体的大小是0
    • 如何渲染阵列?8000美元似乎有点贵

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

  2. # 2 楼答案

    我会把这个问题简化一点。如果让数组足够大,只容纳一个立方体,并以相同的方式填充它(但只填充一次),它会工作吗?如果你把它做得足够大,可以容纳两个立方体,然后给它两个立方体的数据量呢