Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

10
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1

Transcript of Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Page 1: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Computer GraphicsBasic 3D Geometry

CO2409 Computer Graphics

Week 5-1

Page 2: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Today’s LectureToday’s Lecture

1. From 2D to 3D Geometry

2. Handedness

3. Meshes

4. Face and Vertex Normals

Page 3: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

From 2D to 3D GeometryFrom 2D to 3D Geometry

• 3D geometry adds an extra axis over 2D geometry– This “Z” axis represents “depth”

• Can choose the direction to point Z• Giving us the handedness of the

3D axes:– Use thumb (X), index finger (Y) &

middle finger (Z) to represent the axes– Use your left hand and the axes are

left-handed, otherwise they are right-handed

– We will generally use left-handed axesLH

RH

Page 4: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Handedness + DefinitionsHandedness + Definitions

• DirectX documentation and several graphics applications use left-handed axes

• OpenGL documentation + maths texts use right-handed• Neither is better, just a choice

– Note that DirectX and OpenGL can both use either handedness. Handedness is more an issue when drawing diagrams or creating mesh geometry.

• Defining geometry in 3D is just like 2D• Vertices – we add a third coordinate (Z):

A(10, 20,15), B(30, 30,20)

• Edges & Polygons:– No change in the definition from 2D

Page 5: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

MeshesMeshes

• A mesh is a set of polygons representing a 3D object

• Characteristics of meshes:– Polygons connected?– No holes in the polygon surface?– Polygons form a closed solid rather

than a surface (i.e. is there an interior and an exterior)?

• All these types can be rendered– Latter two must be satisfied for an

object to appear truly solid.

Page 6: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Triangular MeshesTriangular Meshes

• Polygons in a mesh can have any number of sides

• However, usually all polygons in a mesh are triangles:

• Graphics hardware tends to support triangle rendering

• Triangles are always planar – [Planar = flat]– Polygons with four or more edges

can be “folded”– Making rendering more complex

• So polygons are usually split into triangles first

Page 7: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Dividing Polygons into TrianglesDividing Polygons into Triangles

• [Reminder]

• Convex polygons:– No indentations– Can join any pair of vertices

without going outside of polygon

• Otherwise concave– Split into convex polygons first

• Polygons can always be split into triangles as shown

• Multiple simple approaches for convex polygons

Page 8: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Face NormalsFace Normals

• A mesh is often defined together with a set of face and/or vertex normals

• A face (polygon) normal is a normalised vector at right angles to a polygon in the mesh

• Together with the vertices of the polygon this defines the plane of the polygon

• Face normals generally point outwards– Defining the outside of the mesh surface

• Face normals can be calculated from polygon edges– Use a math operation called the Cross Product– Will see this in more detail later

Page 9: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Vertex NormalsVertex Normals

• Vertex normals can be defined for each vertex in a mesh

• They can be calculated:– Calculate the face normals– Average all face normals of the polygons

containing the vertex

• Or can be defined by hand– No rule about which direction vertex

normals must face (see next slide)

• Vertex normals used for lighting– To define the mesh curvature

• Widely useful elsewhere– Often just called normals

Page 10: Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.

Multiple Vertex NormalsMultiple Vertex Normals

• Examples on last slide used one normal per vertex to define a smooth surface

• Can have multiple vertex normals on a single vertex

• To indicate that certain edges are “sharp”

• Will see this further when we cover lighting