Computação Gráfica Módulo III – Geometria UniverCidade - Prof. Ismael H F Santos April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1
Considerações Gerais Objetivo: Discutir os principais conceitos eos princípios básicos dos Sistemas Gráficos e a Programação em OpenGL. A quem se destina : Alunos e Profissionais que desejem aprofundar seus conhecimentos sobre Computação Grafica e suas aplicações. April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 2
Bibliografia http://www.lcg.ufrj.br/compgraf1/downloads/apostila.ps.gz Computação Gráfica Volume 1. Jonas Gomes e Luiz Velho. Instituto de Matemática Pura e Aplicada – IMPA. Introdução a Computação Gráfica - Paulo Roma http://www.lcg.ufrj.br/compgraf1/downloads/apostila.pdf http://www.lcg.ufrj.br/compgraf1/downloads/apostila.ps.gz Notas do Curso ministrado na Universidade de Maryland pelo Prof. David Mount ftp://ftp.cs.umd.edu/pub/faculty/mount/427/427lects.ps.gz http://www.lcg.ufrj.br/~esperanc/CG/427lects.ps.gz Apostila Fundamentos da Imagem Digital – Antonio Scuri Computer Graphics: Principles and Practice, Second Edition. James Foley, Andries van Dam, Steven Feiner, John Hughes. Addison-Wesley. OpenGL Programming Guide, 2nd Edition. Mason Woo, Jackie Neider, Tom Davis. Addison Wesley. April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 3
Bibliografia OpenGL OpenGL® Programming Guide, 2nd Edition. Mason Woo, Jackie Neider, Tom Davis. Addison Wesley. http://www.lcg.ufrj.br/redbook Manual de referência online http://www.lcg.ufrj.br/opengl Sítio oficial do OpenGL www.opengl.org April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 4
Ementa Introdução ao OpenGL Exemplos de Transformações 2D Geometria Exemplos de Transformações 2D Fórmulas e cálculos das transformações 2D Usando matriz de transformação (por que?) Coordenadas Homogêneas Concatenação de transformações Transformações 3D Projeções Histórico April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 5
Paradigma dos 4 universos CG – CO023 Paradigma dos 4 universos April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 6
Transformações Geométricas April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 7
Transformações Geométricas CG – CO023 Transformações Geométricas April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 8
Exemplos de Transformações 2D Translação Escala uniforme não uniforme Rebatimento por um eixo (espelhamento) Troca de eixos Rotação pela origem April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 9
Translação Translation of a point is simply vector addition y -2 -1 P1 P2 = P1 + P2 1 2 3 -2 -1 = + x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 10
Escala Scaling about the origin is scalar multiplication y 2 1 = 2 * P2 = P1 * 2 x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 11
Rebatimento por um eixo (espelhamento) x = x y = -y April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 12
Troca de Eixos x = y y = x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 13
Rotação pela Origem y x P´ P x´ y´ x´ = x.cos q - y.sen q y´ = x.sen q + y.cos q April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 14
Por que usar Matriz nas Transformações? Todas as transformações podem ser efetuadas através da multiplicação de matrizes (usando coordenadas homogêneas). As transformações podem ser aninhadas e resolvidas de modo a haver apenas uma matriz de multiplicação a ser aplicada. A característica descrita acima se torna muito importante quando a mesma seqüência de transformações deve ser aplicada para diversos pontos. April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 15
Multiplicação de Matrizes = é ë ê ù û ú a b c d x y x’ y’ onde: + a x b y x’ = + c x d y y’ = April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 16
Uniform Scaling , ù û ú = S é ë ê s = P é ë ê ù û ú x y , = M S P = é = P é ë ê ù û ú x y , = M S P = é ë ê ù û ú s x y , = I é ë ê ù û ú 1 = M s é ë ê ù û ú x y M = s I P , April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 17
Non-uniform Scaling = S é ë ê ù û ú s = P é ë ê ù û ú x y é s ù é s x 1 2 = P é ë ê ù û ú x y é s ù é s x ù é x ù ê 1 ú ê 1 ú ê ê ú ê ú ú = ê ú ê ú ê ú s ë y û s y ë û ë û 2 2 Note orientation shift in line April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 18
Non-uniform Scaling y x P P´ Redução (0< sx <1) , Aumento (sy >1) x y P = x x´ P´ = y´ x´ sx x y = y´ sy April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 19
= é ë ê ù û ú x - y 1 -1 Flip an Axis... -1 What does this do to appearance of objects? April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 20
= é ë ê ù û ú y x 1 Swap Axes April 05 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 21
Rotate by , = M R P é ë ê ù û ú ( ) cos q - sin x y = é ë ê ù û ú - + April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 22
Transformações Geométricas (Translação) y P’ x’ x y tx ty P’ = = + y’ tx ty P t = x x´ x y ? ? Não pode ser escrito na forma = y´ ? ? x´ 1 x y tx ty Ruim para implementação = + y´ 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 23
Vantagens das coordenadas homogêneas (Translação) w y t x w=1 yh x’ y’ 1 1 tx ty x y 1 x’ y’ P’ = = = xh [T] Matriz de Translação April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 24
Coordenadas homogêneas y x y 1 wx wy w xh yh w x y = D = D P = = P x x = xh /w w>0 y = yh /w yh xh w w=1 x y Ex.: 3 2 1 6 4 2 9 6 3 3 2 = D = D = April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 25
Vantagens das coordenadas homogêneas (pontos no infinito) w H1 w 2 3 u = y w=1 C1 H2 = C2 C3 x u H3 w=1 yh uh H1 H2 H3 H4 uh xh 2 3 2 3 1 2 3 1/2 2 3 1/4 2 3 . . . 2 3 = ? C1 C2 C3 C4 infinito na direção (2,3) 1 1.5 2 3 4 6 8 12 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 26
Vantagens das coordenadas homogêneas (pontos no infinito, exemplo) 3 1 -2 A B C D x y O 1 -1 2 A’ B’ C’ D’ x y O’ infinito -1 1 2 3 1 -2 1 1 3 1 -2 2 1 4 2 2 1 J J = = = 3 1 -2 1 1 3 1 -2 2 4 2 -1 = -1 J -2 = -2 J = -1 1 1 1 2 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 27
Efeito de profundidade x x y y April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 28
Simplificação da projeção cônica Projeção ortográfica eye plano de projeção direção de projeção April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 29 plano de projeção
Concatenação a a x y x0 y0 y y0 x0 x y y x x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 30
Concatenação de Transformações x y x y T1 x y x y T2 x y R1 x y R2 E P’= T2 R2 E R1 T1 P April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 31
Composição com sistema local/móvel X2 Y2 Y X X Y P2 X Y = P = X Y X1 Y1 T P1 = R P1= T P e P2 = R P1 P2 = R T P P2 = X2 Y2 X Y x y X Y X Y x y P3 = X3 Y3 P = X Y T’ R T’ = R T R-1 P3= R P e P2 = T’ P3 P2 = R T R-1 R P ou P2 = R T P April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 32
Geometria Projetiva e Coordenadas Homogêneas em 3D z x y xh yh zh w x y z 1 m11 m12 m13 m14 m21 m22 m23 m24 m31 m32 m33 m34 m41 m42 m43 m44 = P’ = x’ y’ z’ xh /w yh/w zh/w P x y z = April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 33
Transformações em 3D (translações e escalas) y x’ y’ z’ 1 1 tx x 1 ty y x = 1 tz z z 1 1 x’ y’ z’ 1 sx x sy y = sz z 1 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 34
Transformações em 3D (Rotações) x’ y’ z’ 1 1 x x y cos qx -sen qx y = qy sen qx cos qx z 1 1 x’ y’ z’ 1 cos qy sen qy x qx 1 y qz z = -sen qy cos qy z 1 1 x’ y’ z’ 1 cos qz -sen qx x sen qx cos qx y = 1 z 1 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 35
Transformações em 3D (rotação em torno de um eixo qualquer) y’ z’ 1 m11 m12 m13 x m21 m22 m23 y z 1 = m31 m32 m33 z 1 v = (vx, vy, vz) m11 = vx2 + cosq (1- vx2) m12 = vxvy(1-cosq ) - vz sen q m13 = vzvx(1-cosq ) + vy sen q m21 = vxvy(1-cosq ) + vz sen q m22 = vy2 + cosq (1- vy2) m23 = vyvz(1-cosq ) - vx sen q m31 = vxvz (1-cosq ) - vy sen q m32 = vyvz(1-cosq )+ vx sen q m22 = vz2 + cosq (1- vz2) y x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 36
CG – CO023 Projeções April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 37
Projeções Planas Cônicas Ap B Bp realista não preserva escala não preserva ângulos April 05
Projeções Planas Paralelas Ap B Bp pouco realista preserva paralelismo possui escala conhecida April 05
Classificação das projeções planas Paralelas ortográficas dp // n plantas elevações iso-métrica oblíquas dp não é paralela a n cavaleiras cabinet Cônicas 1 pto de fuga 2 ptos de fuga 3 ptos de fuga April 05
Projeções de um cubo Paralelas Cônicas a 1/2 a 1 planta ou elevação iso-métrica Cabinete (a=45 ou 90) Cavaleira (a=45 ou 90) Cônicas 1 pto de fuga 2 ptos de fuga April 05
Projeção plana é uma transformação linear? Ou seja: T(P+Q) = T(P)+T(Q) e T(aP) = aT(P) ? 2V V 2V plano de projeção (2V)p¹ 2(Vp) V 2Vp Vp O Vp O cp cp Projeções cônicas não são TL, paralelas podem ser. April 05
Projeção plana paralela é uma transformação linear? T(P+Q) = T(P)+T(Q) ? P O Q Qp Pp P+Q retas paralelas projetam em paralelas Qp Pp Pp+ Qp T( 0 ) = 0 ? Projeção paralela em plano que passa pela origem é uma transformação linear April 05
Matrizes de projeções Cavaleiras e Cabinetes y y M 1 (1,1,1) k a 1 x x z Â3 Â2 T(1,0,0) = (1,0) T(0,1,0) = (0,1) T(0,0,1) = ( -k cos a, -k sin a ) 1 0 -k.cos(a) M = 0 1 -k.sin(a) April 05
Matrizes de projeções pseudo-isométricas y y M j jp 1 (1,1,1) x i x kp ip k z Â3 Â2 T(1,0,0) = (cos 30 ,-sin 30) T(0,1,0) = (0,1) T(0,0,1) = (-cos 30, -sin 30) cos30 0 -cos30 M = -sin30 1 -sin30 April 05
Projeção cônica simples xe ye ze P Pp zp = -d xe xp d -ze = ye yp d -ze = xe ye xp yp d ye yp -ze = d xp xe -ze = -ze d d = n April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 46 xe y z e e z e
Projeção cônica simples xe xp -ze = d xe ye ze P Pp d ye yp -ze = zp = -d xp yp zp 1 d -1 xe d xe d ye d ze -ze (d/-ze) xe (d/-ze) ye -d 1 ye ze 1 = = = ¸ w w April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 47
Simplificação da projeção cônica Projeção ortográfica eye plano de projeção direção de projeção plano de projeção April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 48
Distorce o frustum de visão para o espaço da tela xe ye ze ze = -n ze = -f n -1 [ P ] = d = n xe ye ze ze = -n ze = -f April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 49
Uma equação para profundidade Ptos no near (z=-n): Ptos no far (z=-f): n n+f -1 n Ÿ f [ P ] = April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 50
Translada o paralelepípedo de visão para origem xe ye ze t b [ T ] = 1 -(r+l)/2 -(t+b)/2 +(f+n)/2 l r xe ye ze (t-b)/2 -(t-b)/2 -(r-l)/2 (r-l)/2 (f-n)/2 -(f-n)/2 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 51
Escala o paralelepípedo de visão no cubo [-1,1]x[-1,1]x[-1,1] xe ye ze (t-b)/2 -(t-b)/2 -(r-l)/2 (r-l)/2 (f-n)/2 -(f-n)/2 near far 2/(r-l) 1 2/(t-b) -2/(f-n) [S] = xd yd zd 1 -1 near far April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 52
Matriz Frustum do OpenGL n+f -1 n Ÿ f [ P ] = [S T P ] = [ T ] = 1 -(r+l)/2 -(t+b)/2 +(f+n)/2 OpenGL Spec [S] = 2/(r-l) 1 2/(t-b) -2/(f-n) April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 53
Projeção Cônica (Frustum) void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_, GLdouble far_ ); view frustum ye ze xe camera (eye) Obs.: near e far são distâncias( > 0) Plano de projeção left right top bottom far near April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 54 xe ye ze ze
Projeção Cônica (Perspective) void glPerspective( GLdouble fovy, GLdouble aspect, GLdouble near_, GLdouble far_ ); ye w aspect = w/h ze h xe near far fovy xe ze April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 55
Matriz Ortho do OpenGL OpenGL Spec [ T ] = [S] = -(r+l)/2 -(t+b)/2 1 1 -(r+l)/2 -(t+b)/2 +(f+n)/2 OpenGL Spec [S] = 2/(r-l) 1 2/(t-b) -2/(f-n) April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 56
Projeção Paralela (Ortho) near ye top far bottom ze A xe left right void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_, GLdouble far_ ); void gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top ); April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 57
Glu Look At void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz); Dados: eye, ref, up (definem o sistema de coordenadas do olho) Determine a matriz que leva do sistema de Coordenadas dos Objetos para o sistema de Coordenadas do Olho up eye center Coordenadas dos Objetos Coordenadas do Olho April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 58
Calcula o sistema - xe ye ze vup center eye z0 y0 x0 view dados: eye, center, up view = center - eye vup ze eye view z0 y0 x0 center ze = – view / ||view|| April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 59
Calcula o sistema - xe ye ze center eye vup z0 y0 x0 view ze xe xe = (vup x ze) / ||vup x ze|| center eye vup z0 y0 x0 view ze xe ye eye vup ze xe ye view ye = ze x xe April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 60
Translada o eye para origem center eye z0 y0 x0 ze xe ye 1 0 0 -eyex 0 1 0 -eyey 0 0 1 -eyez 0 0 0 1 [ T ] = z0 y0 x0 center eye ze xe ye April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 61
Roda xe ye ze para xo yo zo xex xey xez 0 yex yey yez 0 zex zey zez 0 0 0 0 1 z0 y0 x0 center eye ze xe ye xe , xo ye , yo ze , zo April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 62
Matriz Look At do OpenGL 1 0 0 -eyex 0 1 0 -eyey 0 0 1 -eyez 0 0 0 1 [ T ] = ze = – view / ||view|| [ R T ] =? xe = (vup x ze) / ||vup x ze|| ye = ze x xe [ R ] = xex xey xez 0 yex yey yez 0 zex zey zez 0 0 0 0 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 63
Concatenação das transformações z0 y0 x0 center eye ze xe ye [ R ] xe ye ze [ T ] [ P ] center eye z0 y0 x0 ze xe ye xe ye ze [ T2 ] [ T ] [ R ] [ P ] [ T2 ] [ S ] xe ye ze [ S ] xe ye ze 1 -1 near far April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 64
CG – CO023 Visualização OpenGL April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 65
Simplificação da projeção cônica Projeção ortográfica eye plano de projeção direção de projeção April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 66 plano de projeção
Problema do clipping ye ze xe ¸ w ye P2 P1 ze xe P’1 P’2 n n n+f -1 n n+f -1 nŸf 1 n -1 1 -n n -n2 n+f -1 nŸf = 1 n -1 = = n n2+2nf -n-2f 1 -n 1 xe ye ze ¸ w P’1 P’2 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 67
Clipping em coordenadas homogêneas xd yd zd 1 -1 near far right left bottom top x Î [left, right] y Î [bottom, top] z Î [near, far] -1 £ x £ 1 -1 £ y £ 1 -1 £ z £ 1 -1 £ xh/w £ 1 -1 £ yh/w £ 1 -1 £ zh/w £ 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 68
Clipping em coordenadas homogêneas x Î [left, right] y -1 £ xh/w £ 1 x xh £ w , se w>0 -1 1 xh/w £ 1 xh ³ w , se w<0 OpenGL Spec April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 69
Clipping em coordenadas homogêneas y x Î [left, right] -1 1 x -1 £ xh/w £ 1 xh -w = 0 1 -1 x xh £ w xh £ -w não serve! w < 0 (ze>0) w xh ³ w -1 xh ³ -w -xh -w = 0 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 70
Equação de um plano N.P = Ax + By + Cz N.P = N.(P0 + D P) = N.P0 = d (N.DP = 0) d = Ax + By + Cz N=(A,B,C) z Ax + By + Cz +D = 0 P0 D P d P=(x,y,z) (A, B, C) = N e D = -d = N.(-P0 ) O y x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 71
Distância de um ponto a um plano N.P = Ax + By + Cz N=(A,B,C) N.P =N.(Pp +D P ) D P P=(x,y,z) N.P = d + N.D P z N.D P = Ax + By + Cz+D Pp O y x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 72
Interseção de reta com plano d1 = | Ax1 + By1 + Cz1+D | d1 P d2 = | Ax2 + By2 + Cz2+D | z d2 P2 P = d1 P2 + d2 P1 d1 + d2 y x April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 73
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 ); April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 74
Transformação para o Viewport void glViewport(GLint x0, GLint y0, GLsizei width, GLsizei height ); xw = x0 + w*(xd -(-1)) / 2 yw = y0 +h*(yd -(-1)) / 2 zw = zd / 2 + 1/2 yw xd yd zd 1 -1 h w xw April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 75 zw[0..1]
Transformações de um vértice OpenGL Spec April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 76
Modelo do Pintor profundidade z April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 77
Problemas na ordenação de faces + + za zb April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 78
BSP trees: Binary Space Partion Trees 1 2 3 4 5a 5b 3 frente atrás 1 2 5a 4 5b 1 2 3 4 5a 5b 3 frente atrás 2 4 5b frente atrás 5a 1 1 2 3 4 5a 5b 3 2 4 5a 1 5b April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 79
Exibição de uma BSP void bspDisplay(bspTree *tree) { if (arvore não é vazia) { if (observador está a frente da raiz) { bspDisplay(tree®backChild); DisplayPolygon(tree®root); bspDisplay(tree®frontChild); } else { Mostra a árvore de trás, a raiz e a árvore da frente. Mostra a árvore da frente, a raiz e a árvore de atrás. April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 80
BSP trees: Dois exemplos de exibição 1 2 3 4 5a 5b 5a, 2, 1, 3, 5b, 4 1 2 3 4 5a 5b 4, 5b, 3, 5a, 2, 1 April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 81
ZBuffer: idéia básica z MATRIZ DE PROFUNDIDADES April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 82
Rasterização de Polígonos e Linhas April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 83
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 ); April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 84