teaching machines

CS 455 Lecture 4 – 2-D Transformations

January 31, 2013 by . Filed under cs455, lectures, spring 2013.

Before class

Scaling, Translation, and Shear

  1. Watch http://youtu.be/Vfs7eOjcKuo. (I misspeak at one point: only translation and rotation are rigid-body transforms.)
  2. Read about transforms for a different graphics API at http://processing.org/learning/transform2d/, stopping before The Transformation Matrix.

Rotation

  1. Watch http://youtu.be/qKgYarnLT94.
  2. Another brief perspective: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm.
  3. For the inclined, read the sin and cosine summation section of http://oakroadsystems.com/twt/sumdiff.htm.

In class

First, here’s a fix to an annoyance several of you have encountered: you add a shader to src/shaders, you configure, you build, you run. Then you edit the shader but the changes don’t show up. That’s because there’s a line in CMakeLists.txt that copies the shaders directory to your build directory at configure time. Long story short, you have two versions of your shaders lying around, and you are changing the wrong one. I’ve looked for the simplest fix possible, and I think this might be it:

  1. Delete this line from CMakeLists.txt:
    file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/shaders DESTINATION ${CMAKE_BINARY_DIR})
  2. Add the line:
    add_definitions(-DSHADERS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/shaders")
  3. With that change, you will only have one shaders directory, sitting inside your project source. (That also means you can’t just take your builds around and run them anywhere. They depend on your source being there too.) When you load up your shaders, you will need to fix your paths to the GLSL source:
    program = td::ShaderProgram::FromFiles(SHADERS_DIR "/vanilla.vert.glsl", SHADERS_DIR "/vanilla.frag.glsl"); 

Second, make sure you’ve completed the exercises from last time or at least have some geometry set up that you can visualize.

Third, implement the canonical bounce animation. Every frame, move your geometry along some defined velocity vector. If the geometry’s center position moves outside of the [-1, 1] x [-1, 1] window, reflect that velocity vector. (Consider velocity as the slope a line. What’s the slope of a perpendicular line?) Also, add some spin. If your geometry is circular, that spin will be hard to detect. Go into wireframe mode with:

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

Haiku

Ay! Con permiso.
Sorry. I’ll translate for you.
Gracias, senor.