// Homework 7
// Name: Chongho Lee
// Section: A
// E-Mail: chonghol@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
PFont f1;
float xPos = 0;
float yPos = 0;
float zPos = 0;
float xAng = 0;
float yAng = 0;
float zAng = 0;
void setup( )
{
size( 500, 500, P3D );
lights( );
f1 = loadFont("f1.vlw");
textFont( f1 );
background( #04075A );
lights( );
lights( );
noStroke( );
}
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:
drawInitial();
// This is called after you have drawn your initial
drawAxis( );
}
void keyPressed()
{
if (key == 'i')
{
zPos += 5;
}
else if (key == 'o')
{
zPos -= 5;
}
else if (key == 'r')
{
xPos -= 5;
}
else if (key == 'l')
{
xPos += 5;
}
else if (key == 'u')
{
yPos += 5;
}
else if (key == 'd')
{
yPos -= 5;
}
else if (key ==' ')
{
xPos = 0;
yPos = 0;
zPos = 0;
xAng = 0;
yAng = 0;
zAng = 0;
}
else if (key == ',')
{
zAng -=5;
}
else if (key == '.')
{
zAng += 5;
}
else if (key == CODED)
{
if (keyCode == LEFT)
{
yAng += 5;
}
if (keyCode == RIGHT)
{
yAng -= 5;
}
if (keyCode == UP)
{
xAng -= 5;
}
if (keyCode == DOWN)
{
xAng += 5;
}
}
}
void drawInitial()
{
// Drawing from the top-end of "C" to the bottom-end (anti-clockwise)
noStroke();
translate(xPos, yPos, zPos);
rotateX(radians(xAng));
rotateY(radians(yAng));
rotateZ(radians(zAng));
pushMatrix();
translate( width*0.35, height*-0.35, -400);
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*0.35, height*-0.35, -400);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*0.15, height*-0.4, -200);
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*0.15, height*-0.4, -200);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*-0.05, height*-0.35, -100 );
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*-0.05, height*-0.35, -100 );
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*-0.2, height*-0.25, -30 );
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*-0.2, height*-0.25, -30);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*-0.3, height*-0.1, 0);
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*-0.3, height*-0.1, 0);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*-0.3, height*0.1, 20);
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*-0.3, height*0.1, 20);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*-0.18, height*0.23, 50);
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*-0.18, height*0.23, 50);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*-0.01, height*0.25, 90);
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*-0.01, height*0.25, 90);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
pushMatrix();
translate( width*0.13, height*0.15, 150);
fill ( #4FD82A, 150);
sphere ( 30 );
popMatrix();
pushMatrix();
translate( width*0.13, height*0.15, 150);
fill ( #FF4C0A, 200);
sphere ( 15 );
popMatrix();
}
void drawAxis( )
{
fill( 255 );
sphere(1);
stroke( 255, 0, 0 );
strokeWeight( 1 );
line( -200, 0, 0, 200, 0, 0);
text( 'W', -200, 0, 0);
text( 'E', 200, 0, 0);
stroke( 0, 255, 0 );
line( 0, -200, 0, 0, 200, 0 );
text( 'N', 0, -200, 0);
text( 'S', 0, 200, 0);
stroke(255, 255, 0 );
line( 0, 0, -200, 0, 0, 200);
text( 'F', 0, 0, 200);
text( 'B', 0, 0, -200);
}