CS452/552; EE465/505. Transformations

Similar documents
Introduction to Computer Graphics with WebGL

Introduction to Computer Graphics with WebGL

CS452/552; EE465/505. Models & Viewing

Transformations. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Transformations. Prof. George Wolberg Dept. of Computer Science City College of New York

Transformations II. Arbitrary 3D Rotation. What is its inverse? What is its transpose? Can we constructively elucidate this relationship?

CS452/552; EE465/505. Review & Examples

CS 4204 Computer Graphics

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Building Models. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Order of Transformations

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CSC 470 Computer Graphics

Building Models. Objectives Introduce simple data structures for building polygonal models. Vertex lists Edge lists

Lecture 4: Transformations and Matrices. CSE Computer Graphics (Fall 2010)

CS452/552; EE465/505. Image Formation

Lecture 9: Transformations. CITS3003 Graphics & Animation

Introduction to Computer Graphics with WebGL

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Transformations. Standard Transformations. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E. Angel

CS D Transformation. Junqiao Zhao 赵君峤

CS452/552; EE465/505. Intro to Lighting

Transformations. Overview. Standard Transformations. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

Transformations. Rotation and Scaling

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Transformations Computer Graphics I Lecture 4

Computer Graphics Geometric Transformations

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL

Computer Graphics. Chapter 7 2D Geometric Transformations

Transformations Computer Graphics I Lecture 4

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Programming with OpenGL Complete Programs Objectives Build a complete first program

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

CS452/552; EE465/505. Geometry Transformations

Announcement. Project 1 has been posted online and in dropbox. Due: 11:59:59 pm, Friday, October 14

Computer Science 336 Fall 2017 Homework 2

Introduction to Computer Graphics with WebGL

CS452/552; EE465/505. Image Processing Frame Buffer Objects

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

We assume that you are familiar with the following:

CS 432 Interactive Computer Graphics

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

Transformations Week 9, Lecture 18

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Computer Graphics 7: Viewing in 3-D

CS452/552; EE465/505. Lighting & Shading

GEOMETRIC TRANSFORMATIONS AND VIEWING

Graphics and Interaction Transformation geometry and homogeneous coordinates

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

CS Computer Graphics: Transformations & The Synthetic Camera

CS559 Computer Graphics Fall 2015

Last week. Machiraju/Zhang/Möller/Fuhrmann

3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. x y z. x y z. glvertex3f(x, y,z);

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

Affine Transformation. Edith Law & Mike Terry

Introduction to Computer Graphics with WebGL

Transformations. CSCI 420 Computer Graphics Lecture 5

Transformations. OpenGL Transformations. 4x4 Model-view Matrix (this lecture) OpenGL Transformation Matrices. 4x4 Projection Matrix (next lecture)

UNIT 2 2D TRANSFORMATIONS

Three Main Themes of Computer Graphics

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

OPENGL RENDERING PIPELINE

Review of Thursday. xa + yb xc + yd

Transformations. CSCI 420 Computer Graphics Lecture 4

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Vector Algebra Transformations. Lecture 4

2D and 3D Transformations AUI Course Denbigh Starkey

Computer Graphics: Viewing in 3-D. Course Website:

EECE 478. Learning Objectives. Learning Objectives. Linear Algebra and 3D Geometry. Linear algebra in 3D. Coordinate systems

Programming with WebGL Part 1: Background. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Transforms. COMP 575/770 Spring 2013

CS452/552; EE465/505. Texture Mapping in WebGL

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

2D/3D Geometric Transformations and Scene Graphs

Fall CSCI 420: Computer Graphics. 2.2 Transformations. Hao Li.

Affine Transformations in 3D

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CSCI E-74. Simulation and Gaming

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

Overview. Affine Transformations (2D and 3D) Coordinate System Transformations Vectors Rays and Intersections

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

Hello, welcome to the video lecture series on Digital Image Processing. So in today's lecture

