From Gears to The Machine in 13 Steps Carolyn Smith COSC 4331 5/6/2009.

Slides:



Advertisements
Similar presentations
OPENGL.
Advertisements

3D Game Programming Geometric Transformations
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
Translate, Rotate, Matrix Pages Function Function Definition Calling a function Parameters Return type and return statement.
Hwk1- A Tutorial of OPENGL ver2.0. We will introduce… Draw a window by OpenGL Draw one/many polygons by OpenGL Rotate/Translate Matrix Push/PopMatrix.
CHAPTER 4 Geometric Transformations: The Pipeline Vivian by Richard S. Wright Jr.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
1 3D modelling with OpenGL Brian Farrimond Robina Hetherington.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 GLUT Callback Functions.
Computer Graphics (Fall 2004) COMS 4160, Lecture 11: OpenGL 2
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Chapter 4 10 February Agenda Program 2 – Due 2/17 Chapter 4 – transformations GLUT solids.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Transformations With OpenGL Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin.
Geometric transformations The Pipeline
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Transformations With OpenGL Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Open GL Lab 10 1 BSCS – 514 Computer Graphics Instructor Humera Tariq.
Modeling with OpenGL Practice with OpenGL transformations.
Graphics Graphics Korea University kucg.korea.ac.kr Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics I, Fall 2010 Working with Callbacks.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
NoufNaief.net 1 TA: Nouf Al-Harbi.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Chap 3 Viewing and Transformation
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.
OpenGL & OpenSceneGraph Graphics Programming Katia Oleinik:
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Introduction to Graphics Programming. Graphics API.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Transformation Example. Order of Transformation Matters Scale, translate Scale, translate Translate scale Translate scale Rotate, Translate Rotate, Translate.
OpenGL LAB III.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
The Modelview Stack Lecture 9 Wed, Sep 12, The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
CSC Graphics Programming
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
School of Computer Science
Working with Callbacks
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
Computer Graphics, KKU. Lecture 13
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Chapters 5/4 part2 understanding transformations working with matrices
Working with Callbacks
Project 1: Into Space! CG Concepts Needed
Chapter 3 arrays of vertices vertex arrays display lists drawing text
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Advanced Graphics Algorithms Ying Zhu Georgia State University
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Presentation transcript:

From Gears to The Machine in 13 Steps Carolyn Smith COSC /6/2009

How does gears.c work? - gear(GLfloat inner_radius, Glfoat outer_radius, Glfloat width, Glint teeth, Glfoat tooth_depth) - draw(void): glPushMatrix(); glTranslatef(-3.0, -2.0, 0.0); glRotatef(angle, 0.0, 0.0, 1.0); glCallList(gear1); GlPopMatrix(); - void key(unsigned char k [...]) //keyboard input for rotation of view on z-axis - void reshape(int width, int height) //responds to resizing of window by scaling gears appropriately - int limit = 0 by default, and int count = 1; limit can be set using an argument at run time, and animation ceases when count = limit

Step 1: Change gears to rings Original code: gear1 = glGenLists(1); glNewList(gear1, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0, 4.0, 1.0, 20, 0.7); GlEndList(); Modified code: gear1 = glGenLists(1); glNewList(gear1, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0, 4.0, 1.0, 20, 0.0); glEndList();

Step 2: Change ring radii & width Original code: gear1 = glGenLists(1); glNewList(gear1, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0, 4.0, 1.0, 20, 0); glEndList(); Modified code: gear1 = glGenLists(1); glNewList(gear1, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0, 1.5, 0.5, 20, 0.0); glEndList();

Step 3: Remove translation Original code: glPushMatrix(); glTranslatef(-3.0, -2.0, 0.0); glRotatef(angle, 0.0, 0.0, 1.0); glCallList(gear1); glPopMatrix(); Modified code: glPushMatrix(); glTranslatef(0.0, 0.0, 0.0); // or just remove altogether glRotatef(angle, 0.0, 0.0, 1.0); glCallList(gear1); glPopMatrix();

Step 4: Change rotation axes Original code (all rotating about z-axis): Gear1: glRotatef(angle, 0.0, 0.0, 1.0); Gear2: glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); Gear3: glRotatef(-2.0 * angle , 0.0, 0.0, 1.0); Modified code: Gear1: glRotatef(angle, 0.0, 1.0, 1.0); Gear2: glRotatef(-2.0 * angle - 9.0, 1.0, 1.0, 0.0); Gear3: glRotatef(-2.0 * angle , 1.0, 0.0, 1.0);

Step 5: Add fourth gear Code to add: //(define new color, “yellow”) static GLfloat yellow[4] = {1.0, 1.0, 0.0, 1.0}; … gear4 = glGenLists(1); glNewList(gear4, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, yellow); gear(7.0, 7.5, 1.0, 20, 0.0); glEndList(); glEnable(GL_NORMALIZE); … glPushMatrix(); glRotatef(-2.0 * angle , 0.0, 1.0, 0.0); glCallList(gear4); glPopMatrix();

Step 6: Resize window Code to add: glutInitWindowSize(700, 700); glutInitWindowPosition(100,150);

Step 7: Begin to construct base Code to add: static GLint gear5; // "holder"-- non-rotating gear … static GLfloat slate[4] = {0.4, 0.5, 0.6, 1.0); … gear5 = glGenLists(1); glNewList(gear5, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, slate); gear(8.0, 8.5, 1.0, 20, 0.0); glEndList(); glEnable(GL_NORMALIZE); … //in draw() glCallList(gear5); // no rotation matrix

Step 8: Define background color Code to add: //in draw() glClearColor(0.0f, 0.1f, 0.3f, 0.0f);

Step 9: Add pod Code to add: //(define new color, white) static GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; … pod = glGenLists(1); glNewList(pod, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white); glutSolidSphere(0.3, 15, 15); glEndList(); … //(in draw()) glCallList(pod);

Step 10: Change camera rotation Original Code: static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; Modified Code: static GLfloat view_rotx = 105.0, view_roty = 0.0, view_rotz = 45.0; Rotation variables are used in draw() to set up camera angle with each redraw, and can be modified using the key() function.

Step 11: Add base supports Code to add: // in draw() glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, slate); glTranslatef(0.0, 8.0, 0.0); glutSolidCube(1.5); glTranslatef(0.0, 0.0, 1.5); glutSolidCube(1.8); glTranslatef(0.0, 0.0, 1.8); glutSolidCube(2.1); glTranslatef(0.0, 0.0, 2.1); glutSolidCube(2.4); glTranslatef(0.0, 0.0, 2.4); glutSolidCube(2.7); GlPopMatrix(); // repeat for other 3 legs with appropriate translation values

Step 12: Zoom out for default view Original code: static void reshape(int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; glViewport(0, 0, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -40.0); } Modified line: glTranslatef(0.0, 2.0, -50.0);

Step 13: Add key-controlled zoom Original code: static void key(char k...) { switch (k) { case 'z': view_rotz += 5.0; break; case 'Z': view_rotz -= 5.0; break; case 27: /* Escape */ exit(0); break; default: return; } glutPostRedisplay(); } Modified line: // added two cases and converted z-axis camera // translation to a variable, view_zoom. case 'i': view_zoom += 0.2; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 2.0, view_zoom); break; case 'o': view_zoom -= 0.2; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 2.0, view_zoom); break;

Source: “gears.h” by Brian Paul, converted to GLUT by Mark J. Kilgard Retrieved from Dr. Wright's ACL directory