Following on from my topic about selecting and moving 2D primitives, i am now looking for guidance as to how i can achieve this with 3D primitives. There are three items id like assistance with in this script:
(A) - How can i place ControlP5 Sliders that dont orbit with Peasycam (have had a go at this however it will not work) --SOLVED–
(B) - How can i select individual or grouped 3d primitives and relocate them on the canvas using the mouse function
( C ) - If i must sacrifice Peasycam to allow item “B” to work, then that is okay, but if there is a way i can toggle peasycam on and off with a ControlP5 Button that would be most preferable. --SOLVED–
Thanks for your help!
// LIBRARIES
import controlP5.*;
import peasy.*;
// CONSTANTS
final int NONE = -1;
// VARIABLES
int selected=NONE; // which column is selected?
float [] posColorWheel; // ColorWheel properties
int widthColorWheel;
int heightColorWheel;
//OBJECTS in an array
GColumn[] myGColumns = new GColumn[7];
GWindow[] myGWindows = new GWindow[6];
GBeam[] myGBeams = new GBeam[6];
TBeam[] myTBeams = new TBeam[1];
//LIBRARY VARIABLES
ControlP5 cp5;
PeasyCam cam;
//SETUP
void setup() {
size(1400, 1000, P3D);
strokeCap(ROUND);
frameRate(10);
//PEASYCAM SETUP
cam = new PeasyCam(this, 700, 500, 000, 850);
cam.setMinimumDistance(50);
cam.setMaximumDistance(2000);
//CONTROLP5 SETUP
cp5 = new ControlP5( this );
cp5.addColorWheel ("colour", 1200, 800, 100 ).setRGB(color(128, 0, 255));
//
posColorWheel = cp5.get(ColorWheel.class, "colour").getPosition();
printArray(posColorWheel);
widthColorWheel = cp5.get(ColorWheel.class, "colour").getWidth();
heightColorWheel = cp5.get(ColorWheel.class, "colour").getHeight();
//cp5.setAutoDraw(false); //When this is enabled, the slider disappears
//INITIALISE COMPONENT VARIABLES
//GCOLUMNS
for (int i=0; i<myGColumns.length; i++) {
myGColumns[i] = new GColumn( 157*i + 50, -30, i);
}
//GWINDOWS
for (int i=0; i<myGWindows.length; i++) {
myGWindows[i] = new GWindow( 157*i + 50, -30, i);
}
//GBEAMS
for (int i=0; i<myGBeams.length; i++) {
myGBeams[i] = new GBeam( 157*i + 50, -30, i);
}
//GBEAMS
for (int i=0; i<myTBeams.length; i++) {
myTBeams[i] = new TBeam( 157*i + 50, -30, i);
}//for
}//func
//DRAW FUNCTIONS
void draw() {
background (234,234,234);
//PeasyCam wont move when mouse is using controlP5
if (cp5.getWindow(this).isMouseOver()) {
cam.setActive(false);
} else {
cam.setActive(true);
}
//GCOLUMN DISPLAY
for (GColumn myGC : myGColumns) {
myGC.Display();
}
//GWINDOW DISPLAY
for (GWindow myGW : myGWindows) {
myGW.Display1();
}
//GBEAM DISPLAY
for (GBeam myGB : myGBeams) {
myGB.Display2();
}
//TBEAM DISPLAY
for (TBeam myTB : myTBeams) {
myTB.Display3();
}//for
}//func
//------------------------------------------------------------
void mousePressed() {
// is mouse over color wheel?
if (overColorWheel())
return; // leave here
// reset
selected=NONE;
// search selected
int i=0;
for (GColumn myGC : myGColumns) {
if (myGC.over()) {
selected = i;
return;
}
i++;
}//for
}//func
boolean overColorWheel() {
// is mouse over color wheel?
return mouseX>posColorWheel[0] &&
mouseX<posColorWheel[0]+widthColorWheel &&
mouseY>posColorWheel[1] &&
mouseY<posColorWheel[1]+ heightColorWheel ;
}//method
void controlEvent(ControlEvent theEvent) {
if (theEvent.isController()) {
// changing the value
if (theEvent.getController().getName()=="colour") {
//color c = cp5.getController("c").getRGB();
color c = cp5.get(ColorWheel.class, "colour").getRGB();
if (selected!=NONE) {
myGColumns[selected].c = c;
myGBeams[selected].c = c;
}//if
}
}
}
// (NEW TAB "GBeam") ================================
//CLASS NAME
class GBeam {
//VARIABLES
color c;
int x;
int y;
int id; // its ID
//Window#1
int beamAX;
int beamAY;
int beamAW;
int beamAH;
int beamAD;
//Window#2
int beamBX;
int beamBY;
int beamBW;
int beamBH;
int beamBD;
//Window#3
int beamCX;
int beamCY;
int beamCW;
int beamCH;
int beamCD;
//Window#4
int beamDX;
int beamDY;
int beamDW;
int beamDH;
int beamDD;
//Window#5
int beamEX;
int beamEY;
int beamEW;
int beamEH;
int beamED;
//Window#6
int beamFX;
int beamFY;
int beamFW;
int beamFH;
int beamFD;
//
//DEFINE CONSTRUCTORS
GBeam( int x_, int y_,
int id_) {
// color
c = color(172, 133, 175);
// pos
x = x_;
y = y_;
id=id_;
//Row#1
//AA
beamAX = 106; //translate x location
beamAY = 996; //translate y location
beamAW = 120; //box A width
beamAH = 7; //box A height
beamAD = 5; //box A depth
//BB
beamBX = 106; //translate x location
beamBY = 972; //translate y location
beamBW = 120; //box A width
beamBH = 7; //box A height
beamBD = 5; //box A depth
//CC
beamCX = 106; //translate x location
beamCY = 965; //translate y location
beamCW = 120; //box A width
beamCH = 3; //box A height
beamCD = 5; //box A depth
//DD
beamDX = 106; //translate x location
beamDY = 960; //translate y location
beamDW = 120; //box A width
beamDH = 5; //box A height
beamDD = 5; //box A depth
//EE
beamEX = 106; //translate x location
beamEY = 762; //translate y location
beamEW = 120; //box A width
beamEH = 8; //box A height
beamED = 5; //box A depth
//FF
beamFX = 106; //translate x location
beamFY = 728; //translate y location
beamFW = 120; //box A width
beamFH = 8; //box A height
beamFD = 5; //box A depth
}
//DEFINE FUNCTIONS
void Display2() {
pushMatrix();
translate(x, y);
fill(c);
if (selected==id)
stroke(240,0,0);
else
stroke(232,232,232,100);
pushMatrix();
translate(beamAX, beamAY);
box(beamAW, beamAH, beamAD);
popMatrix();
pushMatrix();
translate(beamBX, beamBY);
box(beamBW, beamBH, beamBD);
popMatrix();
pushMatrix();
translate(beamCX, beamCY);
box(beamCW, beamCH, beamCD);
popMatrix();
pushMatrix();
translate(beamDX, beamDY);
box(beamDW, beamDH, beamDD);
popMatrix();
pushMatrix();
translate(beamEX, beamEY);
box(beamEW, beamEH, beamED);
popMatrix();
pushMatrix();
translate(beamFX, beamFY);
box(beamFW, beamFH, beamFD);
popMatrix();
popMatrix();
}//method
boolean over() {
return mouseX>x-beamCX-beamCW/2 &&
mouseX<x+beamCX+beamCW/2 &&
mouseY>y+beamCY-beamCH/2 &&
mouseY<y+beamCY+beamCH/2 ;
}//method
//
}//class
//
// (NEW TAB "GCOLUMN") ================================
//CLASS NAME
class GColumn {
//VARIABLES
color c;
int x;
int y;
int id; // its ID
int boxAX;
int boxAY;
int boxAW;
int boxAH;
int boxAD;
int boxBX;
int boxBY;
int boxBW;
int boxBH;
int boxBD;
int spheAX;
int spheAY;
int spheR;
int spheBX;
int spheBY;
//DEFINE CONSTRUCTORS
GColumn( int x_, int y_,
int id_) {
// color
c = color(172, 133, 175);
// pos
x = x_;
y = y_;
id=id_;
boxAX = 25; //translate x location
boxAY = 981; //translate y location
boxAW = 56; //box A width
boxAH = 36; //box A height
boxAD = 56; //box A depth
boxBX = 26;
boxBY = 770;
boxBW = 36;
boxBH = 370;
boxBD = 36;
spheAX = 26;
spheAY = 963;
spheR = 25;
spheBX = 26;
spheBY = 579;
}
//DEFINE FUNCTIONS
void Display() {
pushMatrix();
translate(x, y);
fill(c);
if (selected==id)
stroke(240,0,0);
else
stroke(232,232,232,100);
pushMatrix();
translate(boxAX, boxAY);
box(boxAW, boxAH, boxAD);
popMatrix();
pushMatrix();
translate(boxBX, boxBY);
box(boxBW, boxBH, boxBD);
popMatrix();
pushMatrix();
translate(spheAX, spheAY);
sphere(spheR);
popMatrix();
pushMatrix();
translate(spheBX, spheBY);
sphere(spheR);
popMatrix();
popMatrix();
}//method
boolean over() {
return mouseX>x-boxBX-boxBW/2 &&
mouseX<x+boxBX+boxBW/2 &&
mouseY>y+boxBY-boxBH/2 &&
mouseY<y+boxBY+boxBH/2 ;
}//method
//
}//class
//
// (NEW TAB "GWindow") ================================
//CLASS NAME
class GWindow {
//VARIABLES
color c;
int x;
int y;
int id; // its ID
//Window#1
int winAX;
int winAY;
int winAW;
int winAH;
int winAD;
//Window#2
int winBX;
int winBY;
int winBW;
int winBH;
int winBD;
//Window#3
int winCX;
int winCY;
int winCW;
int winCH;
int winCD;
//Window#4
int winDX;
int winDY;
int winDW;
int winDH;
int winDD;
//Window#5
int winEX;
int winEY;
int winEW;
int winEH;
int winED;
//Window#6
int winFX;
int winFY;
int winFW;
int winFH;
int winFD;
//Window#7
int winGX;
int winGY;
int winGW;
int winGH;
int winGD;
//Window#8
int winHX;
int winHY;
int winHW;
int winHH;
int winHD;
//Window#9
int winIX;
int winIY;
int winIW;
int winIH;
int winID;
//Window#10
int winJX;
int winJY;
int winJW;
int winJH;
int winJD;
//
//DEFINE CONSTRUCTORS
GWindow( int x_, int y_,
int id_) {
// color
c = color(random(255), random(100), 0);
// pos
x = x_;
y = y_;
id=id_;
//Row#1
//AA
winAX = 73; //translate x location
winAY = 985; //translate y location
winAW = 25; //box A width
winAH = 15; //box A height
winAD = 5; //box A depth
//BB
winBX = 106; //translate x location
winBY = 985; //translate y location
winBW = 25; //box A width
winBH = 15; //box A height
winBD = 5; //box A depth
//CC
winCX = 139; //translate x location
winCY = 985; //translate y location
winCW = 25; //box A width
winCH = 15; //box A height
winCD = 5; //box A depth
//Row#2
//DD
winDX = 75; //translate x location
winDY = 862; //translate y location
winDW = 55; //box A width
winDH = 194; //box A height
winDD = 5; //box A depth
//EE
winEX = 136; //translate x location
winEY = 862; //translate y location
winEW = 55; //box A width
winEH = 194; //box A height
winED = 5; //box A depth
//Row#3
//FF
winFX = 59; //translate x location
winFY = 745; //translate y location
winFW = 19; //box A width
winFH = 19; //box A height
winFD = 5; //box A depth
//GG
winGX = 106; //translate x location
winGY = 745; //translate y location
winGW = 65; //box A width
winGH = 19; //box A height
winGD = 5; //box A depth
//HH
winHX = 153; //translate x location
winHY = 745; //translate y location
winHW = 19; //box A width
winHH = 19; //box A height
winHD = 5; //box A depth
//Row#4
//II
winIX = 106; //translate x location
winIY = 667; //translate y location
winIW = 107; //box A width
winIH = 92; //box A height
winID = 5; //box A depth
//JJ
winJX = 106; //translate x location
winJY = 598; //translate y location
winJW = 107; //box A width
winJH = 23; //box A height
winJD = 5; //box A depth
}
//DEFINE FUNCTIONS
void Display1() {
pushMatrix();
translate(x, y);
fill(199,212,214,100);
//if (selected==id)
//stroke(240,0,0);
//else
stroke(232,232,232,100);
pushMatrix();
translate(winAX, winAY);
box(winAW, winAH, winAD);
popMatrix();
pushMatrix();
translate(winBX, winBY);
box(winBW, winBH, winBD);
popMatrix();
pushMatrix();
translate(winCX, winCY);
box(winCW, winCH, winCD);
popMatrix();
pushMatrix();
translate(winDX, winDY);
box(winDW, winDH, winDD);
popMatrix();
pushMatrix();
translate(winEX, winEY);
box(winEW, winEH, winED);
popMatrix();
pushMatrix();
translate(winFX, winFY);
box(winFW, winFH, winFD);
popMatrix();
pushMatrix();
translate(winGX, winGY);
box(winGW, winGH, winGD);
popMatrix();
pushMatrix();
translate(winHX, winHY);
box(winHW, winHH, winHD);
popMatrix();
pushMatrix();
translate(winIX, winIY);
box(winIW, winIH, winID);
popMatrix();
pushMatrix();
translate(winJX, winJY);
box(winJW, winJH, winJD);
popMatrix();
popMatrix();
}//method
boolean over() {
return mouseX>x-winGX-winGW/2 &&
mouseX<x+winGX+winGW/2 &&
mouseY>y+winGY-winGH/2 &&
mouseY<y+winGY+winGH/2 ;
}//method
//
}//class
//
// (NEW TAB "TBeam") ================================
//CLASS NAME
class TBeam {
//VARIABLES
color c;
int x;
int y;
int id; // its ID
//Window#1
int tbeamAX;
int tbeamAY;
int tbeamAW;
int tbeamAH;
int tbeamAD;
//Window#2
int tbeamBX;
int tbeamBY;
int tbeamBW;
int tbeamBH;
int tbeamBD;
//Window#3
int tbeamCX;
int tbeamCY;
int tbeamCW;
int tbeamCH;
int tbeamCD;
//Window#4
int tbeamDX;
int tbeamDY;
int tbeamDW;
int tbeamDH;
int tbeamDD;
//
//DEFINE CONSTRUCTORS
TBeam( int x_, int y_,
int id_) {
// color
c = color(172, 133, 175);
// pos
x = x_;
y = y_;
id=id_;
//Row#1
//AA
tbeamAX = 500; //translate x location
tbeamAY = 565; //translate y location
tbeamAW = 1000; //box A width
tbeamAH = 28; //box A height
tbeamAD = 56; //box A depth
//BB
tbeamBX = 500; //translate x location
tbeamBY = 551; //translate y location
tbeamBW = 1000; //box A width
tbeamBH = 5; //box A height
tbeamBD = 56; //box A depth
//CC
tbeamCX = 500; //translate x location
tbeamCY = 546; //translate y location
tbeamCW = 1000; //box A width
tbeamCH = 5; //box A height
tbeamCD = 56; //box A depth
//DD
tbeamDX = 500; //translate x location
tbeamDY = 541; //translate y location
tbeamDW = 1000; //box A width
tbeamDH = 5; //box A height
tbeamDD = 56; //box A depth
}
//DEFINE FUNCTIONS
void Display3() {
pushMatrix();
translate(x, y);
fill(c);
if (selected==id)
stroke(240,0,0);
else
stroke(232,232,232,100);
pushMatrix();
translate(tbeamAX, tbeamAY);
box(tbeamAW, tbeamAH, tbeamAD);
popMatrix();
pushMatrix();
translate(tbeamBX, tbeamBY);
box(tbeamBW, tbeamBH, tbeamBD);
popMatrix();
pushMatrix();
translate(tbeamCX, tbeamCY);
box(tbeamCW, tbeamCH, tbeamCD);
popMatrix();
pushMatrix();
translate(tbeamDX, tbeamDY);
box(tbeamDW, tbeamDH, tbeamDD);
popMatrix();
popMatrix();
}//method
boolean over() {
return mouseX>x-tbeamBX-tbeamBW/2 &&
mouseX<x+tbeamBX+tbeamBW/2 &&
mouseY>y+tbeamBY-tbeamBH/2 &&
mouseY<y+tbeamBY+tbeamBH/2 ;
}//method
//
}//class
//