Introduction to OpenGL

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Lecture 6 Sections 4.3, 4.6, 4.7. Wed, Sep 9, 2009

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

INF3320 Computer Graphics and Discrete Geometry

Lecture 5: Transforms II. Computer Graphics and Imaging UC Berkeley CS184/284A

The Graphics Pipeline and OpenGL I: Transformations!

CS 428: Fall Introduction to. Transformations in OpenGL + hierarchical modeling. Andrew Nealen, Rutgers, /21/2009 1

Transcription:

CS452/552; EE465/55 Transformations 1-29-15

Outline! Transformations Read: Angel, Chapter 4 (study cube.html/cube.js example) Helpful links: Linear Algebra: Khan Academy Lab1 is posted on github, due: Friday, 1/3, midnight Lab2: use ASDW to move a 2D shape around

Recap: Translation Matrix We can express translation using a 4 x 4 matrix T in homogeneous coordinates p =Tp where T = T(d x, d y, d z ) = & 1 $ $ $ $ % 1 1 This form is better for implementation because all affine transformations can be expressed this way and multiple transformations can be concatenated together d d d x y z 1 #!!!! " Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Translation! Move the origin to a new location!!!!!! " # $ $ $ $ $ $ % & = 1 1 1 1 ),, ( z y x z y x t t t t t t T

Rotation (2D) Consider rotation about the origin by θ degrees radius stays the same, angle increases by θ x = r cos (φ + θ) y = r sin (φ + θ) x = x cos θ y sin θ y = x sin θ + y cos θ x = r cos φ y = r sin φ Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation about the z axis! Rotation about z axis in three dimensions leaves all points with the same z Equivalent to rotation in two dimensions in planes of constant z x = x cos θ y sin θ y = x sin θ + y cos θ z = z or in homogeneous coordinates p =R z (θ)p Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

R = R z (θ) = Rotation Matrix!!!! " # $ $ $ $ % & θ θ θ θ 1 1 cos sin sin cos Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation about x and y axes! Same argument as for rotation about z axis For rotation about x axis, x is unchanged For rotation about y axis, y is unchanged & 1 # $ cos θ - sin θ $ R = R x (θ) = $ sin θ cos θ $!!!! % 1" & cos θ sin θ # $ R = R y (θ) = 1 $ $ - sin θ cos θ $!!!! % 1" Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Scaling Expand or contract along each axis (fixed point of origin) x =s x x y =s y y z =s z z p =Sp S = S(s x, s y, s z ) = & sx $ $ $ $ % s y s z #!!!! 1" Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Reflection corresponds to negative scale factors s x = -1 s y = 1 original s x = -1 s y = -1 s x = 1 s y = -1 Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Inverses! Although we could compute inverse matrices by general formulas, we can use simple geometric observations Translation: T -1 (d x, d y, d z ) = T(-d x, -d y, -d z ) Rotation: R -1 (θ) = R(-θ) Holds for any rotation matrix Note that since cos(-θ) = cos(θ) and sin(-θ)=-sin(θ) R -1 (θ) = R T (θ) Scaling: S -1 (s x, s y, s z ) = S(1/s x, 1/s y, 1/s z ) Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Concatenation! We can form arbitrary affine transformation matrices by multiplying together rotation, translation, and scaling matrices! Because the same transformation is applied to many vertices, the cost of forming a matrix M=ABCD is not significant compared to the cost of computing Mp for many vertices p! The difficult part is how to form a desired transformation from the specifications in the application Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Order of Transformations! Note that matrix on the right is the first applied! Mathematically, the following are equivalent p = ABCp = A(B(Cp))! Note many references use column matrices to represent points. In terms of column matrices p T = p T C T B T A T Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

MATRIX ORDER Multiply left to right Results are drastically different (an angry vertex) JEFF CHASTINE

MATRIX ORDER Multiply left to right Results are drastically different Order of operations Rotate 45 JEFF CHASTINE

