Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game and animation control flow

Similar presentations


Presentation on theme: "Game and animation control flow"— Presentation transcript:

1 Game and animation control flow
CSE 3541/5541 Matt Boggus

2 Overview Pseudocode for a game/animation loop Undo/redo example
Tradeoff in saving cause vs. effect Unity transform and hierarchy computations as saving the effect

3 Game/Animation loop main(){ Initialize(); while(true){ DrawScene(); HandleEvents(); Update(); }

4 Draw() and HandleEvents()
Draw() handled by Unity Types of events I/O Timers Scripted events Network message

5 Initialize() frame time Scene/Hierarchy objects
Initially 0, increases by 1 every time the scene is drawn time Initially 0, increases by dt (a.k.a. timestep, Δt) every update Units might be seconds, minutes, or days, etc. Unity Time and Framerate Management Scene/Hierarchy objects Geometric objects Lights Camera Note the ese of your own dt value for controlling the speed of the animation vs. the Unity Time.deltatime which controls frame-rate for different hardware or run-time conditions

6 Update() P’(time+dt) = P(time) + Displacement(dt)
Displacement(dt) is the change in position over the amount of time, dt, passing Can have similar equation for change in orientation How is Displacement(dt) calculated? Real-time user input Physics Behavior Key-frame data / Interpolation (Motion capture – save positions at each frame instead of computing displacement)

7 Time control or frame selection
Braid (2008) Autodesk MotionBuilder Image from Image from

8 Two approaches P(time-dt) = P’(time) - Displacement(dt)
Save the cause (of the position change): Displacement(dt) Save the effect or result (of the position change) P’(time)

9 Timeline control – undo/redo of drawing shapes
Ex: see MSPaint Removes the last drawn shape Replace removed shapes, unless a new one is drawn

10 Undo/Redo – two options
Save the cause (the data to draw each shape) Which shape? Starting mouse (x, y) Ending mouse (x, y) Save the effect (the image after drawing the new shape) Image width * image height pixels Each pixel has a red, green, and blue value

11 Undo/Redo – two options
Save the cause (of each drawn shape) Algorithm: to undo, clear the background and redraw shapes Storage cost: 5 ints per shape Save the effect (image after each shape is drawn) Algorithm: to undo, revert to previous image Storage cost: x * y * 3 ints per shape

12 Tie-in with hierarchical scenes in Unity
Storing the result of a series of geometric transformations in an object’s transform is comparable to “saving the effect” Image from

13 Additional slides

14 draw_scene() Input: 3D scene + camera Output: 2D image When to redraw?
Camera change [1] Object in view moves [1] Every frame [2] Every xth frame [3] [1] if(flag_set){ draw(); flag_set = false; } [2] [3] counter = (counter + 1)%draw_rate; if(counter == 0)

15 Graphics pipeline


Download ppt "Game and animation control flow"

Similar presentations


Ads by Google