44
Geometric Objects and Transformations Chapter 4

Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors Points - position in space Scalars - real numbers, complex numbers obey

Embed Size (px)

Citation preview

Page 1: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Geometric Objects and Transformations

Geometric Objects and Transformations

Chapter 4Chapter 4

Page 2: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Points, Scalars and Vectors

Points, Scalars and Vectors

Points - position in space Scalars - real numbers, complex

numbers obey a set of rules that are abstractions of arithmetic store values such as distance

Vectors - directed line segment

Points - position in space Scalars - real numbers, complex

numbers obey a set of rules that are abstractions of arithmetic store values such as distance

Vectors - directed line segment

Page 3: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Vector ArithmeticVector Arithmetic

B = 2A C = A + B

Head to tail rule E = -A

Inverse Zero vector = E + A

B = 2A C = A + B

Head to tail rule E = -A

Inverse Zero vector = E + A

Page 4: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Point ArithmeticPoint Arithmetic

Can’t add p1 + p2 = p3 Can’t multiply p1 * 2 = p2 What can you do to produce a 2nd

point from a 1st? p1 + V = p2 V = p2 - p1

Can’t add p1 + p2 = p3 Can’t multiply p1 * 2 = p2 What can you do to produce a 2nd

point from a 1st? p1 + V = p2 V = p2 - p1

Page 5: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Important Vector ConceptsImportant Vector Concepts

Normal Vector A vector at a right angle to a surface. Graphics Usage of Normal Vector

Used to figure out similarity of direction which is necessary for lighting

More precisely, how much light should fall on a surface is calculated by the similarity of the surface normal and the vector between the light source and the surface.

Similarity of direction = vector dot product

Normal Vector A vector at a right angle to a surface. Graphics Usage of Normal Vector

Used to figure out similarity of direction which is necessary for lighting

More precisely, how much light should fall on a surface is calculated by the similarity of the surface normal and the vector between the light source and the surface.

Similarity of direction = vector dot product

Page 6: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey
Page 7: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Vector Dot ProductVector Dot Product

For vectors of length 1 (unit vectors), the dot product is the length of the projection of one vector onto the other.

If the dot product = 1: the vectors point in the same direction 0: the vectors are at right angles -1: the vectors point in opposite directions

For vectors of length 1 (unit vectors), the dot product is the length of the projection of one vector onto the other.

If the dot product = 1: the vectors point in the same direction 0: the vectors are at right angles -1: the vectors point in opposite directions

Page 8: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Vector Cross ProductVector Cross Product

The cross product of two vectors A and B is another vector at right angles to the plane created by A and B

The cross product of two vectors A and B is another vector at right angles to the plane created by A and B

Page 9: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Defining a Coordinate Space

Defining a Coordinate Space

Need to know 1. The origin (or displacement vector)2. The basis vectors - The direction and distance

for +1 movement along each axis This definition is relative To plot a point

1. Begin at origin2. Travel along the x basis vector [direction]

scaled by x coord, then along the y basis vector scaled by the y coord, then finally along the z basis vector scaled by the z coord.

Need to know 1. The origin (or displacement vector)2. The basis vectors - The direction and distance

for +1 movement along each axis This definition is relative To plot a point

1. Begin at origin2. Travel along the x basis vector [direction]

scaled by x coord, then along the y basis vector scaled by the y coord, then finally along the z basis vector scaled by the z coord.

Page 10: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

TransformationsTransformations

Prior to rendering: view, locate and orient eye / camera position 3D geometry

Manage the matrices including the matrix stack

Combine (composite) transformations

Prior to rendering: view, locate and orient eye / camera position 3D geometry

Manage the matrices including the matrix stack

Combine (composite) transformations

Page 11: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Camera AnalogyCamera Analogy

Page 12: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Stages of Vertex TransformationStages of Vertex Transformation

Page 13: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

TransformationsTransformations

45-degree counterclockwise rotation about the origin around the z-axis

a translation down the x-axis

45-degree counterclockwise rotation about the origin around the z-axis

a translation down the x-axis

Page 14: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Order of TransformationsOrder of Transformations

transformed vertex is NMLv transformed vertex is NMLv

glMatrixMode(GL_MODELVIEW);glLoadIdentity();glMultMatrixf(N); /* apply transformation N */glMultMatrixf(M); /* apply transformation M */glMultMatrixf(L); /* apply transformation L */glBegin(GL_POINTS);

glVertex3f(v); /* draw transformed vertex v */glEnd();

Page 15: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

TranslationTranslation

void glTranslate{fd} (TYPE x, TYPE y, TYPE z);

Multiplies the current matrix by a matrix that moves (translates) an object by the given x, y, and z values

void glTranslate{fd} (TYPE x, TYPE y, TYPE z);

Multiplies the current matrix by a matrix that moves (translates) an object by the given x, y, and z values

Page 16: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

RotationRotation

void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z);

Multiplies the current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from the origin through the point (x, y, z). The angle parameter specifies the angle of rotation in degrees.

void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z);

Multiplies the current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from the origin through the point (x, y, z). The angle parameter specifies the angle of rotation in degrees.

Page 17: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

ScaleScale

void glScale{fd} (TYPEx, TYPE y, TYPEz);

Multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axes.

void glScale{fd} (TYPEx, TYPE y, TYPEz);

Multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axes.

Page 18: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

VectorsVectors

1 2 32 + 3 = 53 4 7

Page 19: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

MatricesMatrices

Rectangular array of numbers A vector in 3 space is a n x 1

matrix or column vector. Multiplication

Rectangular array of numbers A vector in 3 space is a n x 1

matrix or column vector. Multiplication

1 0 0 00 1 0 0 x 0 0 0 00 0 1/k 1

Cos α 0 sin α 0 0 1 0 m-sin α 0 cos α n 0 0 0 1

131

Page 20: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Matrix MultiplicationMatrix Multiplication

A is an n x m matrix with entries aij

B is an m x p matrix with entries bij

AB is an n x p matrix with entries cij

m

cij = ais bsj

s=1

A is an n x m matrix with entries aij

B is an m x p matrix with entries bij

AB is an n x p matrix with entries cij

m

cij = ais bsj

s=1

Page 21: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

2D Transformations2D Transformations

Translation: Pf = T + Pxf = xo + dx

yf = yo + dy Rotation: Pf = R · P

xf = xo * cos - yo *sin

yf = xo * sin + yo *cos Scale: Pf = S · P

xf = sx * xo

yf = sy * yo

Translation: Pf = T + Pxf = xo + dx

yf = yo + dy Rotation: Pf = R · P

xf = xo * cos - yo *sin

yf = xo * sin + yo *cos Scale: Pf = S · P

xf = sx * xo

yf = sy * yo

Page 22: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Homogeneous CoordinatesHomogeneous Coordinates

Want to treat all transforms in a consistent way so they can be combined easily

Developed in geometry (‘46 in cambridge) and applied to graphics

Add a third coordinate to a point (x, y, w) (x1, y1, w1) is the same point as (x2, y2,

w2) if one is a multiple of another Homogenize a point by dividing by w

Want to treat all transforms in a consistent way so they can be combined easily

Developed in geometry (‘46 in cambridge) and applied to graphics

Add a third coordinate to a point (x, y, w) (x1, y1, w1) is the same point as (x2, y2,

w2) if one is a multiple of another Homogenize a point by dividing by w

Page 23: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Homogeneous CoordinatesHomogeneous Coordinates

1 0 dx x

0 1 dy · y

0 0 1 1

1 * x + 0 * y + dx * 10 * x + 1 * y + dy * 10 * x + 0 * y + 1 * 1

1 0 dx x

0 1 dy · y

0 0 1 1

1 * x + 0 * y + dx * 10 * x + 1 * y + dy * 10 * x + 0 * y + 1 * 1

Page 24: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Homogeneous CoordinatesHomogeneous Coordinates

1 0 dx x

0 1 dy · y

0 0 1 1

1 0 dx x

0 1 dy · y

0 0 1 1

Page 25: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Homogeneous CoordinatesHomogeneous Coordinates

sx 0 0 x

0 sy 0 · y

0 0 1 1

sx 0 0 x

0 sy 0 · y

0 0 1 1

Page 26: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Homogeneous CoordinatesHomogeneous Coordinates

Cos -sin 0 x

sin cos 0 · y

0 0 1 1

Cos -sin 0 x

sin cos 0 · y

0 0 1 1

Page 27: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Homogeneous CoordinatesHomogeneous Coordinates

1 0 0 x x

0 1 0 · y = y

0 0 1 1 1

Identity Maxtrix x point p = point p

1 0 0 x x

0 1 0 · y = y

0 0 1 1 1

Identity Maxtrix x point p = point p

Page 28: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Combining 2D TransformationsCombining 2D

Transformations Rotate a house about the origin Rotate the house about one of its

corners translate so that a corner of the

house is at the origin rotate the house about the origin translate so that the corner returns to

its original position

Rotate a house about the origin Rotate the house about one of its

corners translate so that a corner of the

house is at the origin rotate the house about the origin translate so that the corner returns to

its original position

Page 29: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

OpenGL BuffersOpenGL Buffers

Color can be divided into front and back for

double buffering Alpha Depth Stencil Accumulation

Color can be divided into front and back for

double buffering Alpha Depth Stencil Accumulation

Page 30: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Double BufferingDouble Buffering

Page 31: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Animating Using Double Buffering

Animating Using Double Buffering

Request a double buffered color bufferglutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);

Clear color buffer glClear(GL_COLOR_BUFFER_BIT);

Render Scene Request swap of front and back buffers

glutSwapBuffers();

Repeat steps 2-4 for animation.

Request a double buffered color bufferglutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);

Clear color buffer glClear(GL_COLOR_BUFFER_BIT);

Render Scene Request swap of front and back buffers

glutSwapBuffers();

Repeat steps 2-4 for animation.

Page 32: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

Depth BufferingDepth Buffering

Page 33: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

3D Coords --> Raster coords

3D Coords --> Raster coords

Transformations Clipping Viewport transformation.

Transformations Clipping Viewport transformation.

Page 34: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

GLUT SolidsGLUT Solids

Sphere Cube Cone Torus Dodecahedron Octahedron Tetrahedron Icosahedron Teapot

Sphere Cube Cone Torus Dodecahedron Octahedron Tetrahedron Icosahedron Teapot

Page 35: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidSphere and glutWireSphere

glutSolidSphere and glutWireSphere

void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);

radius - The radius of the sphere. slices - The number of subdivisions

around the Z axis (similar to lines of longitude).

stacks - The number of subdivisions along the Z axis (similar to lines of latitude).

void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);

radius - The radius of the sphere. slices - The number of subdivisions

around the Z axis (similar to lines of longitude).

stacks - The number of subdivisions along the Z axis (similar to lines of latitude).

Page 36: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidCube and glutWireCube

glutSolidCube and glutWireCube

void glutSolidCube(GLdouble size);

size – length of sides

void glutSolidCube(GLdouble size);

size – length of sides

Page 37: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidCone and glutWireCone

glutSolidCone and glutWireCone

void glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);

base - The radius of the base of the cone. height - The height of the cone. slices - The number of subdivisions around the

Z axis. stacks - The number of subdivisions along the

Z axis.

void glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);

base - The radius of the base of the cone. height - The height of the cone. slices - The number of subdivisions around the

Z axis. stacks - The number of subdivisions along the

Z axis.

Page 38: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidTorus and glutWireTorus

glutSolidTorus and glutWireTorus

void glutSolidTorus(GLdouble innerRadius,GLdouble outerRadius, GLint nsides, GLint rings);

innerRadius - Inner radius of the torus. outerRadius - Outer radius of the torus. nsides - Number of sides for each radial

section. rings - Number of radial divisions for

the torus.

void glutSolidTorus(GLdouble innerRadius,GLdouble outerRadius, GLint nsides, GLint rings);

innerRadius - Inner radius of the torus. outerRadius - Outer radius of the torus. nsides - Number of sides for each radial

section. rings - Number of radial divisions for

the torus.

Page 39: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidDodecahedron and

glutWireDodecahedron

glutSolidDodecahedron and

glutWireDodecahedron

void glutSolidDodecahedron(void);

void glutSolidDodecahedron(void);

Page 40: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidOctahedron and glutWireOctahedron .

glutSolidOctahedron and glutWireOctahedron .

void glutSolidOctahedron(void);

void glutSolidOctahedron(void);

Page 41: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidTetrahedron and glutWireTetrahedron

glutSolidTetrahedron and glutWireTetrahedron

void glutSolidTetrahedron(void);

void glutSolidTetrahedron(void);

Page 42: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidIcosahedron and glutWireIcosahedron

glutSolidIcosahedron and glutWireIcosahedron

void glutSolidIcosahedron(void); void glutSolidIcosahedron(void);

Page 43: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

glutSolidTeapot and glutWireTeapot

glutSolidTeapot and glutWireTeapot

void glutSolidTeapot(GLdouble size);

size - Relative size of the teapot.

void glutSolidTeapot(GLdouble size);

size - Relative size of the teapot.

Page 44: Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey

HomeworkHomework

Project part 2 due 2/19 Turn in a program that, at a

minimum, draws your initial scene.

Project part 2 due 2/19 Turn in a program that, at a

minimum, draws your initial scene.