Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to 3D Graphics Lecture 4: Scenes and Scene Graphs Anthony Steed University College London.

Similar presentations


Presentation on theme: "Introduction to 3D Graphics Lecture 4: Scenes and Scene Graphs Anthony Steed University College London."— Presentation transcript:

1 Introduction to 3D Graphics Lecture 4: Scenes and Scene Graphs Anthony Steed University College London

2 No More Spheres!

3 Overview n Polygons –Representation –Intersection n Polyhedra –Face sets –Winged edge n Scene graphs

4 Polygons n A polygon (face) Q is defined by a series of points n The points are must be co-planar n 3 points define a plane, but a 4th point need not lie on that plane

5 Types of Polygon n Simple - Concave, Convex n Complex We like simple, concave polygons since they are easy to break into triangles

6 Equation of a Plane n a,b,c and d are constants that define a unique plane and x,y and z form a vector P.

7 Deriving a,b,c & d (1) p 0 p 2 p 1 p n The cross product defines a normal to the plane n There are two normals (they are opposite) n Vectors in the plane are all orthogonal to the plane normal vector

8 Deriving a,b,c & d (2) n So p-p 0 is normal to n therefore n But if n = (n 1,n 2,n 3 ) –a= n 1 b= n 2 c= n 3 (n.p) –d = n.p0 = n 1 *x 0 + n 2 *y 0 + n 3* z 0

9 Half-Space n A plane cuts space into 2 half-spaces n Define n If l(p) =0 –point on plane n If l(p) > 0 –point in positive half-space n If l(p) <0 – point in negative half-space

10 Outline of Polygon Ray Casting n Three steps –Does the ray intersect the plane of the polygon? n i.e. is the ray not orthogonal to the plane normal –Intersect ray with plane –Test whether intersection point lies within polygon on the plane

11 Does the ray intersect the plane? n Ray eq. is p 0 + t.d n Plane eq. is n.(x,y,z) = k n Then test is n.d !=0

12 Where does it intersect? n Substitute line equation into plane equation n Solve for t n Find p i

13 Is this point inside the polygon? n Many tests are possible –Winding number (can be done in 3D) –Infinite ray test (done in 2D)

14 Winding Number Test n Sum the angle subtended by the vertices 1 n-1 p1p1 p2p2 p n-1

15 Inside and Outside n Not just draw (stroke, fill) n For closed Shapes –Hit test - inside or outside based on a winding rules (non-zero or even-odd)

16 Counting Edge Crosses n Draw a line from the test point to the outside –Count +1 if you cross an edge in an anti-clockwise sense –Count -1 if you cross and edge in a clockwise sense +1

17 Overview n Polygons –Representation –Intersection n Polyhedra –Face sets –Winged edge n Scene graphs

18 Polyhedra n Polygons are often grouped together to form polyhedra –Each edge connects 2 vertices and is the join between two polygons –Each vertex joins 3 edges –No faces intersect n V-E+F=2 –For cubes, tetrahedra, cows etc...

19 Example Polhedron vo v1 v2 v3 v4 v5 e1 e2 e3 e4 e5 e6 e7 e9 e8 n F0=v0v1v4 n F1=v5v3v2 n F2=v1v2v3v4 n F3=v0v4v3v5 n F4=v0v5v2v1 n V=6,F=5, E=9 n V-E+F=2

20 Representing Polyhedron (1) n Exhaustive (array of vertex lists) –faces[1] = (x0,y0,z0),(x1,y1,z1),(x3,y3,z3) –faces[2] = (x2,y2,z2),(x0,y0,z0),(x3,y3,z3) –etc …. n Very wasteful since same vertex appears at 3(or more) points in the list –Is used a lot though!

21 Representing Polyhedron (2) n Indexed Face set n Vertex array –vertices[0] = (x0,y0,z0) –vertices[1]=(x1,y1,z1) –etc … n Face array (list of indices into vertex array) –faces[0] = 0,2,1 –faces[1]=2,3,1 –etc...

22 Vertex order matters n Polygon v0,v1,v4 is NOT equal to v0,v4,v1 n The normal point in different directions n Usually a polygon is only visible from points in its positive half-space n This is known as back-face culling vo v1 v2 v3 v4 v5 n Polygon v0,v1,v4 is NOT equal to v0,v4,v1 n The normal point in different directions n Usually a polygon is only visible from points in its positive half-space n This is known as back-face culling vo v1 v3 v4 v5

23 Representing Polyhedron (3) n Even Indexed face set wastes space –Each face edge is represented twice n Winged edge data structure solves this –vertex list –edge list (vertex pairs) –face list (edge lists)

24 The Edge List Structure e NV(e) PFace(e)NFace(e) PCW(e)NCCW(e) NCW(e) PCCW(e) PV(e) n Edge contains –Next edge CW –Next edge CCW –Prev edge CW –Prev edge CCW –Next face –Prev face –Next vertex –Prev vertex

25 Advantages of Winged Edge n Simple searches are rapid –find all edges –find all faces of a vertex –etc… n Complex operations –polygon splitting is easy (LOD) –silhouette finding –potentially efficient for hardware –etc…

26 Building the WE n Build indexed face set n Traverse each face in CCW order building edges –label p and n vertices, p and n faces and link previous CCW edge n we fill in next CCW on next edge in this face n we fill in next CW and prev CW when traversing the adjacent face.

27 Overview n Polygons –Representation –Intersection n Polyhedra –Face sets –Winged edge n Scene graphs

28 Concept of Scene Graph n Objects placed relative to one another n Objects made of similar components n Directed acyclic graph root

29 Use for Animation/Modelling B S U E F H

30 n One object has a local transformation relative to its parent –shoulder is translation (0 1 0) from base –upper arm is translation (0 3 0) from shoulder –elbow is translation (0 3 0) from upper arm –fore arm is rotation Z by -90 then translation (0 2 0)

31 Rendering Traverse n Must get object definitions in WC before passing to camera n For object under Base –p.B is in WC n “inherit” matrices down stack n So for object under shoulder –p.SB is in WC –(p.S is in base coordinates)

32 In general n On traverse –“push” on graph descend –“pop” on graph ascend n Combined matrix is current transform (CTM)

33 Sharing Nodes n E.G. One table many places n Table1 has CTM T1T0 n Table2 has CTM T2T0 table table2 table1 T1 T2 T0

34 Spherical Coordinates n Represent a point on a using two angles and . Where r = length(x,y,z) Z P(x,y,z)   X Y Q O Q is projection of P onto XY plane is angle between X axis and OQ  is angle between OP and Z axis

35 Spherical Coordinates n Length OQ = r sin(  ) n So –x = r sin(  )cos( ) –y = r sin(  )sin( ) –z = r cos(  )

36 Rotation About an Arbitrary Axis Z X Y O p1 p2 

37 … 1. Translate p1 so it is at the origin 2. Let p3 = p2-p1 (new position of p2) find spherical co-ordinate of p3 (r, , ) 3. Rotate about Z by - to bring p3 into ZX plane 4. Rotate about Y by -  to bring p3 onto Z axis 5. Now rotate about Z by  6. Invert steps 4-1

38 … Z Y O p1 p2 Z Y O p3 StartTranslate

39 … Z Y p3 Rotate1 Z Y p3 Rotate2 

40 … Z Y p3 After Steps 1-4 n Now we apply the transformation we are after n Invert steps 4-1

41 Summary n Established a set of techniques for describing scenes made of polygons –Particularly the roles of local-coordinates, which form the modelling matrix stack in OpenGl n Described how to ray-cast these shapes –The mathematics of this will be crucial when we turn to projection next week.


Download ppt "Introduction to 3D Graphics Lecture 4: Scenes and Scene Graphs Anthony Steed University College London."

Similar presentations


Ads by Google