Académique Documents
Professionnel Documents
Culture Documents
• Motivation
Synthèse d'image avancée • Rappels d’algèbre linéaire
• Transformations
Cours 2: Transformations, • Caméra sténopé, projection
perspective et caméras
Motivation Motivations
X
Y
Z
Z
Motivations Plan
• Motivation
• Positionner dans le repère de la caméra
• Rappels d’algèbre linéaire
• Transformations
• Modèle caméra sténopé
• (E, +, ·, K)
• E espace vectoriel (EV) sur K si • Combinaison linéaire dans E: ∑ a avec a ∈ E
i
i i i
[ ]
b M= f 21 f 22 f 23 g 11 g 12 g 13 Vecteurs de base
b'
f 31 f 32 f 33 b B= g 21 g 22 g 23 de b exprimés
g 31 g 32 g 33 dans b'
Image des vecteurs de base par f
• Notation pratique:
b'
Points: x =bb' B b x
d
Concaténation de transformations x =dc B cb B ba B a x Définition 2:
Le produit scalaire entre 2 vecteur v1 (x1,y1,z1) et v2 (x2,y2,z2) est défini par :
v1.v2 = x1*x2 + y1*y2 + z1*z2 (dans une base orthogonale)
Fonctions: b M =ba B a M ab B
Autres définitions Espaces affines
• On commence en 2D
– Plus facile à se représenter • Modification simple :
• Chaque point est transformé: • x’ = x+tx
• y’ = y+ty
– x’ = f(x,y)
– y’ = g(x,y)
• Quelle forme pour la transformation ?
Avant Après
Avant Après
Notation matricielle Rotation
• Rotation de coordonnées en 2D :
• C’est une multiplication matricielle :
• x’ = cosθ x - sinθ y
P’ = SP • y’ = sinθ x + cosθ y
S=
[ sx
0
0
sy ] θ
Avant Après
Unification
Notation matricielle
• Notation simple, concise
• Mais pas vraiment unifiée
• Rotation = multiplication matricielle :
– problème de représentation des translations
P’=RP – Comment faire pour concaténer plusieurs
transformations, translation + rotation ?
S= [ cos −sin
sin cos ] • On veut une notation unique
– Comment faire ?
En terme de
changement de
base?
Coordonnées homogènes Coordonnées homogènes
• Outil géométrique très puissant : géométrie • Deux points sont égaux si et seulement si :
projective – x’/w’ = x/w et y’/w’= y/w
[ ][ ]
x x
[ ] x =
y
y =
1
y
w
[ ][ ] [ ][ ]
1 0 tx x sx 0 0 x
0 1 ty
0 0 1
y
w [ x /wt x
y /w t y ] 0 sy 0
0 0 1
y
w [ sx x / w
s y y /w ]
[ ] [ ]
x w t x sx x
yw t y sy y
w w
Échelle en coordonnées homogènes Rotation en coordonnées homogènes
[ 1 0 0
0 1 0
0 0 1/ s ][ ] x
y
w [ s x /w
s y/ w ] [ cos −sin 0
sin cos 0
0 0 1 ][ ] x
y
w [ x / w cos − y / w sin
x / w sin y / w cos ]
[ ]x
y
w /s [ x cos − y sin
x sin y cos
w ]
Composition des transformations Rotation autour d’un point Q
• Toutes les transformations 2D peuvent être exprimées – Rotation autour de l’origine (RΘ)
comme des matrices en coord. homogènes
– Translater en retour vers Q (- TQ).
– Notation très générale
P’=(TQ)RΘTQ P
Et en 3 dimensions ? Translations en 3D ?
• C’est pareil
[ ]
• On introduit une quatrième coordonnée, w 1 0 0 tx
– Deux vecteurs sont égaux si : 0 1 0 ty
x/w = x’/w’, y/w = y’/w’ et z/w=z’/w’
• Toutes les transformations sont des matrices 4x4 0 0 1 tz
0 0 0 1
[ ][ ][ ]
x x
x
y = y
y =
z z
z
1 w
[ ]
• La matrice dépend de l’axe et de l’angle
sx 0 0 0 • Expression directe possible, en partant de l’axe et de l’angle, et
quelques produits vectoriels
0 sy 0 0 – Passage par les quaternions
[ ] [ ]
1 0 0 0 cos 0 sin 0
axe x axe y
0 cos −sin 0 invariant
0 1 0 0
invariant
0 sin cos 0 −sin 0 cos 0
0 0 0 1 0 0 0 1
Vérification: une rotation de π/2 Vérification: une rotation de π/2
devrait changer y en z, et z en y devrait changer z en x, et x en z
[ ]
cos −sin 0 0 • Rotation autour d’un axe n:
sin cos 0 0 axe z
– Changement de repère (Bn) où n devient l’axe x
invariant
0 0 1 0
– Rotation autour de x (RΘ)
0 0 0 1
– Changement de repère en retour vers B-1
n.
Vérification: une rotation de π/2
devrait changer x en y, et y en x -1
P’=BnRΘBn P
Toutes les transformations 3D Attention !
x
Comment faire ? Coordonnées relatives
• Utiliser les coordonnées relatives :
– La position de l’avant-bras est donné en fonction du bras
• Dessiner le bras
– La position des boulons par rapport à la roue
• Translation sur la position de l’avant-bras par rapport au bras
• Dessiner l’avant-bras
• Que faire ?
– translate+rotate
• Dessiner l’objet = traversée de la hiérarchie
– draw second wheel
transl. x • glMatrixMode(GL_MODELVIEW)
• glLoadIdentity
body
• glRotatef, glTranslatef...
transl. transl.
transl. • glScalef
1st wh. 2nd wh. • glPushMatrix, glPopMatrix
Rot. α
• cf TD2, Tutorial Nate Robins
Objets ré-utilisables
1st arm
•Une procédure pour toutes les roues
•Principe du graphe de scène …
(OpenSG...)
Projections et perspectives Projections
• isométrique, orthographique,…
• Projection perspective :
– Plusieurs types :
[ ][ ][ ]
0 0 0 0 1 0 0 0 1 0 0 0
P x= 0 1 0 0 Py= 0 0 0 0 P z= 0 1 0 0
0 0 1 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 1 0 0 0 1
][ ]
x
[ ][
f x f 0 0 0
y
f y = 0 f 0 0
z
z 0 0 1 0
1
Ouverture Projection perspective
tan =1/ f
f f • Projection sur le plan z=0, avec le centre de projection
placé à z=-f (convention OpenGL):
Point de vue 1
[ ]
α
1 0 0 0
P= 0 1 0 0
1 0 0 1/ f 0
Plan de
projection
• glOrtho
• glFrustum
• gluPerspective
• gluLookAt
• conventions de repère différentes
• gestion de la pyramide de vue (clipping)