330 likes | 517 Views
Lecture 03b: Shapes. COMP 175: Computer Graphics January 28, 2014. Quick Review of Linear Algebra. What is a cross product? How do you find the cross product? Different ways to think about the cross product? What is a dot product? How do you find the dot product?
E N D
Lecture 03b:Shapes COMP 175: Computer Graphics January 28, 2014
Quick Review of Linear Algebra • What is a cross product? • How do you find the cross product? • Different ways to think about the cross product? • What is a dot product? • How do you find the dot product? • Different ways to think about the dot product? • Given two vectors A, B, show that the cross product N is orthogonal to A and B. • Points vs. Vectors • What are basis vectors? • In 2D, what 2 vectors cannot be basis vectors? • What is: • a unit vector • a normal vector • a null vector? • Vector math: • Add, subtract, multiple (by scalar) • Normalize a vector
2D Object Definition • Lines and Polyline • Polyline: lines drawn between ordered points • Polygon • If the first and last points of a polyline are the same point, then the polyline is said to be “closed”, and that the closed polyline forms a polygon • Self-intersected polyline not closed, simple polyline simple polygon, closed polyline not simple polygon, closed polyline
2D Object Definition • Convex and Concave polygons • Convex: for every pair of points inside the polygon, the line between them is entirely inside the polygon • Concave: for some pair of points inside the polygon, the line between them is not entirely inside the polygon. Not convex. convex concave
2D Object Definition • Why is a convex polygon so awesome?
2D Object Definition • Why is a convex polygon so awesome? • Center of mass • Tessellation • Subdivision • Fixed boundary • Exactly two intersections • All diagonals are within the boundary • Tessellation -> computing the area • Every interior angle is less than 180 • Etc.
Special Polygons • Circle • Set of all points equidistant from one point called the center • The distance from the center is the radius r • The equation for a circle centered at (0, 0) is r2 = x2 + y2 Rectangle Triangle Square (x, y) (0, y) r (0, 0) (0, x)
6 6 5 5 4 4 3 3 2 2 1 1 0 0 1 2 3 4 5 6 7 8 9 10 10 1 2 3 4 5 6 7 8 9 2D Object Definition • A circle can be approximated by a polygon with many sides. • Axis aligned ellipse: a circle scaled in the x and/or y direction
Representing Shapes • Vertex and Edge tables • General purpose, minimal overhead, reasonably efficient • Each vertex listed once • Each edge is an ordered pair of indices to the vertex list E3 V4 E2 V2 V3 E4 E1 E0 V0 V1
Triangle Meshes • Most common representation of shape in three dimensions • All vertices of triangle are guaranteed to lie in one plane • (not true for quadrilaterals or other polygons) • Uniformity makes it easy to perform mesh operations such as subdivision, simplification, transformation etc. • Many different ways to represent triangular meshes
Triangular Mesh Representation • Vertex, Face, (and Normal) Tables v4 v7 f11 v8 f10 f8 f9 v6 f0 v5 f2 f1 f3 v0 v1 v2
Other Possible Encodings • 3D meshes can be represented as vertices, (edges), faces, and normals • Are there other ways to encode 3D meshes?
2.5D Objects • 2.5D objects are 3D objects that are “protrusions” or “extensions” of 2D shapes (i.e., 2D shape + height)
3D Extrusions • A spring can be described in Cartesian coordinate system as: • Or in cylindrical coordinate as:
Technically... • We can think of the shapes in assignment 2 the same way... ““Vertices in Motion” • So we can make 3D shapes out of 2D and 1D primitives
GL Normal • These two have the same number of quads… • What is the difference?
GL Normal glNormal3f(nx, ny, nz); glBegin(GL_QUADS); glVertex3f(x1, y1, z1); glVertex3f(x2, y2, z2); glVertex3f(x3, y3, z3); glVertex3f(x4, y4, z4); glEnd();
GL Normal glBegin(GL_QUADS); glNormal3f(nx1, ny1, nz1); glVertex3f(x1, y1, z1); glNormal3f(nx2, ny2, nz2); glVertex3f(x2, y2, z2); glNormal3f(nx3, ny3, nz3); glVertex3f(x3, y3, z3); glNormal3f(nx4, ny4, nz4); glVertex3f(x4, y4, z4); glEnd();
GL Normal • What are the normals? • For a circle / sphere? • For a cube? • For a cylinder? • For a cone? • How do you define what a normal is?
GL Normal • What are the normals? • For a circle / sphere? • For a cube? • For a cylinder? • For a cone? • Thinking of the normal of a curved surface as the normal to the tangent plane
Exercise • Write a render function that takes in two parameters, radius and slices, and produces a 2D circle drawn as a set of polylines (assume centered at (0,0)), with a defined normal for each vertex • That is, fill in this function: void drawCircle2D(float radius, int slices) { : : glBegin (...); for (inti=0; i<...) { : : glNormal2f(...); glVertex2f(...); } glEnd(); }