Download presentation
Presentation is loading. Please wait.
1
Animation Lecture 17 Wed, Oct 3, 2007
2
Animation Animation may include Moving the objects in the scene.
Changing the shapes of objects. Moving the camera through the scene.
3
Moving Objects Typically objects move with constant velocity or constant acceleration. If velocity is constant, then position(t) = vt + s0. If acceleration is constant, then velocity(t) = at + v0, position(t) = ½ at2 + v0t + s0.
4
Constant Velocity Assume Then x(t) = vt + s0.
The velocity is constant, The motion is in the x direction only. Then x(t) = vt + s0. During a time interval t, v is constant (so v = 0), and The position changes by x = vt.
5
Constant Velocity The clock will give us the time interval t.
Get the initial time t0 by last = clock(). Get the time interval as t = clock() – last. Update last.
6
Updating the Position void idle() { int now = clock();
float time = (float)(now – last)/CLOCKS_PER_SEC; pos.x += v*time; last = now; return; }
7
Constant Acceleration
When an object is accelerating, its position and speed are changing. If the acceleration is constant, then The speed changes linearly. The position changes quadratically.
8
Constant Acceleration
In this case, we may use position(t) = ½ at2 + v0t + s0 to compute the present position, or We may store the current position and current velocity and update both of them. We will use the second option.
9
Updating Position and Velocity
A simple calculation is v = at, x = vt.
10
Updating Position and Velocity
However, if a > 0, then v = at, v = v + v x = vt. x = x + x will overestimate x , while…
11
Updating Position and Velocity
x = vt. x = x + x v = at, v = v + v will underestimate x . Why? Does it matter?
12
Updating Position and Velocity
It turns out that if a is constant, then we can use the average velocity vavg over the time interval t and get the correct value for x. That is, v = at vavg = (v + (v + v))/2 = v + ½ v x = vavgt.
13
Updating Position and Velocity
void idle() { int now = clock(); float time = (float)(now – last)/CLOCKS_PER_SEC; v_new = v + a*time; pos.x += 0.5*(v + v_new)*time; v = v_new; last = now; return; }
14
Circular Motion By incrementing the angle in the idle() function, we may use glRotate() to rotate an object or to move it in a circle.
15
Changing the Shape of Objects
Objects can be compressed or stretched by calling Scalef() with variable scale factors. Increment the scale factors in idle(), using the clock() function.
16
A Rolling Ball In the next demo, a red ball appears to roll along a strip. Is the ball really rolling?
17
A Rolling Ball Read Run
18
A “Rolling” Beachball Make the plain red ball a beachball.
Now we can tell whether the ball is rolling.
19
A “Rolling” Beachball Read Run
20
Let’s Get This Ball Rolling!
Now we will add a rotation to make the ball roll. The rate of rotation must be coordinated with the distance the ball moves, or else the ball will appear to be slipping or spinning.
21
An Accelerating Beachball
Read Run
22
An Accelerating Beachball
Suppose that the ball moves a distance x. Then it has rolled a distance x along its circumference. If r is the radius, then the angle is x/r, in radians. Perform the rotation: glRotatef((180.0/PI)*dx/rad, 0.0, 0.0, 1.0);
23
Rolling Beachball in 2D In the final rolling-ball example, the ball is rolling around in a 2D plane. It is easy to calculate the ball’s position. However, it’s orientation depends on the particular path it followed to get there. That is, we must know the previous orientation to compute the new orientation.
24
Rolling Beachball in 2D Read Run
25
Stretching the Beachball
Read Run
26
The Bouncing Ball The bouncing ball in the following example animates the shape of the object, as well as its position.
27
Bouncing Ball
28
Bouncing Ball The ball bounces in a semicircular arc.
29
Simulation of Motion in General
Let the position of an object be given by P(t) = (x(t), y(t), z(t)). Then the change in position is given by P(t) = (x(t), y(t), z(t)). We may approximate this by P(t) = (x(t)t, y(t)t, z(t)t) P(t) += P(t).
30
A More Realistic Bounce
We want the ball’s trajectory to be a parabola with height h and let s be the time required to travel this trajectory. For simplicity, assume that y(0) = 0. Then y(s/2) = h, y(s/2) = 0, and y(s) = 0. What is the formula for y(t)?
31
A More Realistic Bounce
The equation of a parabola is quadratic. Therefore, y(t) = at2 + bt + c for some numbers a, b, c. To find a, b, and c, we solve the equations y(0) = c = 0 y(s/2) = as2/4 + bs/2 + c = h y(s) = as2 + bs + c = 0 y(s/2) = as + b = 0.
32
A More Realistic Bounce
The solution is a = -4h/s2, b = 4h/s, c = 0. So, y(t) = -4h(t/s)2 + 4h(t/s). Then y(t) = -8ht/s2 + 4h/s = (4h/s)(1 – 2t/s).
33
A More Realistic Bounce
We program this as time += deltaT; ballPos.x += (bDist/bRate)*deltaT; ballPos.y += (4.0*bHgt/bRate)*(1.0 – 2.0*time/bRate)*deltaT;
34
A More Realistic Bounce
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.