Computer Graphics Labs



Similar documents
Computer Graphics Labs

Graphics Pipeline in a Nutshell

Computer Graphics (Basic OpenGL, Input and Interaction)

The mouse callback. Positioning. Working with Callbacks. Obtaining the window size. Objectives

OpenGL & Delphi. Max Kleiner. 1/22

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

CMSC 427 Computer Graphics 1

CMSC 427 Computer Graphics 1

Input and Interaction. Project Sketchpad. Graphical Input. Physical Devices. Objectives

Input and Interaction. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Graphics Input Primitives. 5. Input Devices Introduction to OpenGL. String Choice/Selection Valuator

An Introduction to. Graphics Programming

Chapter 1 Introduction to OpenGL

Methodology for Lecture. Review of Last Demo

Input and Interaction

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Keyboard Mouse and Menus

Creating Animated Apps

Lecture 3: Coordinate Systems and Transformations

Practical Data Visualization and Virtual Reality. Virtual Reality VR Software and Programming. Karljohan Lundin Palmerius

Computer Graphics Through OpenGL: From Theory to Experiments

Aston University. School of Engineering & Applied Science

Kankakee Community College

Lecture 8 : Coordinate Geometry. The coordinate plane The points on a line can be referenced if we choose an origin and a unit of 20

CMSC 425 Game Programming 1

Marist School Computational Media. Processing Exercise 01 Bouncing Ball Animation. Description:

4D Interactive Model Animations

Jawaharlal Nehru Engineering College

Introduction to Computer Graphics

4BA6 - Topic 4 Dr. Steven Collins. Chap. 5 3D Viewing and Projections

Mobile App Tutorial Animation with Custom View Class and Animated Object Bouncing and Frame Based Animation

CS 4204 Computer Graphics

Solving Simultaneous Equations and Matrices

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Fireworks CS4 Tutorial Part 1: Intro

How To Run A Factory I/O On A Microsoft Gpu 2.5 (Sdk) On A Computer Or Microsoft Powerbook 2.3 (Powerpoint) On An Android Computer Or Macbook 2 (Powerstation) On

3. How many winning lines are there in 5x5 Tic-Tac-Toe? 4. How many winning lines are there in n x n Tic-Tac-Toe?

Visualization of 2D Domains

DNS (Domain Name System) is the system & protocol that translates domain names to IP addresses.

Answer: Same magnitude total momentum in both situations.

Project 2: Bejeweled

TRIGONOMETRY FOR ANIMATION

Univers Virtuels. OpenGL : Modélisation / Visualisation. Alexis NEDELEC. Centre Européen de Réalité Virtuelle Ecole Nationale d Ingénieurs de Brest

Course Project Lab 3 - Creating a Logo (Illustrator)

Plotting: Customizing the Graph

Scripting in Unity3D (vers. 4.2)

Lecture Notes, CEng 477

MovieClip, Button, Graphic, Motion Tween, Classic Motion Tween, Shape Tween, Motion Guide, Masking, Bone Tool, 3D Tool

MIT App Inventor Getting Started Guide


Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

GAMBIT Demo Tutorial

Flash MX 2004 Animation Lesson

MATHEMATICS Unit Pure Core 2

WP Popup Magic User Guide

CS170 Lab 11 Abstract Data Types & Objects

PROBLEM SET. Practice Problems for Exam #1. Math 1352, Fall Oct. 1, 2004 ANSWERS

1.6 A LIBRARY OF PARENT FUNCTIONS. Copyright Cengage Learning. All rights reserved.

WP Popup Magic User Guide

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

An Incomplete C++ Primer. University of Wyoming MA 5310

Basic controls of Rhinoceros 3D software

TouchDevelop Curriculum

Einführung Computergraphik (WS 2014/15)

Visualizing Data: Scalable Interactivity

Introduzione ad OpenGL

EdExcel Decision Mathematics 1

Make your own Temple Run game

REFERENCE GUIDE 1. INTRODUCTION

Procedure: Geometrical Optics. Theory Refer to your Lab Manual, pages Equipment Needed

WAYNESBORO AREA SCHOOL DISTRICT CURRICULUM INTRODUCTION TO COMPUTER SCIENCE (June 2014)

Lecture 2: Homogeneous Coordinates, Lines and Conics

TABLE OF CONTENTS. INTRODUCTION... 5 Advance Concrete... 5 Where to find information?... 6 INSTALLATION... 7 STARTING ADVANCE CONCRETE...

How To Learn To Program In Csc 406 Computer Graphics

SDC. Schroff Development Corporation PUBLICATIONS. MultiMedia CD by Jack Zecher

Creating Hyperlinks & Buttons InDesign CS6

Strategy Trader User Guide

Introduction to Autodesk Inventor for F1 in Schools

Analyzing Piecewise Functions

Microsoft PowerPoint 2010 Templates and Slide Masters (Level 3)

Midterm Solutions. mvr = ω f (I wheel + I bullet ) = ω f 2 MR2 + mr 2 ) ω f = v R. 1 + M 2m

Animations in DrRacket

Animated example of Mr Coscia s trading

SpaceClaim Introduction Training Session. A SpaceClaim Support Document

Create a New Profile Model in GM-SYS Profile Modelling

8-3 Dot Products and Vector Projections

SketchUp Instructions

AR-media TUTORIALS OCCLUDERS. (May, 2011)

Presents ITALIAN QUALITY & DESIGN. New AR Side Bet

Inserting Graphics into Grant Applications & Other Word Documents

Face detection is a process of localizing and extracting the face region from the

Math 259 Winter Recitation Handout 1: Finding Formulas for Parametric Curves

Book Builder Training Materials Using Book Builder September 2014

CHAPTER 14 Understanding an App s Architecture

Portal Connector Fields and Widgets Technical Documentation

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Transcription:

