Slide 1

Slide 1 text

5. Animation Tatsuya Yatagawa

Slide 2

Slide 2 text

What is “animation”? n Individual picture frames updated very quickly n Old motion picture※ in Japan (1907) Computer Graphics Course @Waseda University YouTube: https://www.youtube.com/watch?v=aUS30ya14wY ※ Motion picture is directly translated to “活動写真” (katsudo-shashin), but it means slightly different one from motion picture (it’s movie) in English. Copyright

Slide 3

Slide 3 text

What is “animation”? n Stop motion animation n Photographing scene while incrementally updating it. n Nowadays, it is almost replaced by “computer animation”. Computer Graphics Course @Waseda University YouTube: https://www.youtube.com/watch?v=wT5WUjueWr4 Copyright

Slide 4

Slide 4 text

Current computer animation n The Tale of the Princess Kaguya (Studio Ghibli Inc. 2015) Computer Graphics Course @Waseda University Movieclips Film Festivals & Indie Films (YouTube): https://www.youtube.com/watch?v=9lDrkokymLQ Copyright

Slide 5

Slide 5 text

Current computer games n Unreal Engine 5 (demo running on PlayStation 5) Computer Graphics Course @Waseda University Epic Games (YouTube): https://www.youtube.com/watch?v=qC5KtatMcUw Copyright

Slide 6

Slide 6 text

Frame rates in CG animation Computer Graphics Course @Waseda University Type Frame rates Made with TV animation 8 - 12 fps Hand drawing / CG Movie 24 fps Mostly CG (offline rendering) Video games 60 fps CG (real-time rendering) • Video games require interactivity → real-time rendering • Highly parallelized processing using GPU is more effective CPU vs GPU? See the movie below! https://www.youtube.com/watch?v=-P28LKWTzrI

Slide 7

Slide 7 text

Basics of computer animation n Camera effects n Update camera and projection matrices n e.g., dolly zoom (both camera/projection matrices updated) n Rigid transform to objects n Controlled by model matrix Computer Graphics Course @Waseda University

Slide 8

Slide 8 text

Goal n Simple rotation of two cubes Computer Graphics Course @Waseda University Source code https://github.com/tatsy/OpenGLCourseJP/tree/master/src/animation

Slide 9

Slide 9 text

Animation in GLFW n 1 frame corresponds to 1 while loop Computer Graphics Course @Waseda University 1 frame

Slide 10

Slide 10 text

Update animation parameters n Method for parameter update n User-defined method for updating parameters n Call once per while loop Computer Graphics Course @Waseda University

Slide 11

Slide 11 text

Apply model matrix n Apply object rotation to model-view matrix Computer Graphics Course @Waseda University Rotate cube by theta (in degree)

Slide 12

Slide 12 text

Separate cube drawing method n For convenience, separate method to draw cube Computer Graphics Course @Waseda University

Slide 13

Slide 13 text

Further settings n Control FPS (frames-per-second) n Control time interval between successive draws n Enable current FPS checking n Show FPS to window title n Individual animation controls to objects n One rotates 1 degree, the other rotates 2 degrees, etc. Computer Graphics Course @Waseda University

Slide 14

Slide 14 text

Control FPS n Check time interval after previous draw n Use glfwGetTime to measure the time interval n If time is above (1 / FPS), then draw again Computer Graphics Course @Waseda University

Slide 15

Slide 15 text

Show current FPS to window title n glfwSetWindowTitle is available n Use sprintf (*1 to setup title text n Pass title text to glfwSetWindowTitle Computer Graphics Course @Waseda University *1) Visual Studio needs “#define _CRT_SECURE_NO_WARNINGS”

Slide 16

Slide 16 text

Per-object animation control n Each of two cubes is moved differently n 1st cube rotates 2 degree of angle in 1 frame. n 2nd cube rotates 1 degree of angle in 1 frame. Computer Graphics Course @Waseda University How can this be achieved?

Slide 17

Slide 17 text

Is it easy? Computer Graphics Course @Waseda University // Rotate 1st cube and draw! glRotatef(theta * 2, 0, 1, 0); drawCube(); ... // Rotate 2nd cube and draw! glRotatef(theta, 0, 1, 0); drawCube(); This is a stupid solution! Take care the lifetime of “glRotatef”.

Slide 18

Slide 18 text

OK, it’s so easy! Computer Graphics Course @Waseda University // Rotate 1st cube and draw! glRotatef(theta * 2, 0, 1, 0); drawCube(); ... // Rotate 2nd cube and draw! glRotatef(theta, 0, 1, 0); drawCube(); ← Matrix rotates 1st cube by (2 * theta) ← Matrix rotates 1st cube by (theta + 2 * theta) → Matrix multiplication is accumulated! This is a stupid solution! Take care the lifetime of “glRotatef”.

Slide 19

Slide 19 text

glPushMatrix / glPopMatrix n Manipulate “matrix stack (= LIFO)” (c.f., queue = FIFO) n glPushMatrix → Stack a new matrix on the top n glPopMatrix → Pop the matrix on the top Computer Graphics Course @Waseda University Camera matrix gluLookAt Camera matrix glPushMatrix Identity matrix glRotatef Camera matrix Rotate matrix glPopMatrix Camera matrix

Slide 20

Slide 20 text

Snippet for per-object animation Computer Graphics Course @Waseda University

Slide 21

Slide 21 text

Result Computer Graphics Course @Waseda University

Slide 22

Slide 22 text

Practice n Practice 5-1 n Check what happens if you set large FPS? n Hint: For example, you can set FPS more than 120? Computer Graphics Course @Waseda University

Slide 23

Slide 23 text

Practice n Practice 5-2 n Implement a simple animation of clock using glPushMatrix / glPopMatrix. n Hint: Use thin triangles/rectangle for second hand, minute hand and hour hand. n Hint: To get current time, “localtime()” in C can be useful. Computer Graphics Course @Waseda University

Slide 24

Slide 24 text

_CRT_SECURE_NO_WARNINGS n Macro to disable compile error for some methods deprecated in Visual Studio n This affects sprintf, fprintf, scanf, fscanf, localtime, etc. n Specify this macro to either of following two: n Property sheet → “C++” → “Preprocessor” → “Preprocessor definition” n Topmost line of source code in which you use above methods. Computer Graphics Course @Waseda University