I'm working on a sketch where I'll need to draw a lot. of spheres, but I think I'm missing something about how their coordinates work. In this example I'm trying to draw a line of spheres, equally distant apart on the x-axis. I can draw the spheres starting at 0, between I try to shift them tone centered around the origin, I get strange results.
Main Program
import peasy.*;
ArrayList<Sphere> spheres = new ArrayList<Sphere>();
int r = int(random(0, 256));
int g = int(random(0, 256));
int b = int(random(0, 256));
PeasyCam cam;
void setup ()
{
size(430, 760, P3D);
frameRate(60);
orientation(LANDSCAPE);
for(int i = 0; i < 6; i++){
spheres.add(new Sphere(color(r, g, b), 25, ((i*5) + 75), 0, 0));
}
for(int i = 0; i < 6; i++){
spheres.get(i).shiftx();
}
cam = new PeasyCam(this, 0, 0, 0, 1500);
}
void reset(){
}
void draw ()
{
background(0);
ambientLight(255, 255, 255);
directionalLight(0, 255, 255, 1, -1, 0);
for(int i = 0; i < spheres.size(); i++){
spheres.get(i).update();
}
}
Sphere class
class Sphere {
int size;
color col;
float x;
float y;
float z;
Sphere(color col, int size, float x, float y, float z){
this.size = size;
this.x = x;
this.y = y;
this.z = z;
this.col = col;
println(this.x,this.y, this.z);
}
public void shiftx(){
this.x -= 85;
println(this.x,this.y, this.z);
}
public void update() {
//colorMode(RGB);
fill(col);
sphereDetail(180);
//stroke(255);
noStroke();
translate(this.x,this.y,this.z);
sphere(this.size);
}
}
This is the result when I draw the spheres starting at the origin and increase their x value accordingly.
But this is what happens when I shift every sphere to the left by the same amount. If the are equidistant, and then shifted left (negative on the x axis)by the same amount, why are they suddenly drawn on top of each other?