gpt4 book ai didi

java - 动态绘制立方体的问题

转载 作者:太空狗 更新时间:2023-10-29 12:58:33 25 4
gpt4 key购买 nike

我有一个 float 组 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);
}

然后在新类(class)中它正在做...

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 数组中绘制立方体,我已经检查并且立方体的值确实存在,当我在其中编码数组时它可以工作但是当我动态构建数组时然后传递它立方体不绘制。我这样给类(class)打电话..

           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:我添加了构建 float 组的方式。

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

最佳答案

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

关于java - 动态绘制立方体的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3245579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com