MATRIX ORDER Multiply left to right Results are drastically different Order of operations Rotate 45 Translate 1 units JEFF CHASTINE

MATRIX ORDER Multiply left to right Results are drastically different Order of operations Rotate 45 Translate 1 units before after JEFF CHASTINE

MATRIX ORDER Multiply left to right Results are drastically different Order of operations JEFF CHASTINE

MATRIX ORDER Multiply left to right Results are drastically different Order of operations Translate 1 units JEFF CHASTINE

MATRIX ORDER Multiply left to right Results are drastically different Order of operations Translate 1 units Rotate 45 JEFF CHASTINE

MATRIX ORDER Multiply left to right Results are drastically different Order of operations Translate 1 units Rotate 45 after before JEFF CHASTINE

General Rotation About the Origin! A rotation by θ about an arbitrary axis can be decomposed into the concatenation of rotations about the x, y, and z axes R(θ) = R z (θ z ) R y (θ y ) R x (θ x ) y θ v θ x θ y θ z are called the Euler angles x Note that rotations do not commute We can use rotations in another order but with different angles z Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation About a Fixed Point other than the Origin Move fixed point to origin Rotate Move fixed point back M = T(p f ) R(θ) T(-p f ) Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

WebGL Transformations! Learn how to carry out transformations in WebGL Rotation Translation Scaling! Introduce MV.js transformations Model-view Projection Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215 3 24

The Big Picture! How to we get from space to space?! For every model Have a (M)odel matrix! Transforms from object to world space M? Jeff Chastine

The Big Picture! How to we get from space to space?! To put in camera space Have a (V)iew matrix Usually need only one of these M V Jeff Chastine

The Big Picture! How to we get from space to space?! The ModelView matrix Sometimes these are combined into one matrix Usually keep them separate for convenience M V MV Jeff Chastine

Back to The Big Picture! How might we make the model matrix? M Jeff Chastine

Back to The Big Picture! How might we make the model matrix? M Translation matrix T Rotation matrix R 1 Rotation matrix R 2 Scale matrix S Jeff Chastine

Back to The Big Picture! How might we make the model matrix? M Translation matrix T Rotation matrix R 1 Rotation matrix R 2 Scale matrix S T * R 1 * R 2 * S = M Jeff Chastine

Pre 3.1 OpenGL Matrices! In Pre 3.1 OpenGL matrices were part of the state! Multiple types Model-View (GL_MODELVIEW) Projection (GL_PROJECTION) Texture (GL_TEXTURE) Color(GL_COLOR)! Single set of functions for manipulation! Select which to manipulated by glmatrixmode(gl_modelview); glmatrixmode(gl_projection); Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Why Deprecation! Functions were based on carrying out the operations on the CPU as part of the fixed function pipeline! Current model-view and projection matrices were automatically applied to all vertices using CPU! We will use the notion of a current transformation matrix with the understanding that it may be applied in the shaders Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Current Transformation Matrix (CTM)! Conceptually there is a 4 x 4 homogeneous coordinate matrix, the current transformation matrix (CTM) that is part of the state and is applied to all vertices that pass down the pipeline! The CTM is defined in the user program and loaded into a transformation unit p C p =Cp vertices CTM vertices Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

CTM operations! The CTM can be altered either by loading a new CTM or by postmutiplication Load an identity matrix: C I Load an arbitrary matrix: C M Load a translation matrix: C T Load a rotation matrix: C R Load a scaling matrix: C S Postmultiply by an arbitrary matrix: C CM Postmultiply by a translation matrix: C CT Postmultiply by a rotation matrix: C C R Postmultiply by a scaling matrix: C C S Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation about a Fixed Point Start with identity matrix: C I Move fixed point to origin: C CT Rotate: C CR Move fixed point back: C CT -1 Result: C = TR T 1 which is backwards. This result is a consequence of doing postmultiplications. Let s try again. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Reversing the Order We want C = T 1 R T so we must do the operations in the following order C I C CT -1 C CR C CT Each operation corresponds to one function call in the program. Note that the last operation specified is the first executed in the program Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

