Welcome to the forum when you paste code it is best to format your code to make it easier for others to read. You can edit your last post to format the code rather than re-post.
I see in the code you have specified the details of a 3D cube so are you planning to render
- simple 3D geometric shapes e.g. cuboids, ellipsoids, cones, tubes etc, or
- complex 3D models e.g. those used in games etc.
If the first option do you
- want to create the source code from scratch, or
- are you prepared to use a contributed library to do the hard work.
If the later then I can recommend a truly excellent library, Shapes3D it comes with good examples and supporting website. It can even be installed in the PDE using the contributions manager Sorry about the plug but as the library creator I am a little biased.
If the former then I suggest you use PVector and PMatrix3D to represent and manipulate 3D coordinates rather than 2D arrays directly.
Creating and manipulating 2D arrays in Java is mind bending stuff. In the code below two arrays are declared and defined , a
and b
, they look similar but produce orthogonal arrays
float a[][] = new float[1][4];
float b[][] = {{0}, {0}, {0}, {0}};
void setup() {
a[0][3] = 3.142;
b[3][0] = 2.728;
a2dPrint("Array 'a'", a);
a2dPrint("Array 'b'", b);
}
void a2dPrint(String title, float[][] array) {
println("######", title, "#####");
println(" Size", array.length, "x", array[0].length);
for (int i = 0; i < array.length; i++) {
print(" ");
for (int j = 0; j < array[i].length; j++) {
print(array[i][j], " ");
}
println();
}
println("---------------------------------------");
}
Output:
###### Array 'a' #####
Size 1 x 4
0.0 0.0 0.0 3.142
---------------------------------------
###### Array 'b' #####
Size 4 x 1
0.0
0.0
0.0
3.142
---------------------------------------