Starting from:
$30

$24

Lab #6: Transformation Hierarchies with OpenGL Solution

Overview




In this lab, you will continue to use the OpenGL package and build off your completed code for Lab #5. Now that you are familiar with OpenGL and can setup the initial 3D projection, you can begin using some of the more powerful features.

In class, we have talked about the power of using transformations in designing, manipulating, and mov-ing 3D models. In this lab, you will use transformations hierarchies to build a street of houses. Additionally, you will use transformation hierarchies to make animation of a car driving down the street, with wheels turning.













User Interface




The user interface should be identical to the one implemented in Lab #5. The same keys should cause the same movements. The only difference is that the H key returns to home position, but it also resets the time (see the Time section).













Scene




In addition to the house model that was provided in Lab #5, you also will be provided with two additional models: a car body model and a tire model. You will need these new models to complete the assignment.




The scene that you need to design for this lab is a street of houses with a car driving down the road. As the car moves, the tires should rotate appropriately. The location of the houses and car do not matter as long as the TAs are able to navigate the street easily and see that you are able to apply both translation and rotation matrices appropriately.










Figure 1: Possible Street Design










1
OpenGL Commands




As you saw in the last lab, we are using a very small subset of the available commands of OpenGL. The focus of this lab is using transformation hierarchies appropriately, so the two main functions you will need to add to your arsenal are glPushMatrix() and glPopMatrix().




glPushMatrix




OpenGL has the ability to keep a stack of matrices that it will apply to drawing operations. As you can imagine, this is extremely helpful to implement a transformation hierarchy. However, because OpenGL is imperative, the order of operations can be confusing.

The glPushMatrix() command must be called before the appropriate transformations are called. These transformations are then applied to the matrix that has been pushed on the stack. Each successive glPushMatrix() call clones the current matrix, places it on top of the stack, then applies the next transformation commands.

Here is some example code to illustrate the point:




g l P u s h M a t r i x ( )
# C o p i e s c u r r e n t m a t r i x , p l a c e s i t on s t a c k
g l T r a n s l a t e f ( 5 0 , 0 , 0 )
# A p p l i e s t r a n s l a t i o n t o c u r r e n t m a t r i x
g l R o t a t e f ( 1 0 , 0 , 1 , 0 )
# A p p l i e s r o t a t i o n t o c u r r e n t m a t r i x
d r a w S o m e t h i n g ( )
#
Draws
w i t h
t r a n s f o r m a t i o n s
o f c u r r e n t
g l P u s h M a t r i x ( )
# C o p i e s c u r r e n t m a t r i x , p l a c e s i t on s t a c k
g l T r a n s l a t e ( 0 , 2 5 , 0 )
# A p p l i e s t r a n s l a t i o n t o c u r r e n t m a t r i x
d r a w S o m e t h i n g ( )
#
Draws
w i t h
t r a n s f o r m a t i o n s
o f c u r r e n t
g l P o p M a t r i x ( )
#
Grabs
t h e
t o p m a t r i x o f t h e
s t a c k and


# s e t s i t t o t h e c u r r e n t m a t r i x .


# D e s t r u c t i v e C a l l





Also, remember that the matrix operations go right to left, so the last transformation called will be the first one applied to the object.




glPopMatrix




The glPopMatrix() command allows you to take transformations off the stack so that you can start from a previous state. Again, keep in mind that OpenGL is imperative, so glPopMatrix() does not return the top matrix on the stack. It simply sets the top matrix of stack to the current matrix. It also deletes that matrix from the stack. Keep this in mind as you design your code.































2
Time




In the previous lab, we had the display update anytime there was a key pressed, which in turn changed what needed to be displayed. However, since there is an animation in this lab (car moving, wheels rotating), you will need to keep track of time and update the display periodically.

The simplest way to do this is using OpenGL’s glutTimerFunc command and place it right before glutMainLoop. You can look up documentation for this function at

http://pyopengl.sourceforge.net/documentation/manual-3.0/glutTimerFunc.html.













Submitting Your Lab




Your code should be contained inside a single .py file. To submit the lab, simply submit this file through Learning Suite. If for some reason you used multiple files, zip these files together before submission. If you need to add any special instruction, you can add them there in the notes when you submit.













Rubric




Correct rendering of multiple houses along a street (30 points)




Correct rendering of a car with tires in correct locations (30 points) Correct animation of car moving with tires rotating (30 points)




Generally correct behavior otherwise (10 points) TOTAL: 100 points












































































3

More products