Seminar 1 Scene graph & Hierarchical animation EDA221 Introduction to Computer Graphics Carl Johan Gribel, PhD student
Today Hierarchical animation – T*R*S More on Visual Studio/RenderChimp – Debugging – Atom program Assignment 1 – Solar system
Hierarchical transform torso lower arm upper arm torso lower arm upper arm lower_arm->rotateZ(0, 0, PI/6);upper_arm->rotateZ(0, 0, PI/6);
Compound transform Transformations stored in each node: translation (3d-vector) rotation (3x3-matrix) scaling (3d-vector) Applied in T*R*S order What if further transformations are needed? E.g.: Rotation around arbitrary point p requires a T(p)*R*T(-p) sequence; not achievable by T*R*S only Solution:an extra node, containing another set of transformations
Compound transform: Spin vs orbit world earth sun rotate translate earth pivot rotate earth translate world sun earth spinearth orbit extra node
Decouple spin from orbit world earth pivot sun earth translate rotate earth pivot earth translate world sun rotate sun spin coupled with earth’s orbitsun spin decoupled from earth’s orbit (somewhat more correct astrophysically)
Compound transform: camera world camera camera pivot camera world rotate translate rotate translate ”FP-style””Pivot-style”
Visual Studio Debugging breakpoints DataTips printf precompiler
Breakpoints Toggle breakpoint on current line with F9 Pauses execution: enters break mode Right-click on the breakpoint symbol to add conditions, hit-counters, filters...
DataTips Available during break mode Display / edit variables by hovering them: Can even expand hierarchically into class members, pointer-targets etc Right-click and select ”Watch” to pin variable to a Watch-window
printf The brute force way: print whatever you need to monitor to the standard output (console window) printf(”I want to monitor this value: %f\n”, var); Can format the output Can monitor output continuously as the program executes Messy code
Precompiler Dictates what (not) to compile #define DEBUG_MODE. #if defined DEBUG_MODE // will be compiled only if DEBUG_MODE is defined #endif
Enable debugging To debug, select the ”OpenGL 2.0, Debug” configuration Build + Run (F5)
RenderChimp: SceneGraph class All creation and deletion of Nodes and Resources must go through the SceneGraph class new and delete are not permitted for any RenderChimp objects Light *light = SceneGraph::createLight(“MyLight”); SceneGraph::deleteNode(light); Light *light = new Light(“MyLight”); delete light; Yep! Nope!
RenderChimp: Atom program my_scenegraph.cpp #include "RenderChimp.h” // <-- declare global variables, scene graph nodes... void RCInit() { // <-- initialize variables, nodes...(called ONCE) } int RCUpdate() { // <-- apply transformations... (called EVERY FRAME) } void RCDestroy() { // <-- release allocated memory (called as program exits) }
RenderChimp: Animation Apply animation transformations in the update-routine float earth_spin = 0.6f;// earth spin (rad/s) int RCUpdate() { earth->rotateY( earth_spin * Platform::getFrameTimeStep() ).. } length of a frame (s)
Interaction ”WASD” forward/left/down/right (in camera space) Mouse: Pivot camera left button: absolute angle right button: relative angle
Assignment 1 Model the solar system! Sun, planets, moons, comets...spaceships? It’s up to you. Resources included in RenderChimp are at your disposal Models, textures, shaders Code for how to add shaders is included (more in assignment 3-4) See assignment description for details
Assignment 1 Hint Add planetary rings like this VertexArray *ring_va = createCircleRing(...); Geometry *ring = SceneGraph::createGeometry(“rings”, ring_va); You’ll need #include ”ParametricShapes.h” in the top of your cpp-file
Textures
End