Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update version_final.pde
  • Loading branch information
juw15008 committed Dec 16, 2015
1 parent f39e414 commit b30f604
Showing 1 changed file with 223 additions and 51 deletions.
274 changes: 223 additions & 51 deletions version_final.pde
Expand Up @@ -38,10 +38,22 @@ float vScaler = 0.00;
float vRotateX = 1.18;
float vRotateY = 0.00;
float vRotateZ = 1.25;
//float vRotateX = 0;
//float vRotateY = phi;
//float zRotateZ = the;
int rColor = 128;
int bColor = 128;
int gColor = 128;

// define variables for functionBox
int functionBoxResult = -1;
float zVariable = 0.0;
float xVariable = 0.0;
float yVariable = 0.0;
Textarea xv;
Textarea yv;
Textarea zv;

void setup() {
size(1000, 681, P3D);
noStroke();
Expand All @@ -68,45 +80,56 @@ void draw() {
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);
}
if (functionBoxResult == -1){
//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);
controlCamera();
moveCoords();
scalerCoords();
smooth();
stroke(255);
rotateCoords();
noFill();

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));
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();
}
popMatrix();
//pressedEnter();


//getPressedPoints( mouseX-width/2, mouseY-width/2, map (mouseY-width/2, -height/2, height/2, -height/2, height/2),
//mouseX, mouseY, map (mouseY, -height/2, height/2, -height/2, height/2), color (2, 0, 255));
getPressedPoints( width/2, height/2, 0,
mouseX, mouseY, map (mouseY, -height/2, height/2, -height/2, height/2), color (2, 0, 255));
//popMatrix();
}

void createBox() {
Expand Down Expand Up @@ -272,6 +295,56 @@ void createBox() {
functionBox.setBackgroundColor(color(0,100));
functionBox.setBarHeight(14);

Button b3 = gui.addButton("controlFixed", 0, 65, 20, 80, 24);
b3.moveTo(functionBox);
b3.setColorBackground(color(40));
b3.setColorActive(color(20));
b3.setColorActive(color(20));
b3.setBroadcast(false);
b3.setValue(0);
b3.setBroadcast(true);
b3.setCaptionLabel("FixedCoords");

Button b4 = gui.addButton("controlFree", 0, 155, 20, 80, 24);
b4.moveTo(functionBox);
b4.setColorBackground(color(40));
b4.setColorActive(color(20));
b4.setColorActive(color(20));
b4.setBroadcast(false);
b4.setValue(-1);
b4.setBroadcast(true);
b4.setCaptionLabel("FreeCoords");

xv = gui.addTextarea("outputX");
xv.setPosition(20, 60);
xv.setSize(200, 20);
xv.moveTo(functionBox);
xv.setFont(createFont("arial",12));
xv.setLineHeight(14);
xv.setColor(color(128));
xv.setColorBackground(color(255, 100));
xv.setColorForeground(color(255, 100));

yv = gui.addTextarea("outputY");
yv.setPosition(20, 100);
yv.setSize(200, 20);
yv.moveTo(functionBox);
yv.setFont(createFont("arial",12));
yv.setLineHeight(14);
yv.setColor(color(128));
yv.setColorBackground(color(255, 100));
yv.setColorForeground(color(255, 100));

zv = gui.addTextarea("outputZ");
zv.setPosition(20, 140);
zv.setSize(200, 20);
zv.moveTo(functionBox);
zv.setFont(createFont("arial",12));
zv.setLineHeight(14);
zv.setColor(color(128));
zv.setColorBackground(color(255, 100));
zv.setColorForeground(color(255, 100));

// create a new accordion
// add g1, g2, and g3 to the accordion.
accordion = gui.addAccordion("acc")
Expand Down Expand Up @@ -409,6 +482,9 @@ void rotateCoords() {
rotateX(x);
rotateY(y);
rotateZ(z);
//rotateX(0);
//rotateY(phi);
//rotateZ(the);
}

void controlBox(int theValue) {
Expand Down Expand Up @@ -448,23 +524,119 @@ void controlBackgroundColor() {
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();
xVariable = mouseX;
yVariable = mouseY;
pointSets(xVariable, yVariable, zVariable);
xValue.append(xVariable);
yValue.append(yVariable);
zValue.append(zVariable);
}
}
}

void controlFixed(int theValue) {
functionBoxResult = theValue;
}

void controlFree(int theValue) {
functionBoxResult = theValue;
}

void controlCamera() {
if (functionBoxResult == -1)
{
camera(mouseX, mouseY, (height/2) / tan(PI/5), width/2, height/2, 0, 0, 1, 0);
}
}

// main function to realize transforming the mouse position to 3D coordinates
void getPressedPoints(float x1, float y1, float z1, float x2, float y2, float z2, color strokeColour)
{
PVector p1 = new PVector(x1, y1, z1);
PVector p2 = new PVector(x2, y2, z2);
PVector v1 = new PVector(x2-x1, y2-y1, z2-z1);
float rho = sqrt(pow(v1.x, 2)+pow(v1.y, 2)+pow(v1.z, 2));
float phi = acos(v1.z/rho);
float the = atan2(v1.y, v1.x);
v1.mult(0.5);
pushMatrix();
translate(x1, y1, z1);
translate(v1.x, v1.y, v1.z);
rotateZ(the);
rotateY(phi);
noStroke();
fill(strokeColour);

getPoints(v1.x, v1.y, v1.z);
xVariable = v1.x;
yVariable = v1.y;
zVariable = v1.z;
output();
popMatrix();
}

// get points by mouse press
void getPoints(float x, float y, float z) {
if(mousePressed) {
functionBoxResult = 0;
noCursor();
stroke(255);
mousePointSets(x, y, z);
println(xVariable);
}
else
{
functionBoxResult = -1;
cursor();
}
}

// output the x, y, z value in the textfield of functionbox
void output() {
xv.setText(str(xVariable));
yv.setText(str(yVariable));
zv.setText(str(-zVariable));
}

// draw the points by mouse pressed
void mousePointSets(float x, float y, float z) {
pushMatrix();
translate(x, y, z);
noFill();
stroke(255);
sphere(2.5);
popMatrix();
stroke(100);
}

/*
void drawCoordsSystem() {
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);
}
*/

0 comments on commit b30f604

Please sign in to comment.