Computer Graphics Labs Abel J. P. Gomes LAB. 3 Department of Computer Science and Engineering University of Beira Interior Portugal 2011 Copyright 2009-2011 All rights reserved.

1. Learning goals 2. Timing and redisplay callbacks 3. Example 4. Programming exercises LAB. 3 BASIC ANIMATION AND COLLISIONS

Lab. 3 BASIC ANIMATION AND COLLISIONS In this lecture we intend to learn the basic of animation and collision detection when objects move around a 2D scene. are going to deal with geometric transformations in 2D as their generalization in 3D is straightforward. These geometric transformations are also called affine transformations. 1. Learning Goals At the end of this chapter you should be able to: 1. Use geometric transformations with variable parameters to animate objects within a 2D scene. 2. Use timing callbacks to refresh a dynamic scene that changes over time. 3. Detect collisions of moving 2D objects against the scene borders. 4. Detect collisions between objects in a 2D scene. 2. Timing and Redisplay Callbacks To animate an object within a scene, we need to move the object and redisplay the scene repeatedly within a short period of time. For that purpose, we need to register a timer callback that then calls the GLUT redisplay command called glutpostredisplay(). See Example below for further details (lines 55-60). The glutpostredisplay() command simply calls the display function called DESENHAR every 33 milliseconds. Registering a timer callback is carried out through the following command: gluttimerfunc registers a timer callback to be triggered in a specified number of milliseconds. Prototype: void gluttimerfunc(unsigned int msecs,void(*func)(int value),value); where: msecs: number of milliseconds to pass before calling the callback; func: the timer callback function; value: integer value to pass to the timer callback. The number of milliseconds is a lower bound on the time before the callback is generated. GLUT attempts

to deliver the timer callback as soon as possible after the expiration of the callback's time interval. 3. Example The following program displays a moving square within a sub-domain with a basic collision detection of the bounding edges of such a sub-domain. 1 #include <GLUT/glut.h> // Header File For The GLut Library 2 3 // Initial square position and size 4 GLfloat x1 = 10.0; 5 GLfloat y1 = 0.0; 6 GLfloat size = 2.5; 7 // Step values for coordinates 8 GLfloat xstep = 0.25; 9 GLfloat ystep = 0.25; 10 11 12 void quad() 13 { 14 glbegin(gl_quads); 15 glvertex2f( 0.0, 0.0); 16 glvertex2f( 2.5, 0.0); 17 glvertex2f( 2.5, 2.5); 18 glvertex2f( 0.0, 2.5); 19 glend(); 20 } 21 22 23 24 GLvoid DESENHAR(GLvoid) 25 { 26 glclearcolor(0.0f,0.0f,1.0f,1.0f); 27 glclear(gl_color_buffer_bit); 28 29 glmatrixmode(gl_projection); 30 glloadidentity(); 31 gluortho2d(0.0,40.0,0.0,40.0); 32 33 glmatrixmode(gl_modelview); 34 glloadidentity(); 35 36 // BEGIN collision detection for a square 37 if (x1 + size > 40.0 x1 < 0.0) 38 xstep = -xstep; // reverse direction on left or right edge 39 if (y1 + size > 40 y1 < 0) 40 ystep = -ystep; // reverse direction on top or bottom edge

41 x1 += xstep; // update x-coordinate for square origin 42 y1 += ystep; // update y-coordinate for square origin 43 // END collision detection for a square 44 45 gltranslatef(x1,y1,0); 46 // set current drawing color to red 47 glcolor3f(1.0f,0.0f,0.0f); 48 quad(); 49 // flush drawing commands and swap 50 glutswapbuffers(); 51 } 52 53 54 55 GLvoid TEMPORIZADOR() 56 { 57 // Redraw the scene by calling the display function DESENHAR 58 glutpostredisplay(); 59 gluttimerfunc(33,temporizador, 1); 60 } 61 62 63 void ESCAPE(unsigned char key) 64 { 65 if(key==27) exit(0); 66 } 67 68 69 int main (int argc, char** argv) 70 { 71 // initialization for GLUT/OpenGL 72 glutinit(&argc,argv); 73 glutinitdisplaymode(glut_double GLUT_RGB); 74 // create window with resolution 500x500 75 glutinitwindowsize( 500,500 ); 76 glutcreatewindow("bounce"); 77 // register callbacks 78 glutdisplayfunc(desenhar); 79 glutkeyboardfunc(escape); 80 gluttimerfunc(33,temporizador,1); 81 // process events 82 glutmainloop(); 83 return 0; 84 }

4. Programming Exercises 1. Write a program that moves a circle inside a square box. The circle is reflected when it hits any side of the box. Let us assume that the reflection angle is 45 degrees in relation to the line perpendicular to any box side. HINT: Use the timing callback called TEMPORIZADOR to update the movement of the ball. For that purpose, you must register such a callback by means of the statement gluttimerfunc(33,temporizador,1) in the main function. Within the TEMPORIZADOR callback, you must call the glutpostredisplay() function to redraw the scene again and again every 33 miliseconds. 2. Write a program to roll a wheel on a horizontal line. 3. Write a program to roll a wheel on a bias line. 4. Write a breakout game with a ball, a paddle and a set of bricks. 5. Write a program that moves a 2.5x2.5 square inside a 40x40 domain in R 2. The corresponding viewport has 500x500 pixels. The square movement is carried out in steps of 0.025 in the x-direction and in the y-direction. The initial position of the square is at (0.25,0.00). HINT: Use the GL_QUADS primitive for drawing the square, and the gltranslatef function to move the square. 6. Change the previous program in order to animate two squares that cross in a perpendicular manner inside the box. 7. Change the program in 5. in order to not only move it but also rotate it of 2.5 degrees at every single step.