1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 17 Animations, Loops.

Slides:



Advertisements
Similar presentations
July 8, 2002Serguei Mokhov, 1 Little Intro to OpenGL COMP471 - Computer Graphics Edition 1.2, October 2, 2002.
Advertisements

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations I Week.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
OpenGL 3D and Animation for Simulating a Solar System
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
Hierarchical ModelingHofstra University1 Modeling Define volumetric objects in terms of surfaces patches that surround the volume Each surface patch is.
University of British Columbia CPSC 414 Computer Graphics Week 3, Monday 15 Oct 03 © Tamara Munzner 1 Hierarchies, Display Lists recap: matrix hierarchies,
Hierarchical ModelingHofstra University1 Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,
Computer Graphics (Fall 2004) COMS 4160, Lecture 11: OpenGL 2
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
CAP4730: Computational Structures in Computer Graphics Introduction to OpenGL.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Lecture 3 OpenGL.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Open GL Lab 10 1 BSCS – 514 Computer Graphics Instructor Humera Tariq.
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
Modeling with OpenGL Practice with OpenGL transformations.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 18 Multiple Transformations.
Computer Graphics I, Fall 2010 OpenGL Transformations.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
NoufNaief.net TA: Nouf Al-harbi.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
NoufNaief.net 1 TA: Nouf Al-Harbi.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Introduction to Graphics Programming. Graphics API.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
Modeling Transformations Mario Costa Sousa University of Calgary CPSC 453, Fall 2001 Mario Costa Sousa University of Calgary CPSC 453, Fall 2001.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
OpenGL and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
Introduction of OpenGL - 3D Graphic and Animation
Draw a Simple Object.
2D Imaging and Transformation
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Unit-5 Geometric Objects and Transformations-II
Rendering Pipeline, OpenGL/GLUT
OpenGL program.
Repetition Statements (Loops) - 2
Loops & Nested Loops CSE 120 Winter 2019
Presentation transcript:

1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 17 Animations, Loops

2 Using Variables in Expressions Variables can be used in arithmetic expressions and function calls. Example--Multiplication: float area, width, height; width = 5.0; height = 3.0; area = width * height; Example--Adding 1: int count = 0; count = count + 1; count += 1; count++; Using variables in function calls: float theta = 45.0; glRotatef(theta, 0, 0, 1.0);

3 Local and Global Variables Variables declared at the beginning of the program and outside any function definition are global variables. They can be accessed by any function in the program. Variables declared inside a function definition are local to that function. They can only be accessed within that function. Demo. (We will show this in the example code).

4 Simple Animation Simple Animation in OpenGL is accomplished with an idle( ) function. The idle( ) function is called every tick of the computer clock. We can update a variable in the idle( ) function to change the position of an object. Declaring the idle function (inside the main( ) function): glutIdleFunc(idle); Updating a global variable in the idle function: void idle(void) { theta = theta + 0.1; glutPostRedisplay( ); }

5 Animation continued We then use theta when drawing our object: void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix( ); glRotatef(theta, 0, 0, 1.0); glBegin(GL_POLYGON); glVertex3f(50.0, 50.0, ); glVertex3f(50.0, 100.0, ); glVertex3f(100.0, 100.0, ); glVertex3f(100.0, 50.0, ); glEnd( ); glPopMatrix( ); glFlush(); glutSwapBuffers( ); }

6 Use of glPushMatrix( ) and glPop Matrix( ) We often want to perform a transformation on only one or a few objects in our scene. We need to save the current transformation information, so we can get it back after we have transformed our objects. glPushMatrix( ) saves the current transformation information. glPopMatrix( ) restores the most recently saved transformation information. glPushAttrib(GL_ALL_ATTRIB_BITS) saves other attributes such as color. glPopAttrib( ) restores the most recently saved attributes.

7 Double Buffering If we use a single frame buffer when animating, the drawing into the frame buffer can become out of synchronization with the drawing to the monitor. This can cause the animation to flicker. To avoid this, we use double buffering. We use two frame buffers. We draw to one frame buffer, while the other is being displayed. Then we swap buffers. In OpenGL: In the main( ) function: glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); In the display( ) function: glutSwapBuffers( );

8 Setting the Color OpenGL uses RGB color coordinates. The values for each color range from 0 to 1.0 Set each color with: glColor3f(red, green, blue) Example: glColor3f(1.0, 0.0, 0.0); //draw in red... glColor3f(0.5, 0, 0.5); //draw in purple

9 Loops We often want to repeat an action multiple times, with only small changes. For example, we might want to draw an object in multiple different places. We don't want to re-write the code every time. We can repeat a piece of code multiple times, using a loop.

10 A While Loop int count = 0; while (count < 10) { glPushMatrix( ); glTranslatef(25 * count, 0, 0); glBegin(GL_LINES); glVertex3f(0.0, 25.0, -200); glVertex3f(0.0, -25.0, -200); glEnd( ); glPopMatrix( ); count = count + 1; }

11 General Form of a While Loop while( condition) { //Body of loop statements; } Condition Body of Loop true Rest of program false