Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hidden Line Removal Applying vector algebra to the problem of removing hidden lines from wire-frame models.

Similar presentations


Presentation on theme: "Hidden Line Removal Applying vector algebra to the problem of removing hidden lines from wire-frame models."— Presentation transcript:

1 Hidden Line Removal Applying vector algebra to the problem of removing hidden lines from wire-frame models

2 Convex objects We first focus on modeling convex objects One “outward face” cannot hide another So visible faces can be drawn in any order Examples: barn, cube, and dodecahedron

3 A non-convex object part of this face is hidden by that face eye of viewer

4 2D Polygons in 3D space A polygon is a 2-dimensional figure Its edges and corner-points are coplanar It’s a bounded region of an infinite plane Any plane in 3-space can be described by an first-degree (linear) algebraic equation: ax + by + cz = d Alternatively, using vector algebra, a plane can be described using a reference-point Q and a direction-vector N = (a, b, c), as: N QP = 0

5 Face-Planes of solid objects Any plane surface has two sides When a plane is a surface of a solid object it has an “inside” surface and an “outside” surface (a viewer sees the “outside” one) frontback viewer

6 Angles and cosines An angle of 90-degrees is a “right” angle Angles less than 90-degrees are “acute” And angles over 90-degrees are “obtuse” right angleacute angle obtuse angle cosine = 0 cosine > 0 cosine < 0

7 Vectors and dot-products Vectors u = (u x, u y, u z ) and v = (v x, v y, v z ) have a dot-product: uv = u x v x + u y v y + u z v z A vector’s length ║u║ equals sqrt( uu ) A dot-product is related to the cosine of the angle θ between the two vectors: uv = ║u║║v║cosine(θ) So sign of dot-product tells angle’s type

8 Visibility of face-planes N = outward pointing normal vector D = direction vector (from plane toward viewer’s eye) D N DN > 0 (acute angle θ) outer surface is visible θ

9 “Hidden” face-plane N θ D N = outward pointing normal vector D = direction vector (from plane toward viewer’s eye) DN < 0 (obtuse angle θ) outer surface is hidden

10 Format of model’s data-set Added data needed to describe our model Number and Location of vertices as before Edge-list is no longer needed (zero edges) Face-list is the new information to be add Each face is a polygon: number of sides, list of vertices in counter-clockwise order (as viewed from the outside of the model), and the face-color to be used for the face

11 Example data-set: cube 0 1 2 34 5 6 7 4-sided: 0, 1, 2, 3 (blue) 4-sided: 1, 0, 7, 6 (green) 4-sided: 2, 5, 4, 3 (cyan) 4-sided: 4, 5, 6, 7 (red) 4-sided: 6, 5, 2, 1 (magenta) Face-List (6 faces) The vertices of each face should be listed in counterclockwise order (an seen from the outside of the cube)

12 Why counterclockwise order? We need to compute the outward-pointing “normal” vector for each polygonal face (to determine if that outward face is visible) That normal vector is easily computed (as a vector cross-product) if the vertices are listed in counterclockwise order

13 Recall the cross-product: u×v If u = ( u x, u y, u z ) and v = ( v x, v y, v z ), then w = u×v is given by these formulas: w x = u y v z – u z v y w y = u z v x – u x v z w z = u x v y – u y v x Significance: cross-product w makes a 90-degree angle with both u and v (so it’s normal to a plane containing u and v)

14 Three consecutive vertices V0 V1 V2 p q p = v1 – v0 q = v2 – v1 p×q will be the outward-pointing normal vector (if v0, v1, v2 occurred in counterclockwise order) p×q

15 Remembering u x v Here’s a “trick” students use to remember the formula for computing a cross-product It’s based on the “cofactor expansion” rule for 3x3 determinants: a b c e f d f d e d e f = a - b + c g h i h i g i g h

16 Applying this “trick” i = (1,0,0), j = (0,1,0), k = (0,0,1) u = (u x,u y,u z ) v = (v x,v y,v z ) i j k u x v = u x u y u z v x v y v z = ( u y v z – u z v y, u z v x – u x v z, u x v y – u y v x )

17 Demo program Our ‘filldemo.cpp’ application reads in the data for a 3D model, determines which of its polygonal faces are visible to a viewer, fills each visible face in its specified color, and then draws the edges of visible faces Datasets: plato.dat, redbarn.dat, plane.dat Also two models for a non-convex object: corner1.dat and corner2.dat (same object)

18 The ‘bitblit’ technique Our ‘filldemo’ program achieves its smooth animation, not with ‘page-flipping’, but with the so-called ‘bitblit’ method This approach has the advantage that it avoids dependency on Radeon hardware (e.g., using the CRTC_START register)

19 How ‘bitblit’ is used VRAM Visible page (page 0) Drawing page (page 1) CRTC_START All the drawing is done to page 1 (which never gets displayed) Then after an image has is fully drawn, it is rapidly copied to page 0 (‘bitblit’) (never gets changed)

20 In-class exercises Try to create the data-sets for some “more interesting” 3D objects, (by writing a C++ program to generate the object’s vertices and the face-lists) Example: An octagonal prism –Divide a circle into eight equal-size angles –Use sine and cosine to locate upper vertices –Use sine and cosine to locate lower vertices –Use number-patterns to generate its ten face-planes


Download ppt "Hidden Line Removal Applying vector algebra to the problem of removing hidden lines from wire-frame models."

Similar presentations


Ads by Google