Download presentation
Presentation is loading. Please wait.
Published byKathleen Sutton Modified over 9 years ago
1
Animation with OpenGL Hsiao Chun-Tse 2007/03/27
2
I’ll present the simplest method to generate animation. Without much efforts, you can improve the system much better.
3
Flow chart of animation Initialization Timer function Initialization : 1. Initialize OpenGL & GLUT 2. Load models. 3. Load animation file. Set Timer function : 1. Use glutTimerFunc() to set Timer function. Set Timer function Timer function : 1. Increase time counter. 2. load animation data of this time. 3. if there is another frame, use glutTimerFunc() again
4
glutTimerFunc Arguments msecs : ms. Func : Timer function pointer. Value : argument pass to Timer funciton. Ex. glutTimerFunc(5000, TimerFunc, 0); call TimerFunc(0) 5000 ms later.
5
Improve robot.c I’ll apply some changes to robot.c Edit function. Record frame by frame. Display function. Display frame by frame. All recorded frames will be saved in save.act. Of course, when we display animation, we load save.act for animation data.
6
Save Animation Parameters
7
What data should we save? Basically, we should save : Arguments of model transformations. glTranslatef(), glScalef(), glRotatef()… Argument of view transformation. gluLookAt() Other options : Background color. Display subtitles.
8
Saved data in robot.c We save 11 data members each frame… Counter (t) Shoulder translation (dx, dy, dz) Shoulder rotation (sr) Elbow rotation (er) Finger rotation (fr00, fr01, fr10, fr11) Eye position (eye) t dx dy dz sr er fr00 fr01 fr10 fr11 eye
9
Edit mode in robot.c When we press ‘o’ or ‘O’, enter edit mode. In edit mode, press ‘/’ for saving animation parameters in save.act. Press ‘o’ or ‘O’ again to leave edit mode.
10
Add following codes to keyboard() Add a new function EditMode(). Open save.act file. case 'o': case 'O': EditMode(); glutPostRedisplay(); break;
11
Add following codes to keyboard() Add SaveFrame() function Save current animation parameters to file. case '/': SaveFrame(); break;
12
‘o’ Edit modeAdjust model ‘/’ Save parameters ‘o’ Exit edit mode
13
Display animation.
14
Open the file ‘save.act’ Trigger TimeFunc() to display animation.
15
Add following codes to keyboard() Add DisplayMode() function. Open ‘save.act’ Trigger TimerFunc() by glutTimerFunc(). case'=': DisplayMode(); glutPostRedisplay(); break;
16
TimerFunc Use fscanf() to load animation parameters. Draw the Frame. If EOF is not reached => trigger itself. If EOF is reached => stop.
17
‘=‘ Display mode TimeFunc have data stop no data
18
Demo enhanced robot.c
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.