Presentation is loading. Please wait.

Presentation is loading. Please wait.

Control flow for interactive applications CSE 3541 Matt Boggus.

Similar presentations


Presentation on theme: "Control flow for interactive applications CSE 3541 Matt Boggus."— Presentation transcript:

1 Control flow for interactive applications CSE 3541 Matt Boggus

2 Overview Graphics pipeline reminder Specifying geometry for OpenGL Specifying geometry for Unity Control flow in a rendering/animation loop

3 Graphics pipeline

4 OpenGL programming Initialize OpenGL and drawing window Define the geometry (points, lines, triangles/polygons) Define the vertex attributes (color, normal, …) Transform the geometry (translate, rotate, scale) Set up the camera (position, direction, …) Set up the projection (orthographic or perspective) Set up lighting (light position, color, …) Set up textures Draw

5 Animation/Rendering loop main(){ init_variables_and_objects(); while(true){ draw_scene(); handle_events(); update_variables_and_objects(); }

6 init_variables_and_objects() time – Initially 0 – One instance per animation dt – Amount of time between steps of the animation – For each animation step, time += dt Scene objects – Geometric objects – Lights – Camera – Player

7 update_variables_and_objects() P’(time+dt) = P(time) + displacement(dt) displacement(dt) is the change in position for the given time step (we could do the same thing for orientation/rotation) How is displacement(dt) calculated? – Physics – Behavior – Input – Data Set points absolutely P’ = P[time] where P is an array that stores points

8 Timeline control What if we want to revert to an earlier time? http://www.mobygames.com/game/xbox360/braid/screenshots/

9 Save the Cause or Effect? P(time-dt) = P’(time) - displacement(dt) – Need to save displacement(dt) Or save P() values in a stack

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

11 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

12 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

13 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] draw(); [3] counter = (counter + 1)%draw_rate; if(counter == 0) draw();

14 handle_events() I/O Timers Scripted events Network message


Download ppt "Control flow for interactive applications CSE 3541 Matt Boggus."

Similar presentations


Ads by Google