CTM in WebGL! OpenGL had a model-view and a projection matrix in the pipeline which were concatenated together to form the CTM! We will emulate this process Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Using the ModelView Matrix! In WebGL, the model-view matrix is used to Position the camera Can be done by rotations and translations but is often easier to use the lookat function in MV.js Build models of objects! The projection matrix is used to define the view volume and to select a camera lens! Although these matrices are no longer part of the OpenGL state, it is usually a good strategy to create them in our own applications q = P*MV*p Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation, Translation, Scaling Create an identity matrix: var m = mat4(); Multiply on right by rotation matrix of theta in degrees where (vx, vy, vz) define axis of rotation var r = rotate(theta, vx, vy, vz) m = mult(m, r); Also have rotatex, rotatey, rotatez Do same with translation and scaling: var s = scale( sx, sy, sz) var t = translate(dx, dy, dz); m = mult(s, t); Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Example using MV.js! Rotation about z axis by 3 degrees with a fixed point of (1., 2., 3.) var m = mult(translate(1., 2., 3.), rotate(3.,.,., 1.)); m = mult(m, translate(-1., -2., -3.));! Remember that last matrix specified in the program is the first applied Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Arbitrary Matrices! Can load and multiply by matrices defined in the application program! Matrices are stored as one dimensional array of 16 elements by MV.js but can be treated as 4 x 4 matrices in row major order! OpenGL wants column major data! gl.unifrommatrix4f has a parameter for automatic transpose but it must be set to false.! flatten function converts to column major order which is required by WebGL functions Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Matrix Stacks! In many situations we want to save transformation matrices for use later Traversing hierarchical data structures (Chapter 9)! Pre 3.1 OpenGL maintained stacks for each type of matrix! Easy to create the same functionality in JS push and pop are part of Array object var stack = [ ] stack.push(modelviewmatrix); modelviewmatrix = stack.pop(); Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Examples! TranslatedTriangle! ScaledTriangle_Matrix! RotatedTriangle_Matrix! TranslatedRotatedTriangle! RotatingTranslatedTriangle available on website https://sites.google.com/site/webglbook/ 43

TranslatedTriangle! Vertex Shader attribute vec4 a_position; uniform vec4 u_translation; void main() { } gl_position = a_position + u_translation; 44

TranslatedTriangle, cont. var vertices = new Float32Array([,.5, -.5, -.5,.5, -.5]); var vertexbuffer = gl.createbuffer(); // Create a buffer object // Bind the buffer object to target & write data to the buffer gl.bindbuffer(gl.array_buffer, vertexbuffer); gl.bufferdata(gl.array_buffer, vertices, gl.static_draw); // Assign the buffer object to the attribute variable var a_position = gl.getattriblocation(gl.program, 'a_position'); gl.vertexattribpointer(a_position, 2, gl.float, false,, ); // Enable the assignment to a_position variable gl.enablevertexattribarray(a_position);

TranslatedTriangle, cont. // The translation distance for x, y, and z direction var Tx =.5, Ty =.5, Tz =.; // Pass the translation distance to the vertex shader var u_translation = gl.getuniformlocation(gl.program, 'u_translation'); gl.uniform4f(u_translation, Tx, Ty, Tz,.);

ScaledTriangle_Matrix! Vertex Shader attribute vec4 a_position; uniform mat4 u_xformmatrix; void main() { } gl_position = u_xformmatrix * a_position; 47

ScaledTriangle_Matrix, cont. var Sx = 1., Sy = 1.5, Sz = 1.; // Note: WebGL is column major order var xformmatrix = new Float32Array([ Sx,.,.,.,., Sy,.,.,.,., Sz,.,.,.,., 1. ]); // Pass the rotation matrix to the vertex shader var u_xformmatrix = gl.getuniformlocation(gl.program, 'u_xformmatrix'); gl.uniformmatrix4fv(u_xformmatrix, false, xformmatrix);

