Upload
jacob-tucker
View
253
Download
4
Embed Size (px)
Citation preview
10.1Si23_03
SI23Introduction to Computer
Graphics
SI23Introduction to Computer
Graphics
Lecture 10 – Introduction to 3D Graphics
10.2Si23_03
Course OutlineCourse Outline
ImageDisplay
URLGIMP
colour
2D vectorgraphics
URL SVGViewer
lines,areas
graphicsalgorithms
interaction
VRMLviewer
3DGraphics
URL
surfaces
viewing, shading
GraphicsProgramming
OpenGLAPI
animation
Graphics programming
– Using OpenGL with C, C++
10.3Si23_03
2D Graphics – Picture Description
2D Graphics – Picture Description
SVG is a vector graphics description language<?xml version="1.0" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width = "300" height = "300">
<rect x = "100" y = "100" width = "100" height = "100" style = "fill:red" />
</svg>
SVG Viewer
10.4Si23_03
2D Graphics – Programming Approach
2D Graphics – Programming Approach
For programming graphics, there are a number of APIs, or Application Programming Interfaces
OpenGL is industry standard
– Both 2D and 3D
User Programcalling OpenGL
functions
OpenGL Library
10.5Si23_03
Objectives for This PartObjectives for This Part
To understand how 3D scenes can be modelled - in terms of geometry and appearance - and rendered on a display
To be able to program interactive 3D graphics applications using industry standard software (OpenGL)
10.6Si23_03
Lecture Outline - The Basics
Lecture Outline - The Basics
MODELLING and VIEWING– representing objects in 3D– transforming objects and composing scenes– specifying the camera viewpoint
PROJECTION– projecting 3D scenes onto a 2D display surface
RENDERING– illumination– shading– adding realism via textures, shadows
10.7Si23_03
Basic Modelling and Viewing
Basic Modelling and Viewing
x
y
z
objects representedas set of faces - iepolygons- and facesas a set of points
scenes composedby scaling, rotating,translating objects tocreate a 3D world
camera
Camera positionspecified, togetherwith its direction of view
10.8Si23_03
ProjectionProjection
Projection– 3D scene is projected onto a 2D
plane
camera
viewplane
10.9Si23_03
A PuzzleA Puzzle
10.10Si23_03
RenderingRendering
??
shading:how do we use ourknowledge of illuminationto shade surfaces in ourworld?
illumination:how is light reflectedfrom surfaces?
10.11Si23_03
RenderingRendering
texture
shadows
10.12Si23_03
Creating 3D GraphicsCreating 3D Graphics
OpenGL is an API that allows us to program 3D graphics
– As well as 2D
VRML is a language that allows us to describe 3D graphics scenes
– Cf SVG for 2D
10.13Si23_03
Applications - Computer Games
Applications - Computer Games
10.14Si23_03
Applications - Computer-Aided Design
Applications - Computer-Aided Design
This is Hubble Space Telescope modeled using the BRL-CAD system
Uses CSG modeling and ray tracing for rendering
http://ftp.arl.mil/brlcad
10.15Si23_03
Applications - Virtual Reality
Applications - Virtual Reality
Virtual oceanarium built for EXPO in Lisbon
Example taken from Fraunhofer Institute site
http://www.igd.fhg.de
10.16Si23_03
Before we begin...mathematics!
Before we begin...mathematics!
3D Co-ordinate Systems
LEFT RIGHT
x
yz
x
y
z
z points away z points toward
Align thumb with x, first finger with y, then second fingerof appropriate hand gives z direction. Common now touse a RIGHT HANDED system.
10.17Si23_03
Points and VectorsPoints and Vectors
We shall write points as column vectors
xyz
P =
Difference of two points gives a direction vector:D = P2 - P1
x
y
z
P2
P1
x
y
z
P
Note: If P1 and P2
are on a plane, thenD lies in the plane
10.18Si23_03
Magnitude of a VectorMagnitude of a Vector
The magnitude of a vector V = (v1,v2,v3)T is given by:
|V| = sqrt(v1*v1 + v2*v2 + v3*v3)
eg (1,2,3)T has magnitude sqrt(14) A unit vector has magnitude 1 A unit vector in the direction of
V is V / |V|
10.19Si23_03
Scalar or Dot ProductScalar or Dot Product
The scalar product, or dot product, of two vectors U and V is defined as:
U.V = u1*v1 + u2*v2 + u3*v3
It is important in computer graphics because we can show that also:
U.V = |U|*|V|*coswhere is the angle between U and V
This lets us calculate angle ascos = (u1*v1 + u2*v2 + u3*v3) / (|U|*|V|)
10.20Si23_03
Diffuse LightingDiffuse Lighting
Diffuse reflection depends on angle between light direction and surface normal:reflected intensity = light intensity *
cosine of angle between light direction and surface normal
light normal
scalar product letsus calculate cos
10.21Si23_03
Vector or Cross ProductVector or Cross Product
The vector or cross product is defined as:UxV = (u2v3 - u3v2, u3v1 - u1v3, u1v2 - u2v1)
We can also show that:UxV = N |U||V| sin where N is unit vector orthogonal to U and V
(forming a right handed system) and is angle between U and V
This allows us to find the normal to a plane
– cross-product of two directions lying in plane , eg (P3-P2), (P2-P1), where P1, P2, P3 are three points in the plane
10.22Si23_03
ExercisesExercises
Convince yourself that the x-axis is represented by the vector (1,0,0)
What is the unit normal in the direction (2,3,4)?
What is the angle between the vectors (1,1,0) and (1,0,0)?
Which vector is orthogonal to the vectors (1,0,0) and (0,1,0)?
What is the normal to the plane through the points (1,2,3), (3,4,5) and (0,0,0)?
10.23Si23_03
Polygonal RepresentationPolygonal Representation
Any 3D object can be represented as a set of plane, polygonal surfaces
V1
V2V3
V4
V5V8
V7 V6
Note: each vertex part of severalpolygons
10.24Si23_03
Polygonal RepresentationPolygonal Representation
Objects with curved surfaces can be approximated by polygons - improved approximation by more polygons
10.25Si23_03
Scene OrganisationScene Organisation
Scene = list of objects Object = list of surfaces Surface = list of polygons Polygon = list of vertices
scene
objectsurfaces polygons
vertices
10.26Si23_03
Polygon Data StructurePolygon Data Structure
V1
V2V3
V4
V5V8
V7 V6
P1
P2
Object Table
Obj1P1, P2, P3,P4, P5, P6
Object Obj1
Vertex Table
V1X1, Y1, Z1
V2X2, Y2, Z2
. ...
Polygon Table
P1 V1, V2, V3, V4
P2 V1, V5, V6, V2
. .... ...
10.27Si23_03
Typical PrimitivesOrder of VerticesTypical PrimitivesOrder of Vertices
Graphics systems such as OpenGL typically support:
– triangles, triangle strips and fans– quads, quad strips– polygons
How are vertices ordered?– convention is that vertices are ordered
counter-clockwise when looking from outside an object
– allows us to distinguish outer and inner faces of a polygon
10.28Si23_03
Complex PrimitivesComplex Primitives
OpenGL has utility libraries (GLU and GLUT) which contain various high-level primitives– Sphere, cone, torus– Polygonal representation
constructed automatically Similarly for VRML For conventional graphics
hardware:– POLYGONS RULE!
10.29Si23_03
Automatic Generation of Polygonal Objects
Automatic Generation of Polygonal Objects
3D laser scanners are able to generate computer representations of objects
– for successive heights, 2d outline generated as object rotates
– contours stitched together into 3D polygonal representation
Cyberware Cyberscanner in Med Physics at LGI able to scan human faces
10.30Si23_03
Modelling Regular ObjectsModelling Regular Objects
Sweeping
Spinning
2D Profilesweep axis
spinning axis
R1 R2
10.31Si23_03
Sweeping a Circle to Generate a Cylinder as
Polygons
Sweeping a Circle to Generate a Cylinder as
Polygons
vertices at z=0
vertices at z=depthV1
V2
V3V4
V5
V6 V8
V7
V10
V9
V11
V12V13
V14
V15V16
V17
V18
V1[x] = R; V1[y] = 0; V1[z] = 0V2[x] = R cos ; V2[y] = R sin ; V2[z] = 0 (=/4)Vk[x] = R cos k; Vk[y] = R sin k; Vk[z] = 0wherek = 2 (k - 1 )/8, k=1,2,..8
10.32Si23_03
Exercise and Further Reading
Exercise and Further Reading
Spinning:– Work out formulae to spin an
outline (in the xy plane) about the y-axis
READING:– Hearn and Baker, Chapter 10