Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
FinalProject/version_final.pde
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
470 lines (405 sloc)
11.8 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import controlP5.*; | |
import processing.opengl.*; | |
// define float lists to store value of x, y, z | |
FloatList xValue = new FloatList(); | |
FloatList yValue = new FloatList(); | |
FloatList zValue = new FloatList(); | |
float[] xCoordsValue = new float[100]; | |
float[] yCoordsValue = new float[100]; | |
float[] zCoordsValue = new float[100]; | |
// define Strings to store the input for x, y, z | |
String xString; | |
String yString; | |
String zString; | |
// define String to store the iostream of x, y, z | |
String pointSet = "X-Value Y-Value Z-Value"; | |
// define ControlP5 object and other corressponding object | |
ControlP5 gui; | |
ControlGroup messageBox; | |
ControlGroup ajustmentBox; | |
ControlGroup functionBox; | |
Button control; | |
Textarea txt; | |
Accordion accordion; | |
// define other variables | |
int messageBoxResult = -1; // hide or show | |
// define varibles for adjustmentBox | |
int aRevert = -1; // revert value for ajustmentBox | |
float vSidesway = 0.00; | |
float vShift = 0.00; | |
float vScaler = 0.00; | |
float vRotateX = 1.18; | |
float vRotateY = 0.00; | |
float vRotateZ = 1.25; | |
int rColor = 128; | |
int bColor = 128; | |
int gColor = 128; | |
void setup() { | |
size(1000, 681, P3D); | |
noStroke(); | |
// create GUI | |
gui = new ControlP5(this); | |
gui.setFont(createFont("helvetica", 10)); | |
//revertAjustment(); | |
createBox(); | |
control = gui.addButton("controlBox", 1, 20, 20, 100, 20); | |
control.setLabel("HIDE"); | |
} | |
void draw() { | |
hint(ENABLE_DEPTH_TEST); | |
pushMatrix(); | |
if(messageBox.isVisible()) { | |
controlBackgroundColor(); | |
} else { | |
background(0); | |
fill(255); | |
} | |
popMatrix(); | |
hint(DISABLE_DEPTH_TEST); | |
//Drawing the coordinate system and points by the 3D point sets | |
pushMatrix(); | |
camera(mouseX, mouseY, (height/2) / tan(PI/5), width/2, height/2, 0, 0, 1, 0); | |
moveCoords(); | |
scalerCoords(); | |
smooth(); | |
stroke(255); | |
rotateCoords(); | |
noFill(); | |
for (int i=0; i<500; i += 20){ | |
stroke(96); | |
line(i, 0, 0, i, 0, 500); | |
line(0, i, 0, 0, i, 500); | |
line(0, 0, i, 0, 500, i); | |
line(i, 0, 0, i, 500, 0); | |
line(0, 0, i, 500, 0, i); | |
line(0, i, 0, 500, i, 0); | |
} | |
strokeWeight(1); | |
//z-coordinate: red | |
stroke(255, 0, 0); | |
line(0, 0, -500, 0, 0, 500); | |
arrow(0, 0, 500); | |
//y-coordinate: green | |
stroke(0, 102, 0); | |
line(0, -500, 0, 0, 500, 0); | |
arrow(0, 500, 0); | |
//x-coordinate: blue | |
stroke(0, 76, 153); | |
line(-500, 0, 0, 500, 0, 0); | |
arrow(500, 0, 0); | |
for (int i=0; i<xValue.size(); i++) | |
{ | |
pointSets(xValue.get(i), yValue.get(i), zValue.get(i)); | |
} | |
popMatrix(); | |
} | |
void createBox() { | |
// group messageBox | |
// create a group to store the messageBox elements | |
messageBox = gui.addGroup("messageBox"); | |
messageBox.setBackgroundHeight(400); | |
messageBox.setBackgroundColor(color(0,100)); | |
messageBox.setBarHeight(14); | |
// add a TextLable to the messageBox. | |
Textlabel l = gui.addTextlabel("messageBoxLabel", "Entering 3D point sets.", 20, 20); | |
l.moveTo(messageBox); | |
// add a textfield-controller with name-id input x-value | |
Textfield x = gui.addTextfield("inputX", 20, 36, 260, 20); | |
x.moveTo(messageBox); | |
x.setColorForeground(color(20)); | |
x.setColorBackground(color(20)); | |
x.setColorActive(color(20)); | |
x.setCaptionLabel("Input X-coordinate Value"); | |
// add a textfield-controller with name-id input y-value | |
Textfield y = gui.addTextfield("inputY", 20, 76, 260, 20); | |
y.moveTo(messageBox); | |
y.setColorForeground(color(20)); | |
y.setColorBackground(color(20)); | |
y.setColorActive(color(20)); | |
y.setCaptionLabel("Input Y-coordinate Value"); | |
// add a textfield-controller with name-id input z-value | |
Textfield z = gui.addTextfield("inputZ", 20, 116, 260, 20); | |
z.moveTo(messageBox); | |
z.setColorForeground(color(20)); | |
z.setColorBackground(color(20)); | |
z.setColorActive(color(20)); | |
z.setCaptionLabel("Input Z-coordinate Value"); | |
// add the Confirm button to the messageBox. | |
Button b1 = gui.addButton("buttonConfirm",0,65,160,80,24); | |
b1.moveTo(messageBox); | |
b1.setColorBackground(color(40)); | |
b1.setColorActive(color(20)); | |
b1.setBroadcast(false); | |
b1.setValue(1); | |
b1.setBroadcast(true); | |
b1.setCaptionLabel("Confirm"); | |
// add the Cancel button to the messageBox. | |
Button b2 = gui.addButton("buttonCancel", 0, 155, 160, 80, 24); | |
b2.moveTo(messageBox); | |
b2.setBroadcast(false); | |
b2.setValue(0); | |
b2.setBroadcast(true); | |
b2.setCaptionLabel("Cancel"); | |
b2.setColorBackground(color(40)); | |
b2.setColorActive(color(20)); | |
// add the text area to show the point set of inputting | |
txt = gui.addTextarea("showPointSets"); | |
txt.moveTo(messageBox); | |
txt.setPosition(20, 200); | |
txt.setSize(260, 100); | |
txt.setFont(createFont("arial",12)); | |
txt.setLineHeight(14); | |
txt.setColor(color(128)); | |
txt.setColorBackground(color(255, 100)); | |
txt.setColorForeground(color(255, 100)); | |
// group ajustmentBox | |
// create a group to store the messageBox elements | |
ajustmentBox = gui.addGroup("ajustmentBox"); | |
ajustmentBox.setBackgroundHeight(300); | |
ajustmentBox.setBackgroundColor(color(0,100)); | |
ajustmentBox.setBarHeight(14); | |
// create slider to control the sidesway of coordinate system | |
Slider s1 = gui.addSlider("sidesway"); | |
s1.moveTo(ajustmentBox); | |
s1.setPosition(20, 20); | |
s1.setSize(100, 20); | |
s1.setRange(-300, 300); | |
s1.setValue(vSidesway); | |
// create slider to control the shift of coordinate system | |
Slider s2 = gui.addSlider("shift"); | |
s2.moveTo(ajustmentBox); | |
s2.setPosition(20, 50); | |
s2.setSize(100, 20); | |
s2.setRange(-200, 200); | |
s2.setValue(0); | |
// create slider to control the scaler of coordinate system | |
Slider s3 = gui.addSlider("scaler"); | |
s3.moveTo(ajustmentBox); | |
s3.setPosition(20, 80); | |
s3.setSize(100, 20); | |
s3.setRange(0.1, 2); | |
s3.setValue(1); | |
// create slider to control the rotate of x-axis | |
Slider s4 = gui.addSlider("rotateX"); | |
s4.moveTo(ajustmentBox); | |
s4.setPosition(20, 110); | |
s4.setSize(100, 20); | |
s4.setRange(-PI, PI); | |
s4.setValue(1.19); | |
// create slider to control the rotate of y-axis | |
Slider s5 = gui.addSlider("rotateY"); | |
s5.moveTo(ajustmentBox); | |
s5.setPosition(20, 140); | |
s5.setSize(100, 20); | |
s5.setRange(-PI, PI); | |
s5.setValue(0); | |
// create slider to control the rotate of z-axis | |
Slider s6 = gui.addSlider("rotateZ"); | |
s6.moveTo(ajustmentBox); | |
s6.setPosition(20, 170); | |
s6.setSize(100, 20); | |
s6.setRange(-PI, PI); | |
s6.setValue(1.19); | |
// create slider to control the value of R-color | |
Slider s7 = gui.addSlider("R-Value"); | |
s7.moveTo(ajustmentBox); | |
s7.setPosition(20, 200); | |
s7.setSize(100, 20); | |
s7.setRange(0, 255); | |
s7.setValue(rColor); | |
// create slider to control the value of B-color | |
Slider s8 = gui.addSlider("B-Value"); | |
s8.moveTo(ajustmentBox); | |
s8.setPosition(20, 230); | |
s8.setSize(100, 20); | |
s8.setRange(0, 255); | |
s8.setValue(bColor); | |
// create slider to control the value of G-color | |
Slider s9 = gui.addSlider("G-Value"); | |
s9.moveTo(ajustmentBox); | |
s9.setPosition(20, 260); | |
s9.setSize(100, 20); | |
s9.setRange(0, 255); | |
s9.setValue(gColor); | |
/* | |
Button b5 = gui.addButton("controlRevertA",0,65,290,80,24); | |
b5.moveTo(ajustmentBox); | |
b5.setColorBackground(color(40)); | |
b5.setColorActive(color(20)); | |
b5.setBroadcast(false); | |
b5.setValue(1); | |
b5.setBroadcast(true); | |
b5.setCaptionLabel("Revert"); | |
*/ | |
// group functionBox | |
// create a group to store the messageBox elements | |
functionBox = gui.addGroup("functionBox"); | |
functionBox.setBackgroundHeight(200); | |
functionBox.setBackgroundColor(color(0,100)); | |
functionBox.setBarHeight(14); | |
// create a new accordion | |
// add g1, g2, and g3 to the accordion. | |
accordion = gui.addAccordion("acc") | |
.setPosition(20,60) | |
.setWidth(300) | |
.addItem(messageBox) | |
.addItem(ajustmentBox) | |
.addItem(functionBox) | |
; | |
// use Accordion.MULTI to allow multiple group | |
// to be open at a time. | |
accordion.setCollapseMode(Accordion.MULTI); | |
// when in SINGLE mode, only 1 accordion | |
// group can be open at a time. | |
accordion.setCollapseMode(Accordion.SINGLE); | |
} | |
void inputX(String theString) { | |
messageBox.hide(); | |
} | |
void inputY(String theString) { | |
messageBox.hide(); | |
} | |
void inputZ(String theString) { | |
messageBox.hide(); | |
} | |
void buttonConfirm(int theValue) { | |
xString = ((Textfield)gui.getController("inputX")).getText(); | |
yString = ((Textfield)gui.getController("inputY")).getText(); | |
zString = ((Textfield)gui.getController("inputZ")).getText(); | |
xValue.append(float(xString)); | |
yValue.append(float(yString)); | |
zValue.append(float(zString)); | |
pointSet += '\n' + " " + xString + " " + yString + " " + zString; | |
String temp = '\n' + " " + xString + " " + yString + " " + zString; | |
txt.setText(pointSet); | |
messageBoxResult = theValue; | |
((Textfield)gui.getController("inputX")).clear(); | |
((Textfield)gui.getController("inputY")).clear(); | |
((Textfield)gui.getController("inputZ")).clear(); | |
//messageBox.hide(); | |
//functionBox.hide(); | |
//ajustmentBox.hide(); | |
} | |
void buttonCancel(int theValue) { | |
xValue.clear(); | |
yValue.clear(); | |
zValue.clear(); | |
txt.setText("X-Value Y-Value Z-Value"); | |
messageBoxResult = theValue; | |
//messageBox.hide(); | |
//functionBox.hide(); | |
//ajustmentBox.hide(); | |
} | |
//Drawing 3D points by point sets | |
void pointSets(float x, float y, float z){ | |
pushMatrix(); | |
translate(x, y, z); | |
noFill(); | |
stroke(255); | |
sphere(2.5); | |
popMatrix(); | |
stroke(100); | |
line(x, y, z, x, y, 0); | |
line(x, y, z, x, 0, z); | |
line(x, y, z, 0, y, z); | |
} | |
//Drawing arrows of coordinate system | |
void arrow(int x, int y, int z){ | |
smooth(); | |
strokeCap(ROUND); | |
strokeJoin(ROUND); | |
if(x!=0&&y==0&&z==0){ | |
line(x, 0, 0, x-10, 10, 10); | |
line(x, 0, 0, x-10, -10, 10); | |
line(x, 0, 0, x-10, -10, -10); | |
line(x, 0, 0, x-10, 10, -10); | |
} | |
if(y!=0&&x==0&&z==0){ | |
line(0, y, 0, 10, y-10, 10); | |
line(0, y, 0, -10, y-10, -10); | |
line(0, y, 0, -10, y-10, 10); | |
line(0, y, 0, -10, y-10, 10); | |
} | |
if(z!=0&&y==0&&x==0){ | |
line(0, 0, z, 10, 10, z-10); | |
line(0, 0, z, -10, 10, z-10); | |
line(0, 0, z, -10, -10, z-10); | |
line(0, 0, z, -10, 10, z-10); | |
} | |
} | |
// move the coordinate system by sidesway slider and shift slider | |
void moveCoords() { | |
float s1 = gui.getController("sidesway").getValue(); | |
float s2 = gui.getController("shift").getValue(); | |
if (s1!=0||s2!=0) | |
{ | |
translate(width/2+s1, height/2+s2, 0); | |
} | |
else | |
{ | |
translate(width/2, height/2, 0); | |
} | |
} | |
// scaler the coordinate system by scaler slider | |
void scalerCoords() { | |
float s = gui.getController("scaler").getValue(); | |
float a = s/2; | |
scale(a); | |
} | |
void rotateCoords() { | |
float x = gui.getController("rotateX").getValue(); | |
float y = gui.getController("rotateY").getValue(); | |
float z = gui.getController("rotateZ").getValue(); | |
rotateX(x); | |
rotateY(y); | |
rotateZ(z); | |
} | |
void controlBox(int theValue) { | |
if(messageBox.isVisible()) { | |
messageBox.hide(); | |
functionBox.hide(); | |
ajustmentBox.hide(); | |
control.setLabel("SHOW"); | |
} else { | |
messageBox.show(); | |
functionBox.show(); | |
ajustmentBox.show(); | |
control.setLabel("Hide"); | |
} | |
} | |
void controlRevertA(int theValue) { | |
aRevert = theValue; | |
} | |
void revertAjustment() { | |
if(aRevert==1) | |
{ | |
vSidesway = 0.0; | |
aRevert = -1; | |
} | |
} | |
void controlBackgroundColor() { | |
float r = gui.getController("R-Value").getValue(); | |
float b = gui.getController("B-Value").getValue(); | |
float g = gui.getController("G-Value").getValue(); | |
rColor = int(r); | |
bColor = int(b); | |
gColor = int(g); | |
background(rColor, bColor, gColor); | |
} | |
/* | |
void controlShape(FloatList x, FloatList y, FloatList z) { | |
beginShape(); | |
for(int i = 0; i<=x.size(); i++) | |
for(int j = 0; j<=y.size(); j++) | |
for(int k = 0; k<=z.size(); k++) | |
endShape(); | |
} | |
*/ | |
void pressedEnter() { | |
if(mousePressed==true) | |
{ | |
xValue.append(mouseX); | |
yValue.append(mouseY); | |
//zValue.append(); | |
} | |
} |