teaching machines

CS 455 Lecture 2 – Triangles

Agenda

• what ?s
• a history of OpenGL
• an overview of the graphics pipeline
• some models

TODO

Before next class:

• Complete the lab exercise below and send in a screenshot of your main’s console output.

Before next Thursday:

• Read some tutorials or watch some videos on 3-D modeling. (Neal Hirsig offers a complete course.) Build a model of your choosing in Blender or some other modeling program. Post an image of it on this blog, with exactly these three categories: cs455, spring 2015, postmortems. This is worth a Blugold. Log in to the blog using the Login link in the menu at the top of the page. You should have received an email with your password earlier this week. Check your junk mail if you can’t find it, or go through the Forgot my Password dance.

Lab

Pair up with a neighbor to write a Vector3 class with the following specification:

1. Uses floats to represent the vector’s three components.
2. A default constructor that zeroes the vector’s three components.
3. A constructor that accepts the initial values of the three components.
4. A subscript method ( operator[]) that accepts an index of 0, 1, or 2. When the index is 0, it returns the x-component. 1, the y-component. 2, the z-component. So that this message may serve as both a getter ( cout << v[0]) and a setter ( v[0] = 1.2f) return the float as a reference to a member variable.
5. const subscript method.
6. A method that gets the vector’s length or magnitude.
7. const method that determines the dot product of this vector and a parameter vector (which comes in as a const reference).
8. A method that normalizes the vector.
9. + method that adds component-wise this vector to a parameter vector and returns the sum as a new vector.
10. += method similar to the previous method but which alters this vector instead of yielding a new one.
11. * method that scales component-wise this vector by a float scale factor parameter and returns the scaled vector as a new vector.
12. *= method similar to the previous method but which alters this vector instead of yielding a new one.

Declare the class in Vector3.h. Define it in Vector3.cpp. Create these files through Windows Explorer in the top-level source directory.

Many students prefer editing in Notepad++. You may make your edits with it, and when you go to run your projects, jump to Visual Studio. Messy, huh? I prefer the workflow of Linux or Mac.

Also write a << method for printing vectors. Note that this can’t be a member of Vector3, since the invoking object will be an ostream, not a Vector3.

Main

Now let’s create a second project in our Git repository for testing your Vector3 class. Create a directory named vectest and create file vectest.cpp with a main function that creates some vectors, scales them, adds them, and prints them. Invoke every method you wrote and make sure it does the correct thing.

Copy over first/CMakeLists.txt to your vectest directory. Change all the first references to vectest. Append  ../Vector3.cpp to the add_executable command. Also, in order to make CMake aware of this new project, add this line to the overall CMakeLists.txt in your top-level source directory:

add_subdirectory(vectest)

Rebuild in Visual Studio.

Add your new files to your Git project using the GUI client and push them to Bitbucket.