matrices de projection en synthèse d'images -...

19
Projection orthogonale Projection perspective LookAt Rotate Householder St´ er´ eoscopique Panoramique Bilan Matrices de projection en synth` ese d’images Vincent Nozick Vincent Nozick Matrices de projectionen synth` ese d’images 1 / 66 Projection orthogonale Projection perspective LookAt Rotate Householder St´ er´ eoscopique Panoramique Bilan Projections Les 2 principales projections : projection orthogonale projection perspective Vincent Nozick Matrices de projectionen synth` ese d’images 2 / 66 Projection orthogonale Projection perspective LookAt Rotate Householder St´ er´ eoscopique Panoramique Bilan Projections Remarque : une projection orthogonale, c’est une projection perspective avec une focale infinie, prise d’infiniment loin. Vincent Nozick Matrices de projectionen synth` ese d’images 3 / 66 Projection orthogonale Projection perspective LookAt Rotate Householder St´ er´ eoscopique Panoramique Bilan Projections Autres projections : panoramique (projection sur une sph` ere / un cylindre) cam´ era ` a d´ ecentrement Vincent Nozick Matrices de projectionen synth` ese d’images 4 / 66

Upload: truongtuong

Post on 08-Nov-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Matrices de projectionen synthese d’images

Vincent Nozick

Vincent Nozick Matrices de projectionen synthese d’images 1 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projections

Les 2 principales projections :

projection orthogonale projection perspective

Vincent Nozick Matrices de projectionen synthese d’images 2 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projections

Remarque :une projection orthogonale, c’est une projection perspective avecune focale infinie, prise d’infiniment loin.

Vincent Nozick Matrices de projectionen synthese d’images 3 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projections

Autres projections :

• panoramique (projection sur une sphere / un cylindre)

• camera a decentrement

Vincent Nozick Matrices de projectionen synthese d’images 4 / 66

Page 2: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

OpenGL

Principe : cube unitaire

Transformations :

• [l, r]→ [−1, 1]• [b, t]→ [−1, 1]• [n, f ]→ [−1, 1] (non lineaire)

orthogonale

perspective

Vincent Nozick Matrices de projectionen synthese d’images 5 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

OpenGL

near et far :pourquoi borne-t-on l’information de profondeur ?→ pour plus de precision sur le z-bufferpour avoir des profondeurs relatives plus precises

Remarque :la representation de la profondeur n’est pas lineaire : moins deprecision pour les objets lointains.

Vincent Nozick Matrices de projectionen synthese d’images 6 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

Vincent Nozick Matrices de projectionen synthese d’images 7 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale

Supprime l’information de profondeur.

Vincent Nozick Matrices de projectionen synthese d’images 8 / 66

Page 3: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale

Supprime l’information de profondeur.

Vincent Nozick Matrices de projectionen synthese d’images 8 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale

Matrice de projection basique :xy01

=

1 0 0 00 1 0 00 0 0 00 0 0 1

xyz1

ou bien : x

y1

=

1 0 0 00 1 0 00 0 0 1

xyz1

Vincent Nozick Matrices de projectionen synthese d’images 9 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale

En OpenGL :

• on conserve l’information en z pour le clipping/z-buffer

• on la supprime ensuite pour la projectionxyz1

=

1 0 0 00 1 0 00 0 1 00 0 0 1

xyz1

Vincent Nozick Matrices de projectionen synthese d’images 10 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

T =

1 0 0 − r+l

2

0 1 0 − t+b2

0 0 1 −f+n2

0 0 0 1

M =

2r−l 0 0 0

0 2t−b 0 0

0 0 2f−n 0

0 0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 11 / 66

Page 4: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

T =

1 0 0 − r+l

2

0 1 0 − t+b2

0 0 1 −f+n2

0 0 0 1

M =

2r−l 0 0 0

0 2t−b 0 0

0 0 2f−n 0

0 0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 11 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

T =

1 0 0 − r+l

2

0 1 0 − t+b2

0 0 1 −f+n2

0 0 0 1

M =

2r−l 0 0 0

0 2t−b 0 0

0 0 2f−n 0

0 0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 11 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

T =

1 0 0 − r+l

2

0 1 0 − t+b2

0 0 1 −f+n2

0 0 0 1

M =

2r−l 0 0 0

0 2t−b 0 0

0 0 2f−n 0

0 0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 11 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

M =

2r−l 0 0 0

0 2t−b 0 0

0 0 2f−n 0

0 0 0 1

T =

1 0 0 − r+l

2

0 1 0 − t+b2

0 0 1 −f+n2

0 0 0 1

P = MT =

2r−l 0 0 − r+l

r−l

0 2t−b 0 − t+b

t−b

0 0 2f−n −f+n

f−n

0 0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 12 / 66

Page 5: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

PGL =

2r−l 0 0 − r+l

r−l

0 2t−b 0 − t+b

t−b

0 0 −2f−n −f+n

f−n

0 0 0 1

Remarques :

• ×(−1) car OpenGL regarde dans les −z• r 6= l, t 6= b et n 6= f

• pour le clipping → ignorer ce qui depasse du cube unitaire

• on conserve les z pour le z-buffer

Vincent Nozick Matrices de projectionen synthese d’images 13 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection orthogonale OpenGL

PGL =

2r−l 0 0 − r+l

r−l

0 2t−b 0 − t+b

t−b

0 0 −1 0

0 0 0 1

gluOrtho2d :

• extension de glOrtho

• avec near = −1 et far = 1

Vincent Nozick Matrices de projectionen synthese d’images 14 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Vincent Nozick Matrices de projectionen synthese d’images 15 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Vincent Nozick Matrices de projectionen synthese d’images 16 / 66

Page 6: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Vincent Nozick Matrices de projectionen synthese d’images 17 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective

modele du stenope (pinhole camera)

Vincent Nozick Matrices de projectionen synthese d’images 18 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective

modele du stenope (pinhole camera)

Vincent Nozick Matrices de projectionen synthese d’images 18 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective

modele du stenope (pinhole camera)

Vincent Nozick Matrices de projectionen synthese d’images 18 / 66

Page 7: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective

modele du stenope (pinhole camera)

Vincent Nozick Matrices de projectionen synthese d’images 18 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective

Theoreme de Thales

A′xn

=AxAz

=⇒ A′x = nAxAz

Vincent Nozick Matrices de projectionen synthese d’images 18 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective

A′x = nAxAz

A′y = nAyAz

A′z = n

A′ =

nAxAz

nAyAz

n

1

.=

Ax

Ay

AzAzn

Vincent Nozick Matrices de projectionen synthese d’images 19 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective

Matrice de projection basique :

A′ =

AxAyAzAzn

=

1 0 0 00 1 0 00 0 1 00 0 1

n 0

AxAyAz1

Note : finalement la projection se fait vraiment quand on met lacoordonnee homogene a 1

Vincent Nozick Matrices de projectionen synthese d’images 20 / 66

Page 8: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

glFrustum :

• near, far

• left, right

• top, bottom

Vincent Nozick Matrices de projectionen synthese d’images 21 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Projection Pn sur le plan near :

Pn =

1 0 0 0

0 1 0 0

• • • •0 0 1

n 0

.=

n 0 0 0

0 n 0 0

• • • •0 0 1 0

Remarque : et les z, pourquoi on les garde encore?→ pour le clipping et pour le z-buffer

Vincent Nozick Matrices de projectionen synthese d’images 22 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Normer [n, f ] 7→ [−1, 1] :

⇒ avec une loi en 1z

• avec plus de precision vers le plan near

Vincent Nozick Matrices de projectionen synthese d’images 23 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Normer [n, f ] 7→ [−1, 1] : avec une loi en 1z

1z → z′ =

A

z+B avec [n, f ] 7→ [−1, 1]

−1 =A

n+B

1 =A

f+B

A = − 2fn

f − n

B =f + n

f − n

⇒ z′ = − 2fn

f − n1

z+f + n

f − n

Vincent Nozick Matrices de projectionen synthese d’images 24 / 66

Page 9: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Normer [n, f ] en [−1, 1] : avec une loi en 1z

z′ = − 2fn

f − n1

z+f + n

f − n⇒ Pz =

1 0 0 00 1 0 0

0 0 f+nf−n − 2fn

f−n0 0 1 0

→ divise aussi les x et y par z, comme Pn

xzyz

f+nf−n −

2fnf−n

1z

1

=

xy

f+nf−nz −

2fnf−n

z

=

1 0 0 00 1 0 0

0 0 f+nf−n − 2fn

f−n0 0 1 0

xyz1

Vincent Nozick Matrices de projectionen synthese d’images 25 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Eric Lengyel - Mathematics for 3D Games Programming and Computer Graphics

Vincent Nozick Matrices de projectionen synthese d’images 26 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Combiner Pn et Pz : → projection perspective et gestion des z

Pn =

n 0 0 00 n 0 0• • • •0 0 1 0

Pz =

1 0 0 00 1 0 0

0 0 f+nf−n − 2fn

f−n0 0 1 0

Pnz =

n 0 0 00 n 0 0

0 0 f+nf−n − 2fn

f−n0 0 1 0

Remarque : combinaison possible car w est identique pour Pn et Pz.

Vincent Nozick Matrices de projectionen synthese d’images 27 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Normer [l, r] en [−1, 1] :x′ = 2× x− l

r − l− 1

y′ = 2× y − bt− b

− 1

x′ =

2x

r − l− r + l

r − l

y′ =2y

t− b− t+ b

t− b

Ps =

2r−l 0 0 − r+l

r−l0 2

t−b 0 − t+bt−b

0 0 1 0

0 0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 28 / 66

Page 10: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Au final :

Ps =

2r−l 0 0 − r+l

r−l

0 2t−b 0 − t+b

t−b

0 0 1 0

0 0 0 1

Pnz =

n 0 0 0

0 n 0 0

0 0 f+nf−n − 2fn

f−n

0 0 1 0

P = PsPnz =

2nr−l 0 − r+l

r−l 0

0 2nt−b −

t+bt−b 0

0 0 f+nf−n − 2fn

f−n

0 0 1 0

Vincent Nozick Matrices de projectionen synthese d’images 29 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Au vrai final :

PGL =

2nr−l 0 r+l

r−l 0

0 2nt−b

t+bt−b 0

0 0 −f+nf−n − 2fn

f−n

0 0 −1 0

Remarques :

• ×(−1) car OpenGL regarde dans les −z• r 6= l, t 6= b et n 6= f

• pour le clipping → ignorer ce qui depasse du cube unitaire

• pour le z-buffer

Vincent Nozick Matrices de projectionen synthese d’images 30 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Frustum symetrique : si r = −l et t = −b

glFrustum :

• near, far

• right

• top

Vincent Nozick Matrices de projectionen synthese d’images 31 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Frustum symetrique : si r = −l et t = −b

{r + l = 0r − l = 2r (largeur)

{t+ b = 0t− b = 2t (hauteur)

PGL =

nr 0 0 0

0 nt 0 0

0 0 −f+nf−n − 2fn

f−n

0 0 −1 0

Vincent Nozick Matrices de projectionen synthese d’images 32 / 66

Page 11: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

gluPerspective :

• fov y (f ield of view) : angle de vue θy en vertical

• aspect ratio : a =largeur

hauteur• near et far

Vincent Nozick Matrices de projectionen synthese d’images 33 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

gluPerspective

t = −b = n tan(θy2

) (cot =

1

tan

)r = −l = a× t = a× n tan

(θy2

)

PGL =

cot(θy2

)/a 0 0 0

0 cot(θy2

)0 0

0 0 −f+nf−n − 2fn

f−n0 0 −1 0

Vincent Nozick Matrices de projectionen synthese d’images 34 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Matrice de projection infinie : (pas de far)

glFrustum∞ :

• near

• left, right

• top, bottom

Vincent Nozick Matrices de projectionen synthese d’images 35 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Matrice de projection infinie : (pas de far)

PGL∞ = limf 7→∞

2nr−l 0 r+l

r−l 0

0 2nt−b

t+bt−b 0

0 0 −f+nf−n − 2fn

f−n

0 0 −1 0

PGL∞ =

2nr−l 0 r+l

r−l 0

0 2nt−b

t+bt−b 0

0 0 −1 −2n

0 0 −1 0

Vincent Nozick Matrices de projectionen synthese d’images 36 / 66

Page 12: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Matrice de projection infinie : et pour les points a l’infini ?

−x′

z

−y′

z

1

1

=

x′

y′

−z

−z

=

2nr−l 0 r+l

r−l 0

0 2nt−b

t+bt−b 0

0 0 −1 −2n

0 0 −1 0

x

y

z

0

→ dans le cube unitaire, z = 1 correspond au plan far

Vincent Nozick Matrices de projectionen synthese d’images 37 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Projection perspective OpenGL

Matrice de projection infinie : stabilite numerique et rendu OpenGL

PGL∞ =

2nr−l 0 r+l

r−l 0

0 2nt−b

t+bt−b 0

0 0 ε− 1 (ε− 2)n

0 0 −1 0

avec ε ' 2, 4.10−7 (pour des float32)

Applications :

• skybox, soleil, lune et etoiles

• stencil shadow volume

Vincent Nozick Matrices de projectionen synthese d’images 38 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Placement de la camera

LookAt :

• eye

• view

• up

Vincent Nozick Matrices de projectionen synthese d’images 39 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

LookAt(eye,view,up)

• on pose : u =up

‖up‖et v =

view − eye

‖view − eye‖

• un vecteur “cote” w serait : w =v × u

‖v × u‖• le vecteur up corrige est : u2 = w × v

→ systeme de coordonnees camera dans le referentiel de la scene

Vincent Nozick Matrices de projectionen synthese d’images 40 / 66

Page 13: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

LookAt

Mref =

wx u2x −vx 0wy u2y −vy 0wz u2z −vz 00 0 0 1

T =

1 0 0 −eyex0 1 0 −eyey0 0 1 −eyez0 0 0 1

changement de referentiel positionnement de la camera

Vincent Nozick Matrices de projectionen synthese d’images 41 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

LookAt

MlookAt = T.Mref =

wx u2x −vx −eyexwy u2y −vy −eyeywz u2z −vz −eyez0 0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 42 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Placement de la camera

glRotate :

• axe : a = (ax, ay, az)>

• angle : θ

Vincent Nozick Matrices de projectionen synthese d’images 43 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Rotate

Methode :

• rotation M pour faire correspondre l’axe a avec l’axe des z

• rotation d’angle θ autour de l’axe des z

• rotation M−1 =M>

Vincent Nozick Matrices de projectionen synthese d’images 44 / 66

Page 14: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

faire correspondre l’axe a avec l’axe des z

Etape 1 : rotation Rxz autour de l’axe des z vers le plan xz.

Rxz =

cosβ sinβ 0− sinβ cosβ 0

0 0 1

avec :

• cosβ =axh

=ax√a2x + a2y

• sinβ =ayh

=ay√a2x + a2y

Vincent Nozick Matrices de projectionen synthese d’images 45 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

faire correspondre l’axe a avec l’axe des z

Etape 1 : rotation Rxz autour de l’axe des z vers le plan xz. →

Rxz =

ax√a2x+a

2y

ay√a2x+a

2y

0

− ay√a2x+a

2y

ax√a2x+a

2y

0

0 0 1

Remarques :

• Rxza = (√a2x + a2y, 0, az)

>

• Rxz est bien une matrice de rotation (RxzR>xz = Id)

• ne fonctionne pas en l’etat si a = (0, 0, 1)>

Vincent Nozick Matrices de projectionen synthese d’images 46 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

faire correspondre l’axe a avec l’axe des z

Etape 2 : rotation Ry autour de l’axe des y vers l’axe z.

Ry =

cos γ 0 sin γ0 1 0

− sin γ 0 cos γ

avec :

• cos γ =azh

=az√

a2x + a2y + a2z

• sin γ =a′xh

=

√a2x + a2y√

a2x + a2y + a2z

Vincent Nozick Matrices de projectionen synthese d’images 47 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

faire correspondre l’axe a avec l’axe des z

Etape 2 : rotation Ry autour de l’axe des y vers l’axe z.

Ry =

az√

a2x+a2y+a

2z

0 −√a2x+a

2y√

a2x+a2y+a

2z

0 1 0√a2x+a

2y√

a2x+a2y+a

2z

0 az√a2x+a

2y+a

2z

Vincent Nozick Matrices de projectionen synthese d’images 48 / 66

Page 15: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Etape 3 : rotation θ autour de l’axe des z.

Rθ = Rz(θ) =

cos θ sin θ 0− sin θ cos θ 0

0 0 1

Vincent Nozick Matrices de projectionen synthese d’images 49 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

retour au repere initial

Etape 4 : rotation R>y et R>xz

• R−1y = R>y

• R−1xz = R>xz

Vincent Nozick Matrices de projectionen synthese d’images 50 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Au final

Finalement :

R = R>xzR>y RθRyRxz =

a2x+(a2y+a2z)cθ

a2x+a2y+a2z

axay(1−cθ)−az√√√√√a2x+a2y+a2zsθ

a2x+a2y+a2z

axaz(1−cθ)+ay√√√√√a2x+a2y+a2zsθ

a2x+a2y+a2z

axay(1−cθ)+az√√√√√a2x+a2y+a2zsθ

a2x+a2y+a2z

a2y+(a2x+a2z)cθ

a2x+a2y+a2z

ayaz(1−cθ)−ax√√√√√a2x+a2y+a2zsθ

a2x+a2y+a2z

axaz(1−cθ)−ay√√√√√a2x+a2y+a2zsθ

a2x+a2y+a2z

ayaz(1−cθ)+ax√√√√√a2x+a2y+a2zsθ

a2x+a2y+a2z

a2z+(a2x+a2y)cθ

a2x+a2y+a2z

cθ = cos θ et sθ = sin θ

Vincent Nozick Matrices de projectionen synthese d’images 51 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Au vrai final

Finalement : si a est norme : a2x + a2y + a2z = 1

R = R>xzR>y RθRyRxz =

a2x + (1− a2x) cos θ axay(1− cos θ)− az sin θ axaz(1− cos θ) + ay sin θ

axay(1− cos θ) + az sin θ a2y + (1− a2y) cos θ ayaz(1− cos θ)− ax sin θ

axaz(1− cos θ)− ay sin θ ayaz(1− cos θ) + ax sin θ a2z + (1− a2z) cos θ

Vincent Nozick Matrices de projectionen synthese d’images 52 / 66

Page 16: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Et donc finalement

Version simplifiee : avec a norme : a2x + a2y + a2z = 1

R = Id cos θ + sin θ[a]× + (1− cos θ)aa>

avec :

[a]× =

0 −az ayaz 0 −ax−ay ax 0

et aa> =

a2x axay axazaxay a2y ayazaxaz ayaz a2z

Vincent Nozick Matrices de projectionen synthese d’images 53 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Verifications

R =

a2x + (1− a2x) cos θ axay(1− cos θ)− az sin θ axaz(1− cos θ) + ay sin θ

axay(1− cos θ) + az sin θ a2y + (1− a2y) cos θ ayaz(1− cos θ)− ax sin θ

axaz(1− cos θ)− ay sin θ ayaz(1− cos θ) + ax sin θ a2z + (1− a2z) cos θ

si a = (1, 0, 0)> → R =

1 0 00 cos θ − sin θ0 sin θ cos θ

si a = (0, 1, 0)> → R =

cos θ 0 sin θ0 1 0

− sin θ 0 cos θ

si a = (1, 0, 0)> → R =

cos θ − sin θ 0sin θ cos θ 00 0 1

Vincent Nozick Matrices de projectionen synthese d’images 54 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Matrice de Householder

Definition :

Soit u ∈ Rn, la matrice de Householder Hu est definie par :

Hu = Idn − 2uu>

‖u‖2

ou ‖u‖2 = u>u lorsque u est non nul, et Hu = Idn lorsque u = 0

c’est la matrice de reflexion par rapport a l’hyperplan de normale u.

Vincent Nozick Matrices de projectionen synthese d’images 55 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Matrice de Householder

Proprietes :

Soit u ∈ Rn, alors :

• Hu est symetrique : Hu = H>u .

• Hu est inversible et H−1u = Hu (HuHu = Id).

• Huv = −v, ∀v ∈ Rn colineaire a u.

• Huv = v, ∀v ∈ Rn orthogonal a u.

• Det(Hu) = −1 lorsque u 6= 0 et egale a +1 lorsque u = 0.

En definitive, Hu est la matrice de la reflexion d’hyperplan de nor-male u.

Vincent Nozick Matrices de projectionen synthese d’images 56 / 66

Page 17: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Matrices de projection sur plan

Projection sur un plan :

Soit n ∈ Rn la normale d’un hyper-plan π, la matrice H‖π est la ma-

trice qui projette un vecteur a ∈ Rn sur π, definie par :

H‖π = Id− nn>

‖n‖2a‖ = H‖πa

Vincent Nozick Matrices de projectionen synthese d’images 57 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Matrices de projection sur un axe

Projection sur un plan :Soit n ∈ Rn, la matrice H⊥n est la matrice qui projette un vecteura ∈ Rn sur n, definie par :

H⊥n =nn>

‖n‖2a⊥ = H⊥na

Vincent Nozick Matrices de projectionen synthese d’images 58 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Cameras stereoscopiques

Vincent Nozick Matrices de projectionen synthese d’images 59 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Cameras stereoscopiques

• frusta asymetriques (optiques a decentrement)

• axes optiques paralleles

• distance objet / w ↔ distance ecran / largeur ecran

Vincent Nozick Matrices de projectionen synthese d’images 60 / 66

Page 18: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Panoramique

• mosaıque : projection sur un plan → lineaire(sans objet en synthese d’images)

• panoramique cylindrique :projection sur un cylindre → non-lineaire

• panoramique spherique :projection sur une sphere → non-lineaire

• panoramique cubique :projection sur un cube → lineaire

Vincent Nozick Matrices de projectionen synthese d’images 61 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Panoramique cylindrique

→ un rendu projectif par colonne :

• chaque fenetre de rendu fait h× 1 pixels

• on oriente la camera selon la colonne

Vincent Nozick Matrices de projectionen synthese d’images 62 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Panoramique spherique

→ un rendu projectif par pixel :

• chaque fenetre de rendu fait 1× 1 pixel

• on oriente la camera selon le pixel

Vincent Nozick Matrices de projectionen synthese d’images 63 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Panoramique cubique

→ un rendu projectif par face :

Vincent Nozick Matrices de projectionen synthese d’images 64 / 66

Page 19: Matrices de projection en synthèse d'images - igm.univ-mlv.frigm.univ-mlv.fr/~vnozick/teaching/slides/m2_image/03_matrices... · Projection orthogonaleProjection perspectiveLookAtRotateHouseholderSt

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Panoramique cubique

Rendu equivalent a un rendu panoramique spherique / spherique

Vincent Nozick Matrices de projectionen synthese d’images 65 / 66

Projection orthogonale Projection perspective LookAt Rotate Householder Stereoscopique Panoramique Bilan

Resume

P =

2r−l 0 0 − r+l

r−l

0 2t−b 0 − t+b

t−b

0 0 −2f−n − f+n

f−n

0 0 0 1

P =

2r−l 0 0 − r+l

r−l

0 2t−b 0 − t+b

t−b

0 0 −1 0

0 0 0 1

glOrtho gluOrtho2d

P =

2nr−l 0 r+l

r−l 0

0 2nt−b

t+bt−b 0

0 0 − f+nf−n − 2fn

f−n

0 0 −1 0

P =

cot(θy2

)/a 0 0 0

0 cot(θy2

)0 0

0 0 − f+nf−n − 2fn

f−n

0 0 −1 0

glFrustum gluPerspective

Ps =

nr

0 0 0

0 nt

0 0

0 0 − f+nf−n − 2fn

f−n

0 0 −1 0

P∞ =

2nr−l 0 r+l

r−l 0

0 2nt−b

t+bt−b 0

0 0 ε− 1 (ε− 2)n

0 0 −1 0

frustum symetrique projection infinie (ε = 2.4e−7)

Vincent Nozick Matrices de projectionen synthese d’images 66 / 66