Hi all.
I am new to Processing, and to writing code in general, so forgive me in advance if I don't express myself clearly.
My goal is to make a 10x10 grid of Cubes floating in 3d space. Eventually each cube will be textured with a corresponding piece of an image, so that a composite image is formed.
I have decided to use the Quark Shape3D library, which has a Box() class that allows for all 6 "faces" of the cube to use a different image as texture.
The problem I am having is that I do not really understand how the Box() class receives position and rotation parameters. I have been using
- cube[i][j].shapeOrientation(null, new PVector(i*30, j*30, 20));
which positions the cubes into roughly the shape I want, but I don't really understand the what "PVector" is or how it decides the position. 0,0 seems to place the cubes at the center of the image, rather than at the top left as I would expect.
Then in void draw() I have included code to rotate each Cube, but instead of each cube rotating on its own axis, all the cubes end up rotating around a universal axis.
So I wonder if someone can help by explaining how the Shapes3d library actually works. I have been digging through the library "Reference" pages, but I don't understand it much since everything is composed of abbreviations and acronyms. Below is the full code, I have commented out the lines involving Texturing so that you won't have to download dependent files.
- import shapes3d.utils.*;
- import shapes3d.animation.*;
- import shapes3d.*;
- Box[][] cube;
- int cols = 10;
- int rows = 10;
- float angleX, angleY, angleZ;
- void setup() {
- size(400,400, P3D);
- background(160, 0, 90);
- lights();
- cube = new Box[cols][rows];
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- cube[i][j] = new Box(this);
- //String[] faces = new String[] {
- // "face_00.png", "face_01.png", "face_02.png",
- // "face_03.png", "face_04.png", "face_05.png"
- //};
- //cube[i][j].setTextures(faces);
- cube[i][j].fill(color(255));
- cube[i][j].setSize(20,20,20);
- cube[i][j].drawMode(S3D.TEXTURE | S3D.SOLID);
- cube[i][j].shapeOrientation(null, new PVector(i*30, j*30, 20));
- }
- }
- frameRate(30);
- }
- void draw() {
- background(175, 0, 90);
- //directionalLight(0, 255, 0, 0, -1, 0);
- //directionalLight(160, 0, 90, 0, 0, -1);
- lights();
- pushMatrix();
- camera(0, 0, 400, 100, 100, 0, 0, 1, 0);
- angleX += radians(.013f);
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- rotateX(angleX);
- cube[i][j].moveTo(i/10, j/10, i/10);
- cube[i][j].draw();
- }
- }
- popMatrix();
- }
1