RotatedTriangle_Matrix! Vertex Shader attribute vec4 a_position; uniform mat4 u_xformmatrix; void main() { } gl_position = u_xformmatrix * a_position; 49

RotatedTriangle_Matrix, cont. // Create Matrix4 object for the rotation matrix var xformmatrix = new Matrix4(); // Set the rotation matrix var ANGLE = 9.; // The rotation angle xformmatrix.setrotate(angle,,, 1); // Pass the rotation matrix to the vertex shader var u_xformmatrix = gl.getuniformlocation(gl.program, 'u_xformmatrix'); gl.uniformmatrix4fv(u_xformmatrix, false, xformmatrix.elements);

RotatedTriangle_Matrix, cont. // xformmatrix.setrotate(angle,,, 1); Matrix4.setRotate = function(angle, x, y, z) { s = Math.sin(angle); c = Math.cos(angle); see code in cuon-matrix.js Alternative: Angel MV.js

Example: Rotating Cube! Example: Begin with a cube rotating! Use mouse or button listener to change direction of rotation! Start with a program that draws a cube in a standard way Centered at origin Sides aligned with axes Will discuss modeling in next lecture! Two methods for display: vertices vs. indices Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Where do we apply transformation?! Same issue as with rotating square in application to vertices in vertex shader: send MV matrix in vertex shader: send angles! Choice between second and third unclear! Do we do trigonometry once in CPU or for every vertex in shader GPUs have trig functions hardwired in silicon Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation Event Listeners document.getelementbyid( "xbutton" ).onclick = function () { axis = xaxis; }; document.getelementbyid( "ybutton" ).onclick = function () { axis = yaxis; }; document.getelementbyid( "zbutton" ).onclick = function () { axis = zaxis; }; function render(){ gl.clear( gl.color_buffer_bit gl.depth_buffer_bit); theta[axis] += 2.; gl.uniform3fv(thetaloc, theta); gl.drawarrays( gl.triangles,, NumVertices ); requestanimframe( render ); } Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation Shader attribute vec4 vposition; attribute vec4 vcolor; varying vec4 fcolor; uniform vec3 theta; void main() { vec3 angles = radians( theta ); vec3 c = cos( angles ); vec3 s = sin( angles ); // Remember: these matrices are column-major mat4 rx = mat4( 1.,.,.,.,., c.x, s.x,.,., -s.x, c.x,.,.,.,., 1. ) Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Rotation Shader (cont) mat4 ry = mat4( c.y,., -s.y,.,., 1.,.,., s.y,., c.y,.,.,.,., 1. ); mat4 rz = mat4( c.z, -s.z,.,., s.z, c.z,.,.,.,., 1.,.,.,.,., 1. ); fcolor = vcolor; gl_position = rz * ry * rx * vposition; } Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Modeling a Cube Define global array for vertices var vertices = [ vec3( -.5, -.5,.5 ), vec3( -.5,.5,.5 ), vec3(.5,.5,.5 ), vec3(.5, -.5,.5 ), vec3( -.5, -.5, -.5 ), vec3( -.5,.5, -.5 ), vec3(.5,.5, -.5 ), vec3(.5, -.5, -.5 ) ]; Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Colors Define global array for colors var vertexcolors = [ [.,.,., 1. ], // black [ 1.,.,., 1. ], // red [ 1., 1.,., 1. ], // yellow [., 1.,., 1. ], // green [.,., 1., 1. ], // blue [ 1.,., 1., 1. ], // magenta [., 1., 1., 1. ], // cyan [ 1., 1., 1., 1. ] // white ]; Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215

Draw cube from faces function colorcube( ) { quad(,3,2,1); quad(2,3,7,6); quad(,4,7,3); quad(1,2,6,5); quad(4,5,6,7); quad(,1,5,4); } 1 5 6 2 7 4 3 Note that vertices are ordered so that we obtain correct outward facing normals. Each quad generates two triangles Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 215