Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 15 March 2006 EventPro Strategies is looking for a part-time programmer (any language) who knows SQL. For more info, contact Ryan Taylor, ryan@eventprostrategies.com.

Similar presentations


Presentation on theme: "Chapter 4 15 March 2006 EventPro Strategies is looking for a part-time programmer (any language) who knows SQL. For more info, contact Ryan Taylor, ryan@eventprostrategies.com."— Presentation transcript:

1 Chapter 4 15 March 2006 EventPro Strategies is looking for a part-time programmer (any language) who knows SQL. For more info, contact Ryan Taylor,

2 Agenda Chapter 4 – Math for Computer Graphics GLUT solids

3 Transformations 45-degree counterclockwise rotation about the origin around the z-axis a translation down the x-axis Thinking about Transformations Let's start with a simple case of two transformations: a 45-degree counterclockwise rotation about the origin around the z-axis, and a translation down the x-axis. Suppose that the object you're drawing is small compared to the translation (so that you can see the effect of the translation), and that it's originally located at the origin. If you rotate the object first and then translate it, the rotated object appears on the x-axis. If you translate it down the x-axis first, however, and then rotate about the origin, the object is on the line y=x, as shown in Figure 3-4. In general, the order of transformations is critical. If you do transformation A and then transformation B, you almost always get something different than if you do them in the opposite order.

4 Order of transformations
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(); Now let's talk about the order in which you specify a series of transformations. All viewing and modeling transformations are represented as 4 × 4 matrices. Each successive glMultMatrix*() or transformation command multiplies a new 4 × 4 matrix M by the current modelview matrix C to yield CM. Finally, vertices v are multiplied by the current modelview matrix. This process means that the last transformation command called in your program is actually the first one applied to the vertices: CMv. Thus, one way of looking at it is to say that you have to specify the matrices in the reverse order. Like many other things, however, once you've gotten used to thinking about this correctly, backward will seem like forward. With this code, the modelview matrix successively contains I, N, NM, and finally NML, where I represents the identity matrix. The transformed vertex is NMLv. Thus, the vertex transformation is N(M(Lv)) - that is, v is multiplied first by L, the resulting Lv is multiplied by M, and the resulting MLv is multiplied by N. Notice that the transformations to vertex v effectively occur in the opposite order than they were specified. (Actually, only a single multiplication of a vertex by the modelview matrix occurs; in this example, the N, M, and L matrices are already multiplied into a single matrix before it's applied to v.) transformed vertex is NMLv

5 Translation 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

6 Rotation 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. Note that an object that lies farther from the axis of rotation is more dramatically rotated (has a larger orbit) than an object drawn near the axis. Also, if the angle argument is zero, the glRotate*() command has no effect.

7 Scale void glScale{fd} (TYPEx, TYPE y, TYPEz);
Multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axes. Each x, y, and z coordinate of every point in the object is multiplied by the corresponding argument x, y, or z. With the local coordinate system approach, the local coordinate axes are stretched, shrunk, or reflected by the x, y, and z factors, and the associated object is transformed with them. This figure shows the effect of glScalef(2.0, -0.5, 1.0). glScale*() is the only one of the three modeling transformations that changes the apparent size of an object: Scaling with values greater than 1.0 stretches an object, and using values less than 1.0 shrinks it. Scaling with a -1.0 value reflects an object across an axis. The identity values for scaling are (1.0, 1.0, 1.0). In general, you should limit your use of glScale*() to those cases where it is necessary. Using glScale*() decreases the performance of lighting calculations, because the normal vectors have to be renormalized after transformation.

8 Vectors N tuple of real numbers (n = 2 for 2D, n = 3 for 3D)
directed line segment example velocity vector (speed and direction) operations addition multiplication by a scalar dot product

9 Vectors Vector and Vector Algebra
= 5

10 Matrices Rectangular array of numbers Addition QuickMath
(1*cos a) + (0*0) + (0*-sina)+0*0 = cos a row of first operand * column of second Cos a 0 sin a 0 m -sina/k 0 cosa/k n/k + 1

11 Matrices A vector in 3 space is a n x 1 matrix or column vector. 1 3
(1*cos a) + (0*0) + (0*-sina)+0*0 = cos a row of first operand * column of second Cos a 0 sin a 0 m -sina/k 0 cosa/k n/k + 1 1 3

12 Matrices Multiplication 1 0 0 0 0 1 0 0 x 0 0 0 0 0 0 1/k 1
(1*cos a) + (0*0) + (0*-sina)+0*0 = cos a row of first operand * column of second Cos a 0 sin a 0 m -sina/k 0 cosa/k n/k + 1 x /k 1 Cos α 0 sin α 0 m -sin α 0 cos α n

13 Matrix 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 Think of rows of matric a as being vectore and columns of matrix b then multiply together to cij is just A . B the dot product of a and B two n dimensional vectors x and y have the dot oproduct x1y1 + … + xnyn

14 Matrix multiplication
cij = ais bsj s=1 c11 c c c14 c21 c c c24 c31 c c c34 c41 c c c44 Think of rows of matric a as being vectore and columns of matrix b then multiply together to cij is just A . B the dot product of a and B two n dimensional vectors x and y have the dot oproduct x1y1 + … + xnyn x /k 1 Cos α 0 sin α 0 m -sin α 0 cos α n a b

15 2D Transformations Translation: Pf = T + P Rotation: Pf = R · P
xf = 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

16 Homogeneous 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

17 Homogeneous Coordinates
dx x dy · y Apply translation of 3, -4 7,1 10,1 4,5 7,5

18 Homogeneous Coordinates
sx x 0 sy · y Scale by 1/2 in x and 1/4 in y 4,5 7,5 2,5/ /2,5/4

19 Homogeneous Coordinates
Cos -sin 0 x sin cos 0 · y Rotation by 45 degrees 2.1, , 7.8 4,5 7,5

20 Combining 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

21 GLUT Solids Sphere Cube Cone Torus Dodecahedron Octahedron Tetrahedron
Icosahedron Teapot GLUT includes a number of routines for generating easily recognizable 3D geometric objects. These routines reflect functionality available in the aux toolkit described in the OpenGL Programmer's Guide and are included in GLUT to allow the construction of simple GLUT programs that render recognizable objects. These routines can be implemented as pure OpenGL rendering routines. The routines do not generate display lists for the objects they create.

22 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). Renders a sphere centered at the modeling coordinates origin of the specified radius. The sphere is subdivided around the Z axis into slices and along the Z axis into stacks.

23 glutSolidCube and glutWireCube
Description glutSolidCube and glutWireCube render a solid or wireframe cube respectively. The cube is centered at the modeling coordinates origin with sides of length size. void glutSolidCube(GLdouble size); size – length of sides

24 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. glutSolidCone and glutWireCone render a solid or wireframe cone respectively oriented along the Z axis. The base of the cone is placed at Z = 0, and the top at Z = height. The cone is subdivided around the Z axis into slices, and along the Z axis into stacks.

25 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. glutSolidTorus and glutWireTorus render a solid or wireframe torus (doughnut) respectively centered at the modeling coordinates origin whose axis is aligned with the Z axis.

26 glutSolidDodecahedron and glutWireDodecahedron
void glutSolidDodecahedron(void); glutSolidDodecahedron and glutWireDodecahedron render a solid or wireframe dodecahedron (12-sided regular solid) respectively. glutSolidDodecahedron and glutWireDodecahedron render a solid or wireframe dodecahedron respectively centered at the modeling coordinates origin with a radius of the square root of 3.

27 glutSolidOctahedron and glutWireOctahedron .
void glutSolidOctahedron(void); glutSolidOctahedron and glutWireOctahedron render a solid or wireframe octahedron (8-sided regular solid) respectively. glutSolidOctahedron and glutWireOctahedron render a solid or wireframe octahedron respectively centered at the modeling coordinates origin with a radius of 1.0.

28 glutSolidTetrahedron and glutWireTetrahedron
glutSolidTetrahedron and glutWireTetrahedron render a solid or wireframe tetrahedron (4-sided regular solid) respectively. Usage void glutSolidTetrahedron(void); void glutWireTetrahedron(void); Description glutSolidTetrahedron and glutWireTetrahedron render a solid or wireframe tetrahedron respectively centered at the modeling coordinates origin with a radius of . void glutSolidTetrahedron(void);

29 glutSolidIcosahedron and glutWireIcosahedron
void glutSolidIcosahedron(void); glutSolidIcosahedron and glutWireIcosahedron render a solid or wireframe icosahedron (20-sided regular solid) respectively. Usage void glutSolidIcosahedron(void); void glutWireIcosahedron(void); Description glutSolidIcosahedron and glutWireIcosahedron render a solid or wireframe icosahedron respectively. The icosahedron is centered at the modeling coordinates origin and has a radius of 1.0.

30 glutSolidTeapot and glutWireTeapot
void glutSolidTeapot(GLdouble size); size - Relative size of the teapot. glutSolidTeapot and glutWireTeapot render a solid or wireframe teapot respectively. Usage void glutSolidTeapot(GLdouble size); void glutWireTeapot(GLdouble size); size Relative size of the teapot. Description glutSolidTeapot and glutWireTeapot render a solid or wireframe teapot respectively. Both surface normals and texture coordinates for the teapot are generated. The teapot is generated with OpenGL evaluators.

31 Homework next week. Study for Test on Chapters 1-4, 02/15/05


Download ppt "Chapter 4 15 March 2006 EventPro Strategies is looking for a part-time programmer (any language) who knows SQL. For more info, contact Ryan Taylor, ryan@eventprostrategies.com."

Similar presentations


Ads by Google