CS 455 Lecture 1 – Vector
Agenda
- what ?s
- introductions
- meta
- program this
Who are you?
On a 1/4 sheet of paper, please answer the following questions:
- What’s your name?
- What city do you call home?
- What software have you developed that is most memorable?
- What do you hope to be able to do with what we learn in this class?
Program This
Three-dimensional coordinates are of paramount importance in computer graphics. Let’s write a class that we’ll use all semester long to represent 3-D locations and directions. We’ll also (re)steep ourselves in some C++, see how Bitbucket works, and use CMake to build a project that works on many different platforms.
Git
Create if necessary and log in to an account on Bitbucket. Visit https://bitbucket.org/twodee/cs455_2015a and hit Fork. Check This is a private repository and Inherit repository user/group permissions.
On a lab machine, run the Git GUI client. Clone your repository, using its URL as the source location. Check out to a directory on your H: drive.
GLEW
Download the 64-bit binary for the OpenGL Extension Wrangler (GLEW). My understanding is that the Windows OpenGL driver by default only exposes functions from the 1997 standard of OpenGL 1.1 (we say it’s application binary interface or ABI is stuck at 1.1). If you want to access newer functions, you must query for them dynamically. GLEW does this and stores pointers to all the newer functions.
Unzip the archive into your H: drive or some other persistent location. You’ll need the path to this directory when we get to CMake.
Freeglut
Download Martin Payne’s Windows build of Freeglut, a simple cross-platform windowing toolkit. This library doesn’t support a comprehensive set of widgets, but it gets the job done.
Unzip the archive into your H: drive or some other persistent location. You’ll need the path to this directory when we get to CMake.
CMake
Run CMake. Set the source location to your checkout directory. Set the build directory to some directory outside your source directory.
If Freeglut and GLEW are just inside your H: drive and use the default directory names, you can hit Configure and Generate. If not, click Add Entry and define GLUT_ROOT and GLEW_ROOT to be paths to the actual directories.
Pick Visual Studio 2011 Win64 as your target IDE. Our installation of CMake is a bit old, which will give us some grief. We’re really using Visual Studio 2013. Hopefully LTS can upgrade soon.
Open the solution file that CMake generates in the build directory. Say yes on all the dialogs. Visual Studio will ask you to upgrade the project. Do so. It may do so a couple of times.
Click on the project named first
. In the project menu, set this as the startup project. Now hit run.
Visual Studio will want to upgrade your project again. I don’t know why. Do so through Project / Retarget Solution. I agree; it’s silly.
Eventually, you should get a window with a white triangle. Clicking and dragging should generate some debug messages in the console window.
Whew.
Vector3
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 Vector.h
. Define it in Vector.cpp
. Create these files through Windows Explorer in the top-level source directory.
Many students prefer editing in Notepad++. Make you edits there, 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 a file with a main
function that creates some vectors, scales them, adds them, and prints them. Invoke every method you wrote.
Copy over the CMakeLists.txt
file from first
. Change all the first
references to vectest
. Append ../Vector3.cpp
to the add_executable
command.
Add your new files to your Git project using the GUI client and push them to Bitbucket.
TODO
Before next class:
- Complete the project setup steps above (through CMake) and send me a screenshot of your white triangle. Emails with timestamps after class starts will not receive credit.
- Read the syllabus.
- Watch A Brief History of Graphics, which focuses on game graphics. On a 1/4 sheet of paper (produced by 2 perpendicular folds or cuts), share 3-4 questions or observations about the content of these videos or the course. Turn it in at the beginning of Thursday’s class.
Haiku
In the beginning
God made the heavens and the earth
After he made math