views:

191

answers:

2

Hey guys,

I've got a float array camObjCoord declared as..

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

I'm then filling its indexes in a class that does something like the following..

                      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++;
    }
}

I'm then calling 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);
}

and then in the new class it's doing...

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

I then have another class class GLLayer and it looks like the following.. http://pastebin.org/394884 inside this class I'm drawing the cube(s) from the float array, I've check and the values for the cube are indeed there and when I'm coding the array in it works but when I'm dynamically building the array then passing it the cube doesn't draw. I'm calling the class like so..

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

Anyone have any idea why? How would I fix my problem? Just to add, I am giving the exact same values to the exact same indexes when drawing dynamically

          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,
        };

Then it will render this cube. It appears to not like that I'm making the array and then dynamically adding indexes. Why? how do I fix this? For the bounty I would also accept an appropriate workaround which will work in Android.

Thanks.

edit1: I've tried various things it's not the passing of the array causing the problems if I was to declare the array like so...

edit2: I've also tried printing the array as it goes into GLLayer (class which renders cubes) and everything is as you would expect. I've no idea why these cubes wouldn't be appearing :(

edit3: I've added how I'm constructing the float arrays.

edit4: I've also tried setting the size of the array equal to the number of values I'm inputting. Doesn't work.

+1  A: 

This is basically not an answer but a few things to check:

  • Is the data in the proper winding order? Enable double sided rendering and see if it works then.
  • Are you sure that the generated data is within the viewport?
  • Are you sure that the generated data is even proper cubes?
  • Maybe the cubes are have a size of 0?
  • How are you rendering the array? 8000 seems to be a bit much.

The entire code and sample data might be helpful here, since the snipers probably don't contain the error.

Sean Farrell
1) I've checked, 2) Yes, 3) Yeah, 4) They don't 5) I'm basically adding 72 indexes to the array for every cube and rendering multiple cubes off of 1 float array. It's of size 8000 so it can handle a large amount of dynamic cubes.Thanks for the effort. I'll try and dig out more relevant code. I'm trying not to scare people off with a huge amount of code. I've added the code where I add to the float array.
Ulkmun
Maybe the size of the array is the issue. Try use something like System.arraycopy(camObjCoord, 0, tmparray, 0, i) to cut out the unused array cells.
Anthony Kong
Sadly didn't work :(
Ulkmun
+2  A: 

I would pare down the problem a little. If you were to make the array big enough to hold only one cube, and populate it the same way (but just once), would it work? What if you made it big enough to hold two cubes, and gave it two cubes' worth of data?

Carl Manaster
I've tried both and it hasn't worked. I've even tried copying it to a new array just big enough for the number of cubes being drawn. no luck :(
Ulkmun
Answer lead me to doing something similar that solved the problem :)
Ulkmun
Cool. What was the trick?
Carl Manaster
I'm declaring a seperate array which fills with indexes from the first array. It's assignment and declaration is in 1 step and it works :)
Ulkmun