Skip to content

Instantly share code, notes, and snippets.

@juandjara
Created May 19, 2017 17:38
Show Gist options
  • Save juandjara/792a21ab0ecf2868f81267b740dded51 to your computer and use it in GitHub Desktop.
Save juandjara/792a21ab0ecf2868f81267b740dded51 to your computer and use it in GitHub Desktop.
practica repaso examen de MVG
clear
w = 500;
h = 500;
x = 0;
y = 0;
bg = 'white';
marco(x,y,w,h, bg);
ventana(0.1, 0.1, 0.8, 0.8, -6,6, -1,9, -2,2);
pol1_x = [-1 -1 1 1];
pol1_y = [0 1 1 0];
pol2_x = [-1 0 1];
pol2_y = [0 1 0];
center1_x = mean(pol1_x);
center1_y = mean(pol2_y);
center1 = [center1_x; center1_y; 0; 1];
center2_x = mean(pol2_x);
center2_y = mean(pol2_y);
center2 = [center2_x; center2_y; 0; 1];
pol1 = [pol1_x; pol1_y; zeros(1, length(pol1_x)); ones(1, length(pol1_x))];
pol2 = [pol2_x; pol2_y; zeros(1, length(pol2_x)); ones(1, length(pol2_x))];
%T1 = traslacion([0 (2 - center1_y ) 0 ]);
T2 = traslacion([0 5 0]);
s1 = [2 5 1];
s2 = [2 3 1];
S1 = escalado(s1, [0;0;0]);
S2 = escalado(s2, [0;0;0]);
T3 = traslacion([0 5.5 0]);
S3 = escalado([0.25 0.5 1], [0;0;0]);
T4 = traslacion([0 4 0]);
S4 = escalado([0.5 2 1], [0;0;0]);
R = rotacion(pi/4, [0;6;0], 'z');
R2 = rotacion(pi/2, [0;6;0], 'z');
base = S1 * pol1;
tejado = T2 * S2 * pol2;
ventana_izq = traslacion([1 3.5 0]) * S3 * pol1;
ventana_cen = traslacion([0 3.5 0]) * S3 * pol1;
ventana_der = traslacion([-1 3.5 0]) * S3 * pol1;
aspa = R * T4 * S4 * pol2;
aspa2 = R2 * R * T4 * S4 * pol2;
aspa3 = R2 * R2 * R * T4 * S4 * pol2;
aspa4 = R2 * R2 * R2 * R * T4 * S4 * pol2;
A = afilamiento([1 1], 'x');
hierba = A * escalado([0.25 0.5 0], [0;0;0]) * pol1;
% la funcion simetria recibe el vector normal al eje
M = simetria([1 0 0]);
SA = escalado([0.25 0.5 0], [0;0;0]);
hierba2 = M * A * SA * pol1;
hold on;
fill(base(1, :), base(2, :), 'white');
fill(tejado(1, :), tejado(2, :), [0.7 0.5 0.3]);
fill(ventana_izq(1, :), ventana_izq(2, :), 'black');
fill(ventana_cen(1, :), ventana_cen(2, :), 'black');
fill(ventana_der(1, :), ventana_der(2, :), 'black');
fill(aspa(1, :), aspa(2, :), 'black');
fill(aspa2(1, :), aspa2(2, :), 'black');
fill(aspa3(1, :), aspa3(2, :), 'black');
fill(aspa4(1, :), aspa4(2, :), 'black');
fill(hierba(1, :), hierba(2, :), 'green');
fill(hierba2(1, :), hierba2(2, :), 'green');
plot(0, 6, '.', 'MarkerSize', 40, 'color', 'black');
Vert = [-1 1 0 1 -1 1 0 1;
0 1 0 -1 0 1 0 -1;
0 0 0 0 4 4 4 4;
1 1 1 1 1 1 1 1];
Caras = [1 2 3 4; 5 6 7 8; 1 2 6 5; 3 4 8 7; 3 2 6 7];
color = ones(6,3);
figure(1);
dibujarEscena(Vert, Caras, color);
P = [1 0 -5];
Pm = [0 0 0];
L = 1;
FOV = 40;
C = camara(P, Pm, L);
Vp = P * C * Vert;
dim = dimension_ventana(L, FOV);
figure(2);
dibujarPerspectiva(Vp, dim, Caras, color);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment