We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › draw cube of cubes from back to front
Page Index Toggle Pages: 1
draw cube of cubes from back to front (Read 359 times)
draw cube of cubes from back to front
Jun 24th, 2008, 4:58am
 
I'm having trouble figuring out how to render a group of boxes from back to front in order to take advantage of depth testing in OpenGL. My sketch is a cube that is composed of multiple smaller cubes (similar to the "3D and OpenGL" > Form > CubicGrid example that comes with Processing). I am rotating the composed large cube with something like the following code:

Inside my composite cube class
...
pushMatrix();
translate( loc.x, loc.y, loc.z );
rotateX( PApplet.radians( xRotation ) );
rotateY( PApplet.radians( yRotation ) );
renderMyCubes( myArrayOfCubes );
popMatrix();

The problem with this is that I don't know the location of each cube because I'm using the matrix and rotation operations to simplify drawing the cube objects in myArrayOfCubes. What I'd rather do is figure out the location and rotation of each SubCube of the composite so that I can sort those SubCubes from back to front before rendering them.

I'm not sure if that makes any sense, but I'd appreciate any help you can give. I can try and explain it a different way if this didn't make sense.
Thanks
Page Index Toggle Pages: 1