36
Introduction to 3D Introduction to 3D Graphics Graphics Lecture 3: General Lecture 3: General Camera Model Camera Model Anthony Steed Anthony Steed University College London University College London

Introduction to 3D Graphics Lecture 3: General Camera Model

  • Upload
    yitro

  • View
    28

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to 3D Graphics Lecture 3: General Camera Model. Anthony Steed University College London. Overview. More Maths Rotations and translations Homogenous co-ordinates General Camera Specification Mapping to world coordinates. Vectors and Matrices. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to 3D Graphics Lecture 3: General Camera Model

Introduction to 3D GraphicsIntroduction to 3D Graphics

Lecture 3: General Camera Lecture 3: General Camera ModelModel

Anthony SteedAnthony Steed

University College LondonUniversity College London

Page 2: Introduction to 3D Graphics Lecture 3: General Camera Model

OverviewOverview

More MathsMore Maths– Rotations and translationsRotations and translations– Homogenous co-ordinatesHomogenous co-ordinates

General CameraGeneral Camera– SpecificationSpecification– Mapping to world coordinatesMapping to world coordinates

Page 3: Introduction to 3D Graphics Lecture 3: General Camera Model

Vectors and MatricesVectors and Matrices

Matrix is an array of numbers with Matrix is an array of numbers with dimensions M (rows) by N (columns)dimensions M (rows) by N (columns)– 3 by 6 matrix3 by 6 matrix– element 2,3element 2,3

is (3)is (3)

Vector can be considered a 1 x M Vector can be considered a 1 x M matrixmatrix–

zyxv

100025

114311

212003

Page 4: Introduction to 3D Graphics Lecture 3: General Camera Model

Types of MatrixTypes of Matrix

Identity matrices - Identity matrices - II

Diagonal Diagonal

1001

1000010000100001

Symmetric Symmetric

– Diagonal matrices Diagonal matrices are (of course) are (of course) symmetricsymmetric

– Identity matrices Identity matrices are (of course) are (of course) diagonaldiagonal

4000010000200001

fecedbcba

Page 5: Introduction to 3D Graphics Lecture 3: General Camera Model

Operation on MatricesOperation on Matrices

AdditionAddition– Done elementwiseDone elementwise

TransposeTranspose– ““Flip” (M by N becomes N by M)Flip” (M by N becomes N by M)

s d r cq b p a

s rq p

d cb a

389

724

651

376

825

941T

Page 6: Introduction to 3D Graphics Lecture 3: General Camera Model

Operations on MatricesOperations on Matrices

MultiplicationMultiplication– Only possible to multiply of dimensionsOnly possible to multiply of dimensions

xx11 by y by y11 and x and x22 by y by y22 iff y iff y11 = x = x22 – resulting matrix is xresulting matrix is x1 1 byby yy22

e.g. Matrix A is 2 by 3 and Matrix by 3 by e.g. Matrix A is 2 by 3 and Matrix by 3 by 44

– resulting matrix is 2 by 4resulting matrix is 2 by 4 Just because A x B is possible doesn’t mean Just because A x B is possible doesn’t mean

B x A is possible! B x A is possible!

Page 7: Introduction to 3D Graphics Lecture 3: General Camera Model

Matrix Multiplication OrderMatrix Multiplication Order

A is n by k , B is k by A is n by k , B is k by mm

C = A x B defined byC = A x B defined by

BxA not necessarily BxA not necessarily equal to AxBequal to AxB

k

l

ljilij bac1

*

*****

*****

*.

*.*.*.*.*.

*****

*...

*.*.*.*.*.

*****.....

Page 8: Introduction to 3D Graphics Lecture 3: General Camera Model

Example MultiplicationsExample Multiplications

____

____

1011

12

101132

__________________

010001100

111013322

Page 9: Introduction to 3D Graphics Lecture 3: General Camera Model

InverseInverse

If A x B = I and B x A = I thenIf A x B = I and B x A = I then

A = BA = B-1-1 and B = A and B = A-1-1

Page 10: Introduction to 3D Graphics Lecture 3: General Camera Model

3D Transforms3D Transforms

In 3-space vectors are transformed In 3-space vectors are transformed by 3 by 3 matricesby 3 by 3 matrices

ziyfxczhyexbzgydxa

ihg

fed

cba

zyx

Page 11: Introduction to 3D Graphics Lecture 3: General Camera Model

ScaleScale

Scale uses a diagonal matrixScale uses a diagonal matrix

Scale by 2 along x and -2 along zScale by 2 along x and -2 along z

zcybxac

ba

zyx

000000

1046200

010002

543

Page 12: Introduction to 3D Graphics Lecture 3: General Camera Model

RotationRotation

Rotation about z axisRotation about z axis

Note Note z values z values remain the same whilst remain the same whilst x and y changex and y change

1000)θcos()θsin(-0)θsin()θcos(

Y

X

θ yx

yθ cosxθ sin yθ sin-xθ cos

Page 13: Introduction to 3D Graphics Lecture 3: General Camera Model

Rotation X, Y and ScaleRotation X, Y and Scale

About XAbout X

About YAbout Y

Scale (should look Scale (should look familiar)familiar)

)θcos()θsin(-0

)θsin()θcos(0

001

)θcos(0)θsin(

010

)θsin(-0)θcos(

c

b

a

00

00

00

Page 14: Introduction to 3D Graphics Lecture 3: General Camera Model

Homogenous PointsHomogenous Points

Add 1D, but constrain that to be equal Add 1D, but constrain that to be equal to 1 (x,y,z,1)to 1 (x,y,z,1)

Homogeneity means that any point in 3-Homogeneity means that any point in 3-space can be represented by an infinite space can be represented by an infinite variety of homogenous 4D pointsvariety of homogenous 4D points– (2 3 4 1) = (4 6 8 2) = (3 4.5 6 1.5)(2 3 4 1) = (4 6 8 2) = (3 4.5 6 1.5)

Why?Why?– 4D allows as to include 3D translation in 4D allows as to include 3D translation in

matrix formmatrix form

Page 15: Introduction to 3D Graphics Lecture 3: General Camera Model

Homogenous VectorsHomogenous Vectors

Vectors != Points Vectors != Points Remember points can not be Remember points can not be

addedadded If A and B are points A-B is a vectorIf A and B are points A-B is a vector Vectors have form (x y z 0)Vectors have form (x y z 0) Addition makes senseAddition makes sense

Page 16: Introduction to 3D Graphics Lecture 3: General Camera Model

Translation in Translation in Homogenous FormHomogenous Form

Note that the homogenous Note that the homogenous component is preserved (* * * 1), component is preserved (* * * 1), and aside from the translation the and aside from the translation the matrix is I matrix is I

1

1010000100001

1 czbyax

cba

zyx

Page 17: Introduction to 3D Graphics Lecture 3: General Camera Model

Putting it TogetherPutting it Together

R is rotation and scale componentsR is rotation and scale components T is translation componentT is translation component

1000

321

987

654

321

TTTRRRRRRRRR

Page 18: Introduction to 3D Graphics Lecture 3: General Camera Model

1432

1432010000100001

1

1432010000100001

1000001001000001

1

YZXYZXZYX

1442

1000

0010

0100

0001

1442

1000

0010

0100

0001

1432

0100

0010

0001

1

YZXZYXZYX

Order MattersOrder Matters

Composition order of transforms Composition order of transforms mattersmatters– Remember that basic vectors change so Remember that basic vectors change so

“direction” of translations changed“direction” of translations changed

Page 19: Introduction to 3D Graphics Lecture 3: General Camera Model

OverviewOverview

More MathsMore Maths– Rotations and translationsRotations and translations– Homogenous co-ordinatesHomogenous co-ordinates

General CameraGeneral Camera– SpecificationSpecification– Mapping to world coordinatesMapping to world coordinates

Page 20: Introduction to 3D Graphics Lecture 3: General Camera Model

Simple Camera Simple Camera (Cross Section)(Cross Section)

Z -Z

Yd

COP

ymax

ymin

Page 21: Introduction to 3D Graphics Lecture 3: General Camera Model

General CameraGeneral Camera

View Reference Point (VRP)View Reference Point (VRP)– where the camera iswhere the camera is

View Plane Normal (VPN)View Plane Normal (VPN)– where the camera pointswhere the camera points

View Up Vector (VUV)View Up Vector (VUV)– which way is up to the camerawhich way is up to the camera

X (or U-axis) forms X (or U-axis) forms LHLH system system

Page 22: Introduction to 3D Graphics Lecture 3: General Camera Model

UVN Co-ordindatesUVN Co-ordindates

View Reference Point (VRP)View Reference Point (VRP)– origin of VC systemorigin of VC system

View Plane Normal (VPN)View Plane Normal (VPN)– Z (or N-axis) of VC systemZ (or N-axis) of VC system

View Up Vector (VUV)View Up Vector (VUV)– determines Y (or V-axis) of VCSdetermines Y (or V-axis) of VCS

X (or U-axis) forms X (or U-axis) forms LHLH system system

Page 23: Introduction to 3D Graphics Lecture 3: General Camera Model

World Coords and Viewing World Coords and Viewing CoordsCoords

Y

X

Z

V U

N

VUV

VRP

1000

321

987

654

321

TTTRRRRRRRRR

We want to find a general transform (EQ1) of

the above form that will map WC to VC

Page 24: Introduction to 3D Graphics Lecture 3: General Camera Model

View from the CameraView from the Camera

VUV

N and VPN into the page

U

V

XYZ

xmin, ymin

xmax, ymax

Page 25: Introduction to 3D Graphics Lecture 3: General Camera Model

Finding the basis vectorsFinding the basis vectors

Step 1 - find nStep 1 - find n

Step 2 - find uStep 2 - find u

Step 3 - find vStep 3 - find v

||VPN

VPNn

VUVn

VUVnu

nuv

Page 26: Introduction to 3D Graphics Lecture 3: General Camera Model

Finding the Mapping (1)Finding the Mapping (1)

u,v,n must rotate under R to i,j,k of u,v,n must rotate under R to i,j,k of viewing spaceviewing space

Both basis are normalised so this is a Both basis are normalised so this is a pure rotation matrix pure rotation matrix – recall in this case Rrecall in this case RTT = R = R-1-1

IR

nvu

333

232

111

nvunvunvu

R

Page 27: Introduction to 3D Graphics Lecture 3: General Camera Model

Finding the Mapping (2)Finding the Mapping (2)

In uvn system VRP (q) is (0 0 0 In uvn system VRP (q) is (0 0 0

1)1)

And we know from EQ1 And we know from EQ1

so so

3

1

3

1

3

1 i

ii

i

ii

i

ii nqvquq

qRt0 tqR

Page 28: Introduction to 3D Graphics Lecture 3: General Camera Model

Complete MappingComplete Mapping

Complete matrixComplete matrix

1

000

3

1

3

1

3

1

333

222

111

i

ii

i

ii

i

ii nqvquq

nvunvunvu

M

Page 29: Introduction to 3D Graphics Lecture 3: General Camera Model

For you to checkFor you to check

IfIf

ThenThen

1

0qRRM

101

qRM

T

Page 30: Introduction to 3D Graphics Lecture 3: General Camera Model

Using this for Ray-CastingUsing this for Ray-Casting

Use a similar camera configuration Use a similar camera configuration (COP is usually, but not always on -(COP is usually, but not always on -n)n)

To trace object must eitherTo trace object must either– transform spheres into VCtransform spheres into VC– transform rays into WCtransform rays into WC

Page 31: Introduction to 3D Graphics Lecture 3: General Camera Model

Ray-castingRay-casting

Transforming rays into WCTransforming rays into WC– Transform end-point onceTransform end-point once– Find direction vectors through COP as Find direction vectors through COP as

beforebefore

– Transform vector byTransform vector by

– Intersect spheres in WC Intersect spheres in WC

10

qRT

Page 32: Introduction to 3D Graphics Lecture 3: General Camera Model

Ray-castingRay-casting

Transforming spheres into VCTransforming spheres into VC– Centre of sphere is a point so can be Centre of sphere is a point so can be

transformed as usual (WC to VC)transformed as usual (WC to VC)– Radius of sphere is unchanged by Radius of sphere is unchanged by

rotation and translation (and spheres rotation and translation (and spheres are spheroids if there is a non-are spheroids if there is a non-symmetric scale)symmetric scale)

Page 33: Introduction to 3D Graphics Lecture 3: General Camera Model

TradeoffTradeoff

If more rays than spheres do the If more rays than spheres do the formerformer– transform spheres into VCtransform spheres into VC

For more complex scenes e.g. with For more complex scenes e.g. with polygons polygons – transform rays into WCtransform rays into WC

Page 34: Introduction to 3D Graphics Lecture 3: General Camera Model

Alternative Forms of the Alternative Forms of the CameraCamera

Simple “Look At”Simple “Look At”– Give a VRP and a target (TP)Give a VRP and a target (TP)– VPN = TP-VRPVPN = TP-VRP– VUV = (0 1 0) (i.e. “up” in WC)VUV = (0 1 0) (i.e. “up” in WC)

Field of ViewField of View– Give horizontal and vertical FOV or one or Give horizontal and vertical FOV or one or

the other and an aspect ratiothe other and an aspect ratio

– Calculate viewport and proceed as beforeCalculate viewport and proceed as before

Page 35: Introduction to 3D Graphics Lecture 3: General Camera Model

Animated CamerasAnimated Cameras

Animate VRP (observer-cam)Animate VRP (observer-cam) Animate VPN (look around)Animate VPN (look around) Animate TP (track-cam)Animate TP (track-cam) Animate COP Animate COP

– along VPN - zoomalong VPN - zoom– orthogonal to VPN - distortorthogonal to VPN - distort

Page 36: Introduction to 3D Graphics Lecture 3: General Camera Model

SummarySummary

We set up the mathematics of We set up the mathematics of transformations between co-transformations between co-ordinate spacesordinate spaces

We created a more general We created a more general camera which we can use to create camera which we can use to create views of our scenes from arbitrary views of our scenes from arbitrary positionspositions

Formulation of mapping from WC Formulation of mapping from WC to VC (and back)to VC (and back)