Hello OpenGL. Nice to see you again, C++!

In this assignments, you will work create a simple animation using C++ and openGL. The goal of this assignment is to give you exposure to features that you'll likely see in the basecode. If something is unfamiliar to you, please ask questions!

In lab, you were given a simple openGL example which drew a square using an orthographic projection. We are going to extend this example to support colors, animation, and multiple objects! The basecode has been reorganized to include a Shape class which will be capable of drawing either a square or triangle.

  1. (10 points) Implement copy constructor, assignment operator, and iostream operator in the Shape class
  2. (10 points) The DefineUnitQuad() function initialized the quad geometry that we drew in helloGL. Using this as an example, finish the implementation of the DefineUnitTri() function.
    1. Specify vertices for the triangle in DefineUnitTri()
    2. Modify your program to draw a triangle shape
  3. (25 points) Using GLUT, we have registered a timer callback that is invoked every 100 ms. Use the given system calls (gettimeofday) to compute the delta time from the previous frame as well as the elapsed time. Then implement Shape.update() to make some attribute of the Shape change over time. Some animation ideas:
    1. Hover: each frame add a sin() offset to the Y coordinate of the shape. The angle passed to sin should be the elapsed time
    2. Spin: update the Z rotation of your triangle. Use the time since the last update to make the update smooth
    3. Pulse: use sin() to change the scale of the object. Either change the scale uniformly or animate either the Y or X components.
  4. (25 points) Use the vector container from the standard template library to create a list of objects. This list is already a global variable. Initialize and print the contents of the list in InitCanvas(). Draw the contents of the list in Draw(). You may create any number of objects, but start with a small number (say 3) to start. You can also choose how you will init the list, but be sure to include both triangles and squares. Some ideas:
    1. Make even indexes squares and odd indexes triangles
    2. Use <random> to choose either triangles or squares
    3. Make the first index a square and the remainder triangles
    4. Make sure to initialize each shape to have a different position so you can see them!
  5. (10 points) Obtain a pointer to the u_color variable in the fragment shader using glGetUniformLocation. Then set its value using glUniform4f. You will need to edit Shape::draw. Try setting a blue color to start.
  6. (10 points) Create screenshots and a video for submission.

Extra Challenges Personalize your submission. Here are some ideas

  1. Randomize the colors, sizes, and positions for each object.
  2. What happens when you change the order of transformations in draw() to switch the rotate and translate calls? In the README, describe how a shape that is initialized at (0,0) is positioned in each case.
  3. Change the program to use a perspective camera and place objects at different values along Z (e.g. so they are different distances from the camer). Take screenshots of the two scenes and explain the differences of each.
  4. Position the triangles and squares to make scenes and patterns.
  5. Add a circle primitive
  6. Animate the shape position based on the elapsed time. For example, objects could move in circles or straight lines. Objects moving in straight lines can either wrap at boundaries or bounce.

Submission Instructions