3/18/15 Computer Graphics Keyframing and Linear Interpola9on This Lecture • Keyframing and Interpola7on – two topics you are already familiar with from your Blender modeling and anima7on of a robot arm • This lecture: Linear Interpola7on • Next lecture: Cubic interpola7on 1 3/18/15 Keyframing • The simplest form of anima7ng an object θ3 c3 θ2 60 sec anima7on • Video: 30 frames / sec = 1800 frames • We have 6 key frames • Keyframe system must generate 1794 frames A c2 c1 t=0 θ1 t=50ms What’s the in-‐between mo7on? Interpola9on Mathema7cal problem: Given a set of points, what are the most reasonable points in between? 2 3/18/15 Simplest – Linear Interpola9on …. just use a weighted average between points. We abbreviate “linearly interpolate” as Lirp Linear Interpola9on • The simplest solu7on – given: p0 and p1 – t is our control variable p1 Q p0 Q(t) = (1− t)p0 + tp1 0 t 1 • Note: we only do this for t between 0 and 1, inclusive 3 3/18/15 Linear Interpola9on: General Case • What if we are not given values at t=0 and t=1? – Say the value is p0 at t0 and p1 at t1 p1 Q p0 t' = t0 t t1 t − t0 t1 − t0 Q(t) = (1− t ')p0 + t ' p1 • From this point on, we will assume that t varies 0 to 1 Linear Interpola9on: Example 1 • An object lies at posi7on y = 2 at 7me t = 0 and posi7on y = 3.1 at 7me t = 1. Using linear interpola7on, approximate the posi7on of the object at 7me t = 0.6. y = (1− t)p0 + tp1 • Answer: p0=2, p1=3.1, t=0.6 y = (1− 0.6) × 2 + 0.6 × 3.1 y = 2.66 4 3/18/15 Linear Interpola9on: Example 2 • The brightness of a moving light source is b0 = 1.0 when it lies at posi7on x0 = 1.1 and b1 = 0.5 when it lies at posi7on x1 = 1.5. Using linear interpola7on, approximate the brightness of the light source when it lies at posi7on x = 1.4. b = (1− x)b0 + xb1 • We start at p0 = 1.1, end at p1 = 1.5, approximate at x = 1.4 x ' = (x − x0 ) / (x1 − x0 ) x ' = (1.4 −1.1) / (1.5 −1.1) = 0.75 Approximate at x’=0.75: b = (1− x ')b0 + x 'b1 b = (1− 0.75) ×1.0 + 0.75× 0.5 = 0.625 Linear Interpola9on: Example 3 • The posi7on of an object is (0, 1) at 7me t = 0 and (2, 10) at t = 1. Using linear interpola7on, approximate the posi7on of the object at 7me t = 0.1. • Linearly interpolate the two coordinates separately x = (1− t)x1 + tx2 x = (1− 0.1) × 0 + 0.1× 2 = 0.2 y = (1− t)y1 + ty2 y = (1− 0.1) ×1+ 0.1×10 = 1.9 The object posi7on at 7me 0.1 is (0.2, 1.9) 5 3/18/15 Hands-‐On Session • Download robotinterp.cpp, keyframe.cpp, keyframe.h and keyframe.txt from the class website • Copy keyframe.txt to the "resources" folder of the project 05_asset_instance, then add it to the "resources" group of this project. Depending on the configura7on on your compiler, you might need to save it in the "Debug" directory of your project. • Copy robotinterp.cpp, keyframe.cpp, keyframe.h to the "sources" directory of 05_asset_instance, and add them to your project. The file robotinterp.cpp will replace the current main file of your project. The keyframe files include code for linear interpola7on • Add the appropriate header files to robotinterp.cpp, then compile the project and run. Higng the key 'a' will start the robot anima7on based on linear interpola7on Hands-‐On Ac9vity 1 • The format of the keyframe.txt file is as follows: keyframe time param1 param2 • Here time is the actual 7me of the keyframe, param1 is the lei upper arm angle, and param2 is the lei lower arm angle • The file keyframe.cpp includes code for reading this file and interpola7ng all parameters given in the file • Study the code for keyframe.cpp and the connec7on with robotinterp.cpp (in Update, by means of the params array) • Add code to robotinterp.cpp and configure keyframe.txt to have the robot wave both arms • Show the anima7on to your TA or your instructor when finished 6 3/18/15 Hands-‐On Ac9vity 2 • You can interpolate not only the joint angles of the robot, but also the posi7on or other akributes (color, texture, lights, camera) • Let’s experiment with the robot posi7on in the world: – Add another parameter to keyframe.txt to represent the robot posi7on in each keyframe (in addi7on to joint angles) – Add code to robotinterp.cpp to make the robot change posi7on (for example, it may vanish along the nega7ve z-‐axis) while waving • Show the anima7on to your TA or your instructor when finished Hands-‐On Ac9vity 3 • In your latest assignment you got a taste of Vizard and its power for quick graphics development. Extend your Vizard script to make the camera fly over the piazza using keyframe interpola7on: – You may hardcode the keyframes, so that you can focus on interpola7on rather than file handling. For example, if you alter only the (x,y,z) posi7on of the camera, your keyframes look like keyframes = [[0,0,0,0],[1.2,0,3,2],[2.2,5,3,4], etc.]! – Define a func7on linearInterpolation(time) similar to the one given in the OpenGL robot code – Define a func7on navigate that uses linear interpola7on to set the posi7on (and orienta7on) of your camera, and schedule its execu7on using a 7mer 7 3/18/15 Hands-‐On Ac9vity 3 (contd.) • To make sure that your linearInterpolation func7on works properly, place an object of your choice at each interpolated posi7on to trace the path that the camera takes. Here’s an example: • Show the anima7on to your TA or your instructor when finished Hands-‐On Ac9vity 4 • In your latest assignment you have also imported your own Blender object into your graphics scene • Extend your Vizard script to make your Blender object move around the piazza using keyframe interpola7on • Show the anima7on to your TA or your instructor when finished 8 3/18/15 Linear Interpola9on: Limita9ons • Requires a large number of keyframes when the mo7on is highly nonlinear • Solu7on: cubic interpola7on (next lecture) 9
© Copyright 2026 Paperzz