3D Sucks!

As you can tell from this title, I really don’t like 3D programming. It’s bulky and slow and hard to manipulate. But since we had to play with 3D for an assignment, here it is. My original plan was to make an array of orbs that jump when you scroll over them, but I had trouble getting them to move correctly (or rather, at all). So instead I just make them change color based on where you move the mouse. I can’t seem to post the code on OpenProcessing or make a version you can play with on the web, so I’ve embedded a video and included the code below:

Main code:

[code lang="java"]Ball[] balls1;
Ball[] balls2;
Ball[] balls3;
Ball[] balls4;

int r = 30;
int cols = 5;

void setup()
{
  size(600, 400, P3D);
  balls1 = new Ball[cols];
  balls2 = new Ball[cols];
  balls3 = new Ball[cols];
  balls4 = new Ball[cols];
  
  for(int i = 0; i < cols; i++)
  {
    balls1[i] = new Ball(r);
    balls2[i] = new Ball(r);
    balls3[i] = new Ball(r);
    balls4[i] = new Ball(r);
  }
}

void draw()
{
  background(103, 162, 2);
  smooth();
  directionalLight(mouseX, mouseY, 255, -1, 0, 0);
  
  for(int i = 0; i < cols; i++)
  {
    pushMatrix();
    translate(140+(i*80), 2*height/3, 100);
    balls1[i].drawBall();
    balls1[i].spinBall();
    popMatrix();
    
    pushMatrix();
    translate(140+(i*80), 2*height/3, 0);
    balls2[i].drawBall();
    popMatrix();
    
    pushMatrix();
    translate(140+(i*80), 2*height/3, -100);
    balls3[i].drawBall();
    popMatrix();
    
    pushMatrix();
    translate(140+(i*80), 2*height/3, -200);
    balls4[i].drawBall();
    popMatrix();
    
  }
}[/code]

Code for the Ball class:

[code lang="java"]class Ball
{
  int r;
  
  Ball(int _r)
  {
    r = _r;
  }
  
  void drawBall()
  {
    pushMatrix();
    fill(255, 130, 5);
    sphere(r);
    popMatrix();
  }
  
  void spinBall()
  {
    if(keyPressed)
    {
      rotateY(PI);
    } 
  }
}[/code]