Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Shapes3D library's Shape3D fill() method

$
0
0

Hello,

I can't get the Shape3D fill() method to return anything other than white ((R,G,B)=(250.0,250.0,250.0)) when I'm picking a Box.

A slightly adapted version of the Shapes3D example sketch S3D4P_Picking.pde is below.

Am I missing something?

Thanks,

Jim

/**
 Simple program to demonstrate the shape picking feature
 of this library.

 Click on the slowly revolving cubes to change their colour.

 created by Peter Lager
 */

import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;
import peasy.*;

PeasyCam cam;

Box[] box = new Box[20];
Shape3D picked = null;
boolean clicked = false;

float bsize, a, d = 50, c = 120;

void setup() {
  size(400, 400, P3D);
  //cursor(CROSS);
  cam = new PeasyCam(this, 100);
  cam.setMinimumDistance(10);
  cam.setMaximumDistance(500);
  for (int i = 0; i < box.length; i++) {
    bsize = 5 + (int)random(12);
    box[i] = new Box(this, bsize, bsize, bsize);
    box[i].moveTo(random(-d, d), random(-d, d), random(-d, d));
    box[i].fill(randomColor());
    box[i].stroke(color(64, 0, 64));
    box[i].strokeWeight(0.6);
    box[i].drawMode(S3D.SOLID | S3D.WIRE);
    box[i].tag = "Box " + i;
  }
}

void draw() {
  background(128);
  pushMatrix();
  //camera(c * sin(a), 10, c * cos(a), 0, 0, 0, 0, 1, 0);
  if (clicked) {
   clicked = false;
   picked = Shape3D.pickShape(this, mouseX, mouseY);
   println("picked: " + picked);
     if (picked != null) {
       picked.fill(randomColor());
       int pickedFillColour = picked.fill();
       println("Picked colour: (R,G,B)=(" + red(pickedFillColour) + ", " + green(pickedFillColour) + ", " + blue(pickedFillColour) + ")");
    }
  }
  for (int i = 0; i < box.length; i++)
    box[i].draw();
  popMatrix();
  a += 0.002;
}

void mouseClicked() {
  clicked = true;
}

int randomColor() {
  return color(random(100, 220), random(100, 220), random(100, 220));
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles