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:
- Uses
float
s to represent the vector’s three components. - A default constructor that zeroes the vector’s three components.
- A constructor that accepts the initial values of the three components.
- 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 thefloat
as a reference to a member variable. - A
const
subscript method. - A method that gets the vector’s length or magnitude.
- A
const
method that determines the dot product of this vector and a parameter vector (which comes in as aconst
reference). - A method that normalizes the vector.
- A
+
method that adds component-wise this vector to a parameter vector and returns the sum as a new vector. - A
+=
method similar to the previous method but which alters this vector instead of yielding a new one. - A
*
method that scales component-wise this vector by a float scale factor parameter and returns the scaled vector as a new vector. - A
*=
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.
Haiku
Be great at one thing
Or be good at lots of things
Machines picked the first