Upload
elden
View
42
Download
0
Embed Size (px)
DESCRIPTION
Introduction to 3D Graphics Lecture 4: Scenes and Scene Graphs. Anthony Steed University College London. No More Spheres!. Overview. Polygons Representation Intersection Polyhedra Face sets Winged edge Scene graphs. Polygons. A polygon (face) Q is defined by a series of points - PowerPoint PPT Presentation
Citation preview
Introduction to 3D GraphicsIntroduction to 3D Graphics
Lecture 4: Scenes and Lecture 4: Scenes and Scene GraphsScene Graphs
Anthony SteedAnthony Steed
University College LondonUniversity College London
No More Spheres!No More Spheres!
OverviewOverview
PolygonsPolygons– RepresentationRepresentation– IntersectionIntersection
PolyhedraPolyhedra– Face setsFace sets– Winged edgeWinged edge
Scene graphsScene graphs
PolygonsPolygons A polygon (face) Q is defined by a A polygon (face) Q is defined by a
series of pointsseries of points
The points are must be The points are must be co-planarco-planar 3 points define a plane, but a 4th 3 points define a plane, but a 4th
point need not lie on that planepoint need not lie on that plane
iiii
nn
zyxp
ppppp
,,
,1,...,2,1,0
Types of PolygonTypes of Polygon
Simple - Concave, ConvexSimple - Concave, Convex
ComplexComplex
We like simple, concave polygons since they are easy to break into triangles
Equation of a PlaneEquation of a Plane
a,b,c and d are constants that a,b,c and d are constants that define a unique plane and x,y and define a unique plane and x,y and z form a vector P.z form a vector P.
dczbyax
Deriving a,b,c & d (1)Deriving a,b,c & d (1)
p0
p2
p1
p
The cross productThe cross product
defines a defines a normalnormal to the to the planeplane
There are two normals (they There are two normals (they are opposite)are opposite)
Vectors in the plane are all Vectors in the plane are all orthogonal to the plane orthogonal to the plane normal vectornormal vector
)( 0201 ppppn
Deriving a,b,c & d (2)Deriving a,b,c & d (2)
So p-pSo p-p0 0 is normal to n thereforeis normal to n therefore
But if n = (nBut if n = (n11,n,n22,n,n33))
– a= na= n11 b= n b= n22 c= n c= n3 3 (n.p)(n.p)
– d = n.p0 = nd = n.p0 = n11*x*x00 + n + n22*y*y0 0 + n+ n3*3*zz00
00 ppn
Half-SpaceHalf-Space
A plane cuts space into 2 A plane cuts space into 2 half-spaceshalf-spaces Define Define
If l(p) =0If l(p) =0– point on planepoint on plane
If l(p) > 0If l(p) > 0– point in point in positivepositive half-space half-space
If l(p) <0If l(p) <0– point in point in negative negative half-spacehalf-space
dczbyaxzyxl ),,(
Outline of Polygon Ray Outline of Polygon Ray CastingCasting
Three stepsThree steps– Does the ray intersect the plane of Does the ray intersect the plane of
the polygon?the polygon? i.e. is the ray not orthogonal to the plane i.e. is the ray not orthogonal to the plane
normalnormal
– Intersect ray with planeIntersect ray with plane– Test whether intersection point lies Test whether intersection point lies
within polygon on the planewithin polygon on the plane
Does the ray intersect the Does the ray intersect the plane?plane?
Ray eq. is pRay eq. is p00 + t.d + t.d Plane eq. is n.(x,y,z) = kPlane eq. is n.(x,y,z) = k
Then test is n.d !=0Then test is n.d !=0
Where does it intersect?Where does it intersect?
Substitute line equation into plane Substitute line equation into plane equationequation
Solve for tSolve for t
Find pFind pii
kdztzdytydxtxn .... 000
dn
pnkt
)( 0
Is this point inside the Is this point inside the polygon?polygon?
Many tests are possibleMany tests are possible– Winding number (can be done in 3D)Winding number (can be done in 3D)– Infinite ray test (done in 2D)Infinite ray test (done in 2D)
Winding Number TestWinding Number Test
Sum the angle subtended by the Sum the angle subtended by the verticesvertices
1
n-1
p1
p2
pn-1
21
n
ii
Inside and OutsideInside and Outside
Not just draw (stroke, fill)Not just draw (stroke, fill) For closed ShapesFor closed Shapes
– Hit test - inside or outside based on a Hit test - inside or outside based on a winding rules (non-zero or even-odd)winding rules (non-zero or even-odd)
Counting Edge CrossesCounting Edge Crosses
Draw a line from the test point to the outsideDraw a line from the test point to the outside– Count +1 if you cross an edge in an anti-clockwise Count +1 if you cross an edge in an anti-clockwise
sensesense– Count -1 if you cross and edge in a clockwise senseCount -1 if you cross and edge in a clockwise sense
+1
-1
OverviewOverview
PolygonsPolygons– RepresentationRepresentation– IntersectionIntersection
PolyhedraPolyhedra– Face setsFace sets– Winged edgeWinged edge
Scene graphsScene graphs
PolyhedraPolyhedra
Polygons are often grouped Polygons are often grouped together to form polyhedratogether to form polyhedra– Each edge connects 2 vertices and is Each edge connects 2 vertices and is
the join between two polygonsthe join between two polygons– Each vertex joins 3 edgesEach vertex joins 3 edges– No faces intersectNo faces intersect
V-E+F=2 V-E+F=2 – For cubes, tetrahedra, cows etc...For cubes, tetrahedra, cows etc...
Example PolhedronExample Polhedron
vo v1
v2
v3
v4
v5
e1e2
e3e4
e5e6
e7
e9
e8
F0=v0v1v4F0=v0v1v4 F1=v5v3v2F1=v5v3v2 F2=v1v2v3v4F2=v1v2v3v4 F3=v0v4v3v5F3=v0v4v3v5 F4=v0v5v2v1F4=v0v5v2v1
V=6,F=5, V=6,F=5, E=9E=9
V-E+F=2V-E+F=2
Representing Polyhedron (1) Representing Polyhedron (1)
Exhaustive (array of vertex lists)Exhaustive (array of vertex lists)– faces[1] = (x0,y0,z0),(x1,y1,z1),(x3,y3,z3)faces[1] = (x0,y0,z0),(x1,y1,z1),(x3,y3,z3)– faces[2] = (x2,y2,z2),(x0,y0,z0),(x3,y3,z3)faces[2] = (x2,y2,z2),(x0,y0,z0),(x3,y3,z3)– etc ….etc ….
Very wasteful since same vertex Very wasteful since same vertex appears at 3(or more) points in the listappears at 3(or more) points in the list– Is used a lot though!Is used a lot though!
Representing Polyhedron (2) Representing Polyhedron (2)
Indexed Face setIndexed Face set Vertex arrayVertex array
– vertices[0] = (x0,y0,z0)vertices[0] = (x0,y0,z0)– vertices[1]=(x1,y1,z1)vertices[1]=(x1,y1,z1)– etc …etc …
Face array (list of indices into vertex Face array (list of indices into vertex array)array)– faces[0] = 0,2,1faces[0] = 0,2,1– faces[1]=2,3,1faces[1]=2,3,1– etc ...etc ...
Vertex order mattersVertex order matters
Polygon v0,v1,v4 is NOT Polygon v0,v1,v4 is NOT equal to v0,v4,v1equal to v0,v4,v1
The normal point in The normal point in different directionsdifferent directions
Usually a polygon is only Usually a polygon is only visible from points in its visible from points in its positive half-spacepositive half-space
This is known as This is known as back-back-face cullingface culling
vo v1v2
v3v4
v5
Polygon v0,v1,v4 is NOT Polygon v0,v1,v4 is NOT equal to v0,v4,v1equal to v0,v4,v1
The normal point in The normal point in different directionsdifferent directions
Usually a polygon is only Usually a polygon is only visible from points in its visible from points in its positive half-spacepositive half-space
This is known as This is known as back-back-face cullingface culling
vo v1
v3v4
v5
Representing Polyhedron (3)Representing Polyhedron (3)
Even Indexed face set wastes Even Indexed face set wastes spacespace– Each face edge is represented twiceEach face edge is represented twice
Winged edge data structure solves Winged edge data structure solves thisthis– vertex listvertex list– edge list (vertex pairs)edge list (vertex pairs)– face list (edge lists)face list (edge lists)
The Edge List StructureThe Edge List Structure
e
NV(e)
PFace(e)NFace(e)
PCW(e)NCCW(e)
NCW(e) PCCW(e)
PV(e)
Edge containsEdge contains– Next edge CWNext edge CW– Next edge CCWNext edge CCW– Prev edge CWPrev edge CW– Prev edge CCWPrev edge CCW– Next faceNext face– Prev facePrev face– Next vertexNext vertex– Prev vertexPrev vertex
Advantages of Winged Advantages of Winged EdgeEdge
Simple searches are rapidSimple searches are rapid– find all edgesfind all edges– find all faces of a vertexfind all faces of a vertex– etc…etc…
Complex operationsComplex operations– polygon splitting is easy (LOD)polygon splitting is easy (LOD)– silhouette findingsilhouette finding– potentially efficient for hardwarepotentially efficient for hardware– etc… etc…
Building the WEBuilding the WE
Build indexed face setBuild indexed face set Traverse each face in CCW order Traverse each face in CCW order
building edgesbuilding edges– label p and n vertices, p and n faces label p and n vertices, p and n faces
and link previous CCW edgeand link previous CCW edge we fill in next CCW on next edge in this we fill in next CCW on next edge in this
faceface we fill in next CW and prev CW when we fill in next CW and prev CW when
traversing the adjacent face.traversing the adjacent face.
OverviewOverview
PolygonsPolygons– RepresentationRepresentation– IntersectionIntersection
PolyhedraPolyhedra– Face setsFace sets– Winged edgeWinged edge
Scene graphsScene graphs
Concept of Scene GraphConcept of Scene Graph
Objects placed relative to one Objects placed relative to one anotheranother
Objects made of similar Objects made of similar componentscomponents
Directed acyclic graphDirected acyclic graphroot
Use for Use for Animation/ModellingAnimation/Modelling
BS
U
E
F
H
One object has a One object has a local local transformation transformation relative to its parentrelative to its parent– shoulder is translation shoulder is translation
(0 1 0) from base(0 1 0) from base– upper arm is translation upper arm is translation
(0 3 0) from shoulder (0 3 0) from shoulder– elbow is translation (0 3 0) elbow is translation (0 3 0)
from upper armfrom upper arm– fore arm is rotation Z by -fore arm is rotation Z by -
90 then translation (0 2 0)90 then translation (0 2 0)
robotarmj ointjointarmbase
shoulder
elbow
forearm
upper
hand
Rendering TraverseRendering Traverse
Must get object definitions in WC Must get object definitions in WC before passing to camerabefore passing to camera
For object under For object under BBasease– p.B is in WCp.B is in WC
““inherit” matrices down stackinherit” matrices down stack So for object under shoulderSo for object under shoulder
– p.SB is in WCp.SB is in WC– (p.S is in base coordinates)(p.S is in base coordinates)
In generalIn general
On traverse On traverse – ““push” on graph push” on graph
descend descend – ““pop” on graph pop” on graph
ascendascend Combined matrix Combined matrix
is is current current transform transform (CTM)(CTM)
Sharing NodesSharing Nodes
E.G. One table E.G. One table many places many places
Table1 has Table1 has CTM T1T0CTM T1T0
Table2 has Table2 has CTM T2T0CTM T2T0
table
table2
table1
T1 T2
T0
Spherical CoordinatesSpherical Coordinates
Represent a point on a using two anglesRepresent a point on a using two angles and and . Where r = length(x,y,z). Where r = length(x,y,z)
Z
P (x,y,z)
X
Y
QO
Q is projection of P onto XY plane is angle between X axis and OQ is angle between OP and Z axis
Spherical CoordinatesSpherical Coordinates
Length OQ = r sin(Length OQ = r sin()) SoSo
– x = r sin(x = r sin()cos()cos( ) )– y = r sin(y = r sin()sin()sin( ) )– z = r cos(z = r cos())
Rotation About an Rotation About an Arbitrary AxisArbitrary Axis
Z
X
Y
Op1
p2
……
1. Translate p1 so it is at the origin1. Translate p1 so it is at the origin
2. Let p3 = p2-p1 (new position of p2)2. Let p3 = p2-p1 (new position of p2)
find spherical co-ordinate of p3 (r, find spherical co-ordinate of p3 (r, ,,))
3. Rotate about Z by -3. Rotate about Z by - to bring p3 into ZX to bring p3 into ZX planeplane
4. Rotate about Y by - 4. Rotate about Y by - to bring p3 onto Z to bring p3 onto Z axisaxis
5. Now rotate about Z by 5. Now rotate about Z by
6. Invert steps 4-16. Invert steps 4-1
… …
Z
Y
O p1
p2Z
Y
O
p3
Start Translate
……
Z
Y
p3
Rotate1
Z
Y
p3
Rotate2
… …
Z
Y
p3
After Steps 1-4
Now we apply the Now we apply the transformation we transformation we are afterare after
Invert steps 4-1Invert steps 4-1
SummarySummary
Established a set of techniques for Established a set of techniques for describing scenes made of polygonsdescribing scenes made of polygons– Particularly the roles of local-Particularly the roles of local-
coordinates, which form the modelling coordinates, which form the modelling matrix stack in OpenGlmatrix stack in OpenGl
Described how to ray-cast these Described how to ray-cast these shapesshapes– The mathematics of this will be crucial The mathematics of this will be crucial
when we turn to projection next week.when we turn to projection next week.