Hmmm...
If I understand you, you're not trying to create a 2D GUI on a 3D scene, which would be cam.beginHUD(), controlP5.draw(), cam.endHUD();
From what I gather, you're trying to have the controlP5 control actually floating in 3d space. Not sure you can because I think ControlP5 uses the mouse position in 2d space to determine if your over and clicking on the control. You can draw it in 3D space... something like I have below, but your clickable object is still going to be where the control was originally drawn in 2d space. You may want to look at 3D picking and make your own triggers.
- import controlP5.*;
- import peasy.PeasyCam;
- PeasyCam cam;
- ControlP5 controlP5;
- float[] rotations = new float[3];
- int myColorBackground = color(0, 0, 0);
- color[] col = new color[] {
- color(100), color(150), color(200), color(250)
- };
- void setup() {
- size(400, 400, P3D);
- frameRate(30);
- cam = new PeasyCam(this, width);
- controlP5 = new ControlP5(this);
- controlP5.setAutoDraw(false);
- cam.setResetOnDoubleClick(false);
- // change the trigger event, by default it is PRESSED.
- controlP5.addBang("bang", 0, 0, 120, 40).setTriggerEvent(Bang.RELEASE);
- controlP5.controller("bang").setLabel("changeBackground");
- }
- void draw() {
- background(myColorBackground);
- rotations = cam.getRotations();
- pushMatrix();
- translate(40, 250);
- rotateX(rotations[0]);
- rotateY(rotations[1]);
- rotateZ(rotations[2]);
- controlP5.draw();
- popMatrix();
- }
- public void bang() {
- int theColor = (int)random(255);
- myColorBackground = color(theColor);
- println("### bang(). a bang event. setting background to "+theColor);
- }