// Homework 7 // Name: Dae Hong Kim // Section: 15-100 D // E-Mail: daek@andrew.cmu.edu // DO NOT ALTER THE COMMENT THAT STARTS ON THE NEXT LINE -- DETAILS IN CLASS /** Lateral Motion Commands


move in ---- [i]
move out --- [o]

move right - [r]
move left -- [l]

move up ---- [u]
move down -- [d]


Rotational Motion Commands


rotate left (y axis) --- [left arrow]
rotate right(y axis) --- [right arrow]

rotate up ( x axis ) --- [up arrow]
rotate down ( x axis ) - [down arrow]

rotate CCW ( z axis ) -- [,]
rotate CW (z axis ) ---- [.]


reset to zero ---------- [space]

*/ // Declare gobal variables here float xCor = 0 ; float yCor = 0; float zCor = 0; float xTheta = 0; float yTheta = 0; float zTheta = 0; PFont f1; void setup( ) { size( 500, 500, P3D ); lights( ); f1 = loadFont("f1.vlw"); textFont( f1 ); lights( ); }// end of setup() void draw( ) { // This moves the (0,0,340) point to the center of the window // Do not remove or alter this line of code translate( width/2, height/2, 0 ); background( #04075A ); // Do your initial translation and rotations here: drawInitials(); // This is called after you have drawn your initial drawAxis( ); }// end of draw() void drawInitials() // draw the 3D inital { float boxSize = width/20; // 3D box size float boxSpace = boxSize*1.2; // space between boxes //println("My initial is H~!"); translate(xCor, yCor, zCor); // nevigate boxes rotateX(radians(xTheta)); rotateY(radians(yTheta)); rotateZ(radians(zTheta)); for(float z = -boxSpace; z <= boxSpace; z += boxSpace) // draw boxes in z cordinates { pushMatrix( ); translate(0, 0, z); fill(random(255), random(255), random(255)); box(boxSize); for(int count=0; count < 4; count++) { translate(boxSpace, 0, 0); fill(random(255), random(255), random(255)); box(boxSize); } pushMatrix(); for(int count=0; count < 4; count++){ translate(0, -boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); for(int count=0; count < 4; count++){ translate(0, boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); pushMatrix(); translate(0, 0, z); for(int count=0; count <4; count++){ translate(-boxSpace, 0, 0); fill(random(255), random(255), random(255)); box(boxSize); } pushMatrix(); for(int count=0; count <4; count++){ translate(0, -boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); for(int count=0; count <4; count++){ translate(0, boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); // back to the original coordinate pushMatrix( ); // save th original coordinate translate(0, -boxSpace, z); fill(random(255), random(255), random(255)); box(boxSize); for(int count=0; count < 3; count++){ translate(boxSpace, 0, 0); fill(random(255), random(255), random(255)); box(boxSize); } for(int count=0; count < 3; count++){ translate(0, -boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); pushMatrix( ); // save th original coordinate translate(0, boxSpace, z); fill(random(255), random(255), random(255)); box(boxSize); for(int count=0; count < 3; count++){ translate(boxSpace, 0, 0); fill(random(255), random(255), random(255)); box(boxSize); } for(int count=0; count < 3; count++){ translate(0, boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); pushMatrix( ); // save th original coordinate translate(0, -boxSpace, z); fill(random(255), random(255), random(255)); box(boxSize); for(int count=0; count < 3; count++){ translate(-boxSpace, 0, 0); fill(random(255), random(255), random(255)); box(boxSize); } for(int count=0; count < 3; count++){ translate(0, -boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); pushMatrix( ); // save the original coordinate translate(0, boxSpace, z); fill(random(255), random(255), random(255)); box(boxSize); for(int count=0; count < 3; count++){ translate(-boxSpace, 0, 0); fill(random(255), random(255), random(255)); box(boxSize); } for(int count=0; count < 3; count++){ translate(0, boxSpace, 0); fill(random(255), random(255), random(255)); box(boxSize); } popMatrix(); } // end of for loop for drawing boxes in z cordinates }// end of drawInitials() void keyPressed() { if (key == CODED) { if (keyCode == UP) { xTheta -= 2; } else if (keyCode == DOWN) { xTheta += 2; } else if (keyCode == LEFT) { yTheta += 2; } else if (keyCode == RIGHT) { yTheta -= 2; } }// end of if(key == CODED) else if(key == 'i') { zCor += 2; } else if(key == 'o') { zCor -= 2; } else if(key == 'r') { xCor -= 2; } else if(key == 'l') { xCor += 2; } else if(key == 'u') { yCor += 2; } else if(key == 'd') { yCor -= 2; } else if (key == '.') { zTheta += 2; } else if (key == ',') { zTheta -= 2; } else if (key == ' ') // press 'SPACE' to reset { xCor = 0 ; yCor = 0; zCor = 0; xTheta = 0; yTheta = 0; zTheta = 0; } }// end of keyPressed() void drawAxis( ) { fill( 255 ); sphere(1); stroke( 255, 0, 0 ); strokeWeight( 1 ); line(-(width*0.4), 0, 0, width*0.4, 0, 0); text( 'W', -(width*0.4), 0, 0); text( 'E', width*0.4, 0, 0); stroke( 0, 255, 0 ); line( 0, -(height*0.4), 0, 0, height*0.4, 0); text( 'N', 0, -(height*0.4), 0); text( 'S', 0, height*0.4, 0); stroke(255, 255, 0 ); line( 0, 0, -200, 0, 0, 200); text( 'F', 0, 0, 200); text( 'B', 0, 0, -200); }// end of drawAxis()