I'm trying to create a 3D grid of points in a box using Processing with PeasyCam to visualize the box. To make the grid of points, I'm using a method that I've used successfully in 2D.
import peasy.*;
PeasyCam cam;
void setup()
{
size(1000, 800, P3D);
background(0);
frameRate(60);
cam = new PeasyCam(this, 1200);
cam.lookAt(boxwidth/2, boxheight/2, boxdepth/2);
cam.setMinimumDistance(50);
cam.setMaximumDistance(2000);
//initialize grid of points of interest
float count = 0;
grid_spacingx = grid_width / (Nx-1); //one fewer spacings than points
grid_spacingy = grid_height / (Ny-1);
grid_spacingz = grid_depth / (Nz-1);
for(int i = 0; i<N; i++){
px[i] = (count*grid_spacingx);
count++;
if(count%Nx == 0){
count = 0;
}
}
for(int i = 0; i<N; i++){
py[i] = (count*grid_spacingy);
count++;
if(count%Ny == 0){
count = 0;
}
}
for(int i = 0; i<N; i++){
pz[i] = (count*grid_spacingz);
count++;
if(count%Nz == 0){
count = 0;
}
}
}
int boxwidth = 1000;
int boxheight = 1000;
int boxdepth = 1000;
//size of arrays
int Nx = 26; //number of horizontal points (makes N-1 spacings)
int Ny = 26; //number of vertical points
int Nz = 26; //number of vertical points
int N = Nx * Ny; //total number of points
float grid_width = 1000;
float grid_height = 1000;
float grid_depth = 1000;
float grid_spacingx;
float grid_spacingy;
float grid_spacingz;
//position of point of interest
float[] px = new float[N];
float[] py = new float[N];
float[] pz = new float[N];
void draw()
{
background(0);
colorMode(RGB, 255);
fill(255);
strokeWeight(2);
drawBox();
drawFieldArrows();
}
//******************************************************//
void drawFieldArrows() {
fill(255);
for(int i = 0; i<N; i++){
pushMatrix();
translate(px[i], py[i], pz[i]);
point(0, 0, 0);
popMatrix();
}
}
//******************************************************//
void drawBox() {
stroke(255);
noFill();
line(0, 0, 0, boxwidth, 0, 0);
line(0, 0, 0, 0, boxheight, 0);
line(0, 0, 0, 0, 0, boxdepth);
line(0, 0, boxdepth, boxwidth, 0, boxdepth);
line(0, 0, boxdepth, 0, boxheight, boxdepth);
line(boxwidth, boxheight, boxdepth, boxwidth, boxheight, 0);
line(boxwidth, boxheight, boxdepth, 0, boxheight, boxdepth);
line(boxwidth, boxheight, boxdepth, boxwidth, 0, boxdepth);
line(boxwidth, 0, 0, boxwidth, boxheight, 0);
line(boxwidth, 0, 0, boxwidth, 0, boxdepth);
line(0, boxheight, 0, boxwidth, boxheight, 0);
line(0, boxheight, 0, 0, boxheight, boxdepth);
//fill(135,206,250, 100);
//rect(0, 0, boxwidth, boxheight);
//translate(0, 0, boxdepth);
//rect(0, 0, boxwidth, boxheight);
}
For some reason in 3D, it produces a single diagonal line of points instead of a complete grid. Any insight would be greatly appreciated!
I've copied code that worked perfectly in 2D (x, y only), and I've tried to add in the z dimension, to no avail.