Sie sind auf Seite 1von 6

Alex Jablonski amj650 EECS 351-1 Project A: Mixer and pendulum

Users Guide
This project consists of two main elements, a mixer made of several rotating structures on a main rotating cross, and a pendulum, made of several jointed pieces that oscillate at different rates. The mixer has at the end of each of the four arms on the large cross a smaller cross which can rotate at a different rate. Each of these crosses have smaller crosses at the ends of their arms (with an independent rotation speed), and those crosses have alternating small stars and octagons at the ends of their arms (which can all rotate at a speed different from any of the larger parts). The rotation speed of each level in the mixer can be controlled independently. The following key commands control the speed of rotation of each part, from the smallest to largest. To see the changes in speed more quickly, press and hold down the desired speed control. Key 1 ! (Shift + 1) 2 @ (Shift + 2) 3 # (Shift + 3) 4 $ (Shift + 4) Function increase clockwise / decrease counterclockwise rotation speed for octagons and pointed stars decrease clockwise / increase counterclockwise rotation speed for octagons and pointed stars increase clockwise / decrease counterclockwise rotation speed for smallest crosses decrease clockwise / increase counterclockwise rotation speed for smallest crosses increase clockwise / decrease counterclockwise rotation speed for medium crosses decrease clockwise / increase counterclockwise rotation speed for medium crosses increase clockwise / decrease counterclockwise rotation speed for largest cross decrease clockwise / increase counterclockwise rotation speed for largest cross

In addition, the entire mixer can be moved by using the arrow keys (Up, Left, Down, and Right move the mixer up, left, down, and right, respectively). The pendulum consists of a large triangular pendulum, to which is attached another smaller triangular pendulum. At the end of this pendulum is a diamond that likewise oscillates, but that also expands and contracts as it swings back and forth. The pendulum can be moved by clicking and dragging the mouse, or by simply right-clicking in a new location. The main pendulums color can be cycled (between red, yellow, green, cyan, blue, and magenta) by left-clicking anywhere in the viewing window.

Jablonski 2 The program can be paused at any time by pressing p (it is unpaused by simply pressing p again). ESC, q, and the spacebar all allow the user to exit the program. All of this information is also included in the help text, which can be toggled on or off using F1.

Code Guide
All variables and functions are contained within Proj_A.cpp, with associated function declarations in the header file Proj_A.h . Global variables mixerThetas[] controls the angle at which each level of item (stars and octagons, small crosses, medium crosses, large cross) in the mixer is rotated; it contains numMixerAngles elements, which is set to 4. mixerThetaSteps[] controls the rate at which the angles of rotation at each level of the mixer change, and also contains 4 elements. pendulumThetas[] and pendulumThetaSteps[] are similar to mixerThetas[] and mixerThetaSteps[], except that for the pendulum, the angles are restricted to 90, and there are only 3 (instead of 4) values, corresponding with the 3 elements of the pendulum. mixerRed, mixerGreen, and mixerBlue contain the levels of red, green, and blue in the color for the mixer. mixerRedStep, mixerGreenStep, and mixerBlueStep control the rate at which the mixer changes colors. mixerXpos, mixerYpos, pendulumXpos, and pendulumYpos are the x- and y-coordinates of the mixer and pendulum, respectively. These control the values in glTranslated matrices in the myDisplay function. Registered functions myReshape() ensures that the CVV is square, even when the window containing it is not, by defining the viewport as the largest possible inscribed square in the viewing window. It is the registered glutReshapeFunc. myDisplay() is the main loop for the display aspects of the program (the registered glutDisplayFunc). See the commented code for a more in-depth explanation. The basic procedure is to (1) Update color, position, angle, and length variables (all motion variables) (2) Draw the mixer, using the recursivePinwheel function to propagate the pattern down numStarAngles 2 levels (the first level has already been created, and the case when depth = 0 adds an additional level of control that requires angles, namely, the stars and octagons at the ends of the smallest crosses) (3) Draw the pendulum.

Jablonski 3 myKeyboard() contains all non-special key commands described in the User Guide section. myKeySpecial() handles these special key commands. They are registered as the glutKeyboardFunc and as glutSpecialFunc, respectively. myMouseClik() monitors and handles input from mouse buttons and is registered in glutMouseFunc; myMouseMove() handles the input from a click-and-drag input, and is registered as glutMotionFunc. myHidden() controls window visibility, and is registered as the glutVisibilityFunc. runAnimTimer() handles pausing, and is assisted by myTimer(). Drawing functions drawText2D() allows for writing text onto the screen. getDisplayHeight(), getDisplayWidth(), getDisplayXpos(), and getDisplayYpos() each obtain the information that their name implies from the graphics display window. stepColor() increments the colors for the mixer, with bounds checking to ensure that the colors are numbers between 0 and 1, inclusive. draw4PtCross(), draw4PtStar(), drawOctagon(), drawTriangle(), and drawDiamond() all use glVertex2d to create the shapes that their names suggest. drawMixer() takes a desired depth, or number of layers besides the first, large cross and the small terminal rotating pieces on the ends of the smallest cross. Thus, the depth is 2 less than the number of angles used for rotation of the various parts of the mixer. This function begins by moving to the desired starting position, scaling down the coordinate system, drawing a large cross, and then calling the drawPinwheel() function to recursively add the desired number of layers. This recursive function adds small crosses until the desired depth is reached, and then attaches octagons and small pointed stars to the ends of the smallest crosses. drawPendulum() takes care of drawing the pendulum in 3 steps corresponding to the three different pieces of the pendulum.

Jablonski 4

Results

A sample view of the program shortly after it started and then a short while later. No user input has been supplied, but both the mixer and the pendulum have moved, and the mixer has changed color.

The program with the F1 help menu brought up. Besides bringing up this menu, no user input has been supplied.

Jablonski 5

After left-clicking, the large triangle part of the pendulum has turned yellow.

The pendulum was moved by clicking and dragging; since the left mouse button was used to drag the pendulum, the color changed from yellow to green. The mixer was moved using the arrow keys.

Jablonski 6

Here the pendulum was moved by simply right-clicking, so the color did not change. The project met all of the goals of showing a multi-level, recursively generated mixer (with independent speed controls at each level) and a pendulum with three segments, each of which oscillates independently of the others. Key commands and mouse functionality are built in and work as expected to control the speed and location of the mixer and the location and color of the pendulum.

Das könnte Ihnen auch gefallen