lecture15 - CSE 471 Media Processing and Multimedia...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSE 471 Media Processing and Multimedia Animation Basics The game loop Simple physics Euler steps Collision detection Collision response E xam ple s a re in C#
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 CSE 471 Media Processing and Multimedia The game loop Core component of most animation applications while (not done) Process any input Advance Render Play sounds Message pump end while
Background image of page 2
3 CSE 471 Media Processing and Multimedia Example Simple C# example: { Advance(); Render(); Application.DoEvents(); } false when window destroyed Advance the animation Draw Message pump
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 CSE 471 Media Processing and Multimedia private void Render() { if (device == null) return; device.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0); device.RenderState.ZBufferEnable = false; // We'll not use this feature device.RenderState.Lighting = false; // Or this one. .. device.RenderState.CullMode = Cull.None; // Or this one. .. device.Transform.Projection = Matrix.OrthoOffCenterLH(0, worldW, 0, worldH, 0, 1); //Begin the scene device.BeginScene(); foreach (Polygon p in objects) { p.Draw(device); } //End the scene device.EndScene(); device.Present(); }
Background image of page 4
5 CSE 471 Media Processing and Multimedia Advance Move things Resolve any collisions What’s a collision?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 CSE 471 Media Processing and Multimedia Simple 2D Physics Motion of objects in 2D May or may not obey the laws of physics We’ll create general ideas Most of this can be extended to 3D pretty easily, except rotation is more complicated This is a basic introduction and omits details of objects in continuous contact
Background image of page 6
7 CSE 471 Media Processing and Multimedia The basics Let p(t) be the position in time. We’ll drop the (t) and just say p Other values: v – velocity a - acceleration 2 2 dt p d dt dv a dt dp v = = = Velocity is the derivative of position Acceleration is the derivative of velocity
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 CSE 471 Media Processing and Multimedia Vector calculus Really, p(t) is a double, right? Sometimes Think of these equations as two equations, one for each dimension This is vector calculus = dt dp dt dp t v t v y x y x ) ( ) (
Background image of page 8
9 CSE 471 Media Processing and Multimedia What about real objects? Some of the things we’ll know about a real object: Position vector (p) Velocity vector (v) Acceleration vector (a) We might also know: Mass More to come…
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 CSE 471 Media Processing and Multimedia Variables to keep track of state private Vector2 p = new Vector2(0, 0); // Location private Vector2 v = new Vector2(0, 0); // Linear velocity private Vector2 a = new Vector2(0, 0); // Linear acceleration
Background image of page 10
11 CSE 471 Media Processing and Multimedia Example: Air Resistance The resistance of air is proportional to the velocity F = -kv We know F = ma, so: ma = -kv kv dt dv m kv ma - = - = So, how can we solve?
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon