1 / 51

CAP 4730 Computer Graphic Methods

CAP 4730 Computer Graphic Methods. Prof. Roy Levow Chapter 4. Geometry. Basic components Point Vector Line Segment Directed Line Segment Can be added head-to-tail Similar to vector addition but location of start of first segment is start of sum. Point-Vector Operations.

Download Presentation

CAP 4730 Computer Graphic Methods

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CAP 4730Computer Graphic Methods Prof. Roy Levow Chapter 4

  2. Geometry • Basic components • Point • Vector • Line Segment • Directed Line Segment • Can be added head-to-tail • Similar to vector addition but location of start of first segment is start of sum

  3. Point-Vector Operations • Inverse of a vector • reverses direction • Point + Vector • Gives new point at end of vector from original point • Interpret inverse Point – Point • to be vector from second point to first

  4. Scalar Operations • Scalar times vector is standard operation • Can take linear combination of points and vectors with scalar multipliers as long as net number of points is 1 • OK: P – 2 Q + 3v • Bad: 2 P – 4 Q

  5. Geometric Space • Coordinate-free system • Objects have no location • Scalar Field • add, subtract, multiply, divide • associative and commutative • Vector Space • Vectors and scalars as usual • Affine Space • Vector space plus points • point + vector; point - point

  6. Computational Framework • Magnitude of a vector • |αv| = |α| |v| • Lines • parametric form • P(α) = P0 + αv • affine addition • P = α1 R + α2 Q where α1 + α2 = 1

  7. Convexity • A polygon with vertices P1, …, Pn is convex precisely when all affine sums of the points P = α1 R + … + αn Pn are inside the figure when αi‘s sum to 1

  8. Dot and Cross Products • Dot (inner) Product • u∙v = sum ui vi • |u|2 = u∙u • cos θ = u∙v / |u||v| • Cross Product • n = u x v • orthogonal to plane of u-v • |sin θ | = |u x v| / |u||v| • Right hand rule • Using right hand, u is index, v is middle, n is thumb

  9. Plane • Affine sum of three non-colinear points • or point and two vectors • or solution to the equation • n ∙ (P – P0) = 0

  10. Three-Dimensonal Primitives • Curves • Surfaces • Volumetric Ojbects • Standard treatment • Objects are described by their surfaces and treated as hollow • Objects can be specifiedby vertices • Objects can be defined directly or approximated by flat convex polygons

  11. Coordinate Systemsand Frames • Any vector in 3-dimensions can be represented as a linear combination of any three lineraly independent vectors w = α1 v1 + α2 v2 + α3 v3 • If we fix the vectors v1, v2, v3 we call them a basis • we can represent a point by the coefficients a = (α1,α2,α3)T

  12. Coordinate Systemsand Frames • Conversely w = (α1,α2,α3) (v1, v2, v3)T • The basis vectors define a coordinate system • However, the basis vectors are not anchored and could be moved • Adding a point as the origin gives us a frame • Every point can then be written as P0 plus a linear combination of the basis vectors

  13. Representations • Any point can be represented as • a vector, from the origin • a 3-tuple of the coefficients for the basis

  14. Changes in Coordinate System • Suppose we have two bases • {u1, u2, u3} and {v1, v2, v3} • Each vector ui is a linear combination of the v’s • If M is the 3x3 matrix of coefficients, then (u1, u2, u3)T =M (v1, v2, v3)T • The inverse of M transforms from u’s to v’s

  15. Changing Coordinate System • If a is the coordinate vector for v’s and b is the coordinate vector for u’s then a = MT b • Changing the basis can effect rotation and scaling • Changing the basis leaves the origin unchanged

  16. Homogeneous Coordinates • We can include the origin in our calculation s by adding a 4th dimension for the origin, P0, and agreeing to multiply only by 1 except for the zero vector when we use 0 • Basis is now {v1, v2, v3 , P0} • Last column of transform matrix is 0, 0, 0, 1 • Can convert to new basis {u1, u2, u3, Q0}

  17. Examples • Change of basis 4.3.3, p. 159 • Change of frame 4.3.5, p. 163

  18. Working with Representations • Problem: How to obtain the transformation matrix given two representations • Solution: The representation of one frame in terms of another, a = Cb, gives the inverse of the matrix, D = C-1 (see p. 165)

  19. Frames in OpenGL • Camera us at origin of its frame, pointing in –z direction; y is the up direction and x completes a right-handed coordinate system (see next slide) • To view objects near origin, camera must be moved back, say a distance d (see next slide)

  20. Camera Model-View Matrix • Model-View matrix is 1 0 0 0 0 1 0 0 0 0 1 -d 0 0 0 1 moves point (x,y,z) in world frame to (x,y,z-d)

  21. Camera at (1,0,1)Pointing at Origin • Camera is centered at (1,0,1,1)T • Orthogonal to back is n=(-1,0,-1,1)T • Up is same as world coord (0,1,0,0)T • Third orthogonal is (1,0,-1,0)T • Inverse of 1 0 -1 1 .5 0 -.5 0 0 1 0 0 is 0 1 0 0 -1 0 -1 1 -.5 0 -.5 0 0 0 0 1 0 0 0 1

  22. Modeling a Colored Cube • Steps • Modeling • Converting to camera frame • Clipping • Projecting • Removing Hidden Surfaces • Rasterizing Code is cube.c

  23. Modeling Cube • Model as 6 faces defined by vertices • Vertices at 1, -1 • Each face is a square (polygon) • Polygons have inside and outside face • Face is outward if vertices occur in counterclockwise order • Use right-hand rotation through vertices, thumb points out • Outward face must be to outside of cube

  24. Data Structures • Polygons or Quads • Vertex list representation

  25. Cube Code • Define colors for the vertices see code

  26. Coloring Faces • Faces will be filled with colors by intepolation, bilinear scan-line interpolation from model avoids need for flat

  27. Vertex Arrays • Avoid recomputation • OpenGL Arrays • Color • Vertex • Color Index • Normal • Texture Coordinate • Edge Flag

  28. Application to Cube • glEnableClientState(array_type); • array types: GL_COLOR_ARRAY GL_VERTEX_ARRAY • Create global arrays of values as before

  29. Application to Cube (cont) • Register data arrays with OpenGL glVertexPointer (dim, glType, gap, array_var); glColorPointe (…) • For example glVertexPointer (3, GL_FLOAT, 0, vertices);

  30. Application to Cube (cont) • Then draw the elements with glDrawElements(type, n, fmt, ptr); • For example for (1=0; i<6; i++) glDrawElements(GL_POLYGON, 4 GL_UNSIGNED_BYTE, &cubeIndex[4*i]); • or could do quads in one batch of 24

  31. Affine Transformations • A transformation maps a point (or vector) into another point (or vector) Q = T(P) • With homogeneouscoordinates we can use the same function for both points and vectors, q=f(p) or v=f(u)

  32. Linear Transformations • Limit consideration to functions satisfying f(ap+bq) = af(p) + bf(q) called linear transformations • Linear transformations can always be written as matrix multiplications by a 4x4 matrix • For homogeneous coordinates, the last row is 0 0 0 1 but other 12 entries are arbitrary, but only 9 effect vectors.

  33. Linear Transformations (cont) • Properites • Linear transformations can be viewed as either • change in representation (frame) • transformation on vertices within frame • Lines and planes are preserved • Transformed line segment is generated by transformed end points • This simplifies design of graphics pipeline

  34. Translation, Rotation, Scaling • Translation P’ = P + d • Rotation in two coordinates about origin cos th -sin th sin th cos th

  35. Rotation (cont) • Properties of rotations • one fixed point • can be composed from two-dimensional rotation in different coordinates • define positive rotation in plane if rotation is counterclockwise when viewed down normal to plane • is a rigid-body transformation • shape is not changed

  36. Scaling • An affine non-rigid body transformation • Multiply coordinate by some factor • Negative multiplication produces reflection

  37. Affine Transformations in Homogeneous Cooridnates • All represented by linear transformations • 4x4 matrix with last row 0 0 0 1 • Translation by a b c, and inverse 1 0 0 a 1 0 0 -a 0 1 0 b 0 1 0 –b 0 0 1 c 0 0 1 -c 0 0 0 1 0 0 0 1

  38. Scaling • Multiply axes by a, b, c respectively a 0 0 0 0 b 0 0 0 0 c 0 0 0 0 1 • Inverse comes from 1/a, 1/b, 1/c

  39. Rotation • Can compose z, x, and y rotations by thz, thx, thy • Inverse is rotation by –thz, -thx, -thy • It can be shown that R-1 = RT • Matrices satisfying this property are said to be orthogonal

  40. Shear • Shear in the x axis is defined by x’ = x + y cot th • Inverse users -th

  41. Concatenation of Transforms • A sequence of transformations with T1 followed by T2 followed by T3 can be composed as T3(T2(T1(p))) • If the corrersponding matrices are A, B, C this yields M = CBA • Thus a concatenation of transformations can be represented by a single matrix

  42. Composed Transformaitons • Rotation in z about a fixed point T(p)Rz(th)T(-p) • General rotation Rx(thx) Ry(thy) Rz(thz)

  43. Rotation about given vector • First change coordinates so given vector is on a coordinate axis • Use unit vector to avoid scaling • Then rotate about that coordinate axis • Finally restore to original coordinate system • Can translate for fixed point as before

  44. Instance Transformations • When a particular kind of figure is used many times in a scene, it is convenient to construct one prototype and draw the objects by transforming that prototype • Convention is to center prototype on center of mass and then scale, rotate, and translate: TRS

  45. Open GL Transformation Matrices • Current Transformation Matrix (CTM) is part of the pipeline • It can be set or modified • After setting matrix mode glLoadMatrixf(*matrix); //load matrix glLoadIdentity();

  46. OpenGL Transformations • OpenGL has functions to perform basic operations glRotatef(angle, vx, vy, vz); // rotate about vector v glTranslatef(dx, dy, dz); glScalef(sx, sy, sz); • Applied in order called

  47. OpenGL Rotation about Point • Rotate 45o about line through origin and (1, 2, 3) with fixed point (4, 5, 6) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(4.0, 5.0, 6.0); glRotatef(45.0, 1.0, 2.0, 3.0); glTranslatef(-4.0, -5.0, -6.0);

  48. Spinning the Cube • Mouse button click sets rotation axis • Idle callback adjusts rotation theta on selected axis • Display uses glRotatef() to set cube at desired angles in 3-d

  49. Loading, Pushing, Popping • Can push and pop save and restore matrix • Projection stack is often limited to 2 levels; don’t usually transform it • Can load matrix from array with glLoadMatrix(myArray); • And multiply by our own matrix with glMultMatrix(myArray); • Can’t get OpenGL matrix into array

More Related