// Homework 7
// Aileen Craig
// Section A
// aacraig@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;
int rotationAmountX, rotationIncreaseX;
int rotationAmountY, rotationIncreaseY;
int rotationAmountZ, rotationIncreaseZ;
int translateX, translateY, translateZ;
void setup( )
{
size( 500, 500, P3D );
lights( );
f1 = loadFont("f1.vlw");
textFont( f1 );
rotationAmountX = 0;
rotationIncreaseX = 1;
rotationAmountY = 0;
rotationIncreaseY = 1;
rotationAmountZ = 0;
rotationIncreaseZ = 1;
translateX = 0;
translateY = 0;
translateZ = 0;
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:
rotateZ (radians( rotationAmountX));
rotateX (radians( rotationAmountY));
rotateY (radians( rotationAmountZ));
translate( translateX, translateY, translateZ);
// This is called after you have drawn your
drawInitial();
drawAxis( );
}
void keyPressed( )
{
if(key == CODED)
{
if(keyCode == LEFT)
{
rotationAmountX -= rotationIncreaseX;
}
else if(keyCode == RIGHT)
{
rotationAmountX += rotationIncreaseX;
}
else if( keyCode == UP)
{
rotationAmountY +=rotationIncreaseY;
}
else if( keyCode == DOWN)
{
rotationAmountY -= rotationIncreaseY;
}
}
if( keyPressed )
{
if( keyCode == ',')
{
rotationAmountZ -= rotationIncreaseZ;
}
else if (keyCode == '.')
{
rotationAmountZ += rotationIncreaseZ;
}
else if (key == 'r')
{
translateX--;
}
else if (key == 'l')
{
translateX++;
}
else if (key == 'u')
{
translateY--;
}
else if (key == 'd')
{
translateY++;
}
else if(key == 'i')
{
translateZ++;
}
else if(key == 'o')
{
translateZ--;
}
else if(key == ' ')
{
translateX=0;
translateY= 0;
translateZ=0;
rotationAmountX=0;
rotationAmountY=0;
rotationAmountZ=0;
}
}
}
void drawInitial( )
{
lights();
noStroke();
pushMatrix();
translate(-width*.15, height*.1, 0);
fill(#EA0255);
box(width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(width*.12, height*.02, 0);
fill(#FA7735);
box(width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(width*.1, -height*.05, 0);
fill(#F6FA21);
box (width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(width*.07, -height*.12, 0);
fill(#41FA35);
box(width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(0, -height*.18, 0);
fill(#382CF0);
box(width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(-width*.07, -height*.12, 0);
fill(#41FA35);
box(width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(-width*.1, -height*.05, 0);
fill(#F6FA21);
box(width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(-width*.12, height*.02, 0);
fill(#FA7735);
box(width*.08, height*.08, 50 );
popMatrix();
pushMatrix();
translate(width*.15, height*.1, 0);
fill(#EA0255);
box(width*.08, height*.08, 50);
popMatrix();
pushMatrix();
translate(0, 0, 0);
fill(#CC27D8);
box(width*.2,height*.05,20);
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);
}