Upload
internet
View
143
Download
2
Embed Size (px)
Citation preview
Visualização do OpenGL
Simplificação da projeção cônica
plano de projeçãoeye
Projeção cônica
plano de projeção
direção de projeção
Projeção ortográfica
Problema do clipping
xe
ye
ze
P1P2
1
1
-n
1
n
n
-n2
n
1
1
-n
1
n
0
0
0
0
n
0
0
0
0
n+f
-1
0
0
nŸf
0
= =
n
0
0
0
0
n
0
0
0
0
n+f
-1
0
0
nŸf
0
1
1
n
1
=
n
n
n2+2nf
-n
-1
-1
-n-2f
1
=
xe
ye
ze
P’1
P’2
w
Clipping em coordenadas homogêneas
-1 xh/w 1 -1 yh/w 1 -1 zh/w 1
-1 x 1 -1 y 1 -1 z 1
x[left, right] y[bottom, top]z[near, far]
xd
yd
zd
111
-1-1-1
nearfarright
left
bottom
top
Clipping em coordenadas homogêneas
x[left, right]y
-1 xh/w 1
-1 1
x
xh/w 1
xh w , se w>0 xh w , se w>0
xh w , se w<0 xh w , se w<0
OpenGL Spec
Clipping em coordenadas homogêneas
x[left, right]y
-1 xh/w 1
-1 1
x
x
w
xh w
xh -w
xh w
xh -w
não serve!w < 0(ze>0)
1
0
0
-1
-1
0
0
-1
-xh -w = 0 -xh -w = 0
xh -w = 0 xh -w = 0
O
Equação de um plano
N=(A,B,C)
P=(x,y,z)
x
y
z
P0
N.P = N.(P0 + P) = N.P0 = d N.P = N.(P0 + P) = N.P0 = d
P
d = Ax + By + Cz d = Ax + By + Cz
d
N.P = Ax + By + Cz N.P = Ax + By + Cz
Ax + By + Cz +D = 0Ax + By + Cz +D = 0
(A, B, C) = NeD = -d = N.(-P0 )
(A, B, C) = NeD = -d = N.(-P0 )
(N.P = 0)
O
Distância de um ponto a um plano
N=(A,B,C)
P=(x,y,z)
Pp
x
y
z
P
N.P = Ax + By + Cz N.P = Ax + By + Cz
N.P = Ax + By + Cz+D N.P = Ax + By + Cz+D
N.P =N.(Pp +P ) N.P =N.(Pp +P )
N.P = d + N.P N.P = d + N.P
Interseção de reta com plano
P1
P2
x
y
z
d1 = | Ax1 + By1 + Cz1+D |
d1
d2
d2 = | Ax2 + By2 + Cz2+D | P
P =d1 P2 + d2 P1
d1 + d2
Cálculo das distâncias
/* ===================== Distance ======================**** This function computes and returns the distance between a** point and a plane. Normal points toward out.*/double Distance(double x, double y, double z, double w, int plane ){ switch( plane ) { case 0: return( -w - x ); case 1: return( -w + x ); case 2: return( -w - y ); case 3: return( -w + y ); case 4: return( -w - z ); case 5: return( -w + z ); } return( 0.0 );}
Transformação para o Viewport
xd
yd
zd
111
-1-1-1
xw
yw
w
h
xw = x0 + w*(xd -(-1)) / 2yw = y0 +h*(yd -(-1)) / 2
zw = zd / 2 + 1/2
xw = x0 + w*(xd -(-1)) / 2yw = y0 +h*(yd -(-1)) / 2
zw = zd / 2 + 1/2
0
void glViewport(GLint x0, GLint y0, GLsizei width, GLsizei height );
zw[0..1]
Transformações de um vértice
OpenGL Spec
Modelo do Pintor
prof
undidad
e
z
Problemas na ordenação de faces
+ +
zazb
(a)
(b)
BSP trees: Binary Space Partion Trees
1
23
4
5a5b
3
12
5a
45b
atrásfrente
1
23
4
5a5b
3
45b
atrásfrente
2frente atrás
5a 1
1
23
4
5a5b
3
2
5a 1
4
5b
Exibição de uma BSP
void bspDisplay(bspTree *tree){ if (arvore não é vazia) { if (observador está a frente da raiz) { bspDisplay(treebackChild); DisplayPolygon(treeroot); bspDisplay(treefrontChild); } else { bspDisplay(treefrontChild); DisplayPolygon(treeroot); bspDisplay(treebackChild); } }}
Mostra a árvore detrás, a raiz e a árvoreda frente.
Mostra a árvore dafrente, a raiz e a árvorede atrás.
BSP trees: Dois exemplos de exibição
1
23
4
5a5b
3
2
5a 1
4
5b
5a, 2, 1, 3, 5b, 45a, 2, 1, 3, 5b, 4
1
23
4
5a5b
3
2
5a 1
4
5b
4, 5b, 3, 5a, 2, 14, 5b, 3, 5a, 2, 1
ZBuffer: idéia básica
z
MATRIZ DEPROFUNDIDADES
Rasterização de Polígonos e Linhas
ZBuffer - pseudo-código
void ZBuffer( void){ int x,y;
for (x=0; x<w; x++) { for (y=0;y<h; y++) { WritePixel(x,y, bck_color); WriteZ(x,y,0); } }
for (each primitive) { for (each pixel in the projected primitive) { double pz = z coordinate of the (x,y) pixel; if (pz <= ReadZ(x,y)) { WritePixel(x,y, color); WriteZ(x,y,pz); } } }
} /* Zbuffer */void glEnable( GL_DEPTH_TEST );void glEnable( GL_DEPTH_TEST );
Interpolação de cores
void glShadeModel (GL_SMOOTH);void glShadeModel (GL_SMOOTH);
void glShadeModel (GL_FLAT);void glShadeModel (GL_FLAT);
Suavização da tonalização
c1 c4
c2
c3
c12 c43c
N1 N4
N2
N3
N12 N43
c
GouraudPhong
N