CS 455 Lecture 5 – Vectors, Matrices, and Meshes
Before Class
Meshes
- Watch http://youtu.be/EWtMydWVozQ.
- Watch an introduction to modeling: http://cgcookie.com/blender/2010/08/31/blender-intro-to-modeling.
Vectors and Matrices
- Watch http://youtu.be/cMkKKDanIhw.
- Read http://www.gamedev.net/page/resources/_/technical/math-and-physics/vectors-and-matrices-a-primer-r1832, skipping the sections on determinants, inversion, and projection matrices for now.
In class
- Create a renderer that lets you scale and or translate a tweaked OBJ model with a matrix. (I’ve placed a few models in the W455 directory.) Alter your matrix based on events of your choosing. (Recognizing cursor key events needs to be added to glut_utilities.cpp. It’s simple to do; follow the PAGEUP example or ask if you need help.)
- The GPU can do matrix multiplication out of the box. Send your matrix as a uniform:
uniform mat4 xform; in vec3 position; void main() { gl_Position = xform * vec4(position, 1.0); }
- On the CPU side of things, you need to store your matrix in memory somehow. Next lecture will cover making a handy matrix class. For now, just store matrix elements in a one-dimensional array in column-major order:
scale as {sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1} translate as {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, dx, dy, dz, 1}
- Send your matrix to the GPU uniform with something like:
program->Bind(); GLint location = program->GetUniformLocation("xform"); glUniformMatrix4fv(location, 1, GL_FALSE, scaleOrTranslateMatrix); program->Unbind();
- Give yourself a pat on the back!
Haiku
Poor starving artists
All that clay, bronze, fumbly stuff
Numbers nourish me
All that clay, bronze, fumbly stuff
Numbers nourish me