-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXcuadrado.cpp
109 lines (93 loc) · 3.68 KB
/
Xcuadrado.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Xcuadrado.cpp: implementation of the Xcuadrado class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Xcuadrado.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Xcuadrado::Xcuadrado(Punto3D * p1, Punto3D * p2, Punto3D * p3, Punto3D * p4) {
vertices[0] = *p1;
vertices[1] = *p2;
vertices[2] = *p3;
vertices[3] = *p4;
RGBaristas[0] = 0.0;
RGBaristas[1] = 0.0;
RGBaristas[2] = 0.0;
RGBcaras[0] = 1.0;
RGBcaras[1] = 1.0;
RGBcaras[2] = 1.0;
pintar = false;
}
Xcuadrado::Xcuadrado() { }
Xcuadrado::~Xcuadrado() { }
void Xcuadrado::CalcularLandas(Visual v) {
for (int j = 0; j < 4; j++) vertices[j].modL(Figura::calcularLanda(vertices[j], v));
}
void Xcuadrado::CalcularLandaMin() {
double landa = vertices[0].cogerL();
for (int j = 1; j < 4; j++) {
if (landa > vertices[j].cogerL()) {
landa = vertices[j].cogerL();
}
}
landaMin = landa;
}
int Xcuadrado::modNormal(Punto3D n) {
if ((normal.cogerX() == n.cogerX()) && (normal.cogerY() == n.cogerY()) && (normal.cogerY() == n.cogerY())) return -1;
normal = n;
return 0;
}
void Xcuadrado::dibujar(Visual v, Ventana win) {
Punto2D aux1, aux2;
Arista2D aux2D;
Cara2D Cpintar(4);
for (int n = 0; n < 4; n++) {
if ((vertices[n].cogerL() > 0) && (vertices[(n + 1) % 4].cogerL() > 0)) {
aux1 = Figura::punto3Da2D(vertices[n], v, win);
aux2 = Figura::punto3Da2D(vertices[(n + 1) % 4], v, win);
aux2D = Arista2D(&aux1, &aux2);
Cpintar.addArista2D(&aux2D);
}
else if (((vertices[n].cogerL() < 0) && (vertices[(n + 1) % 4].cogerL() > 0)) ||
((vertices[n].cogerL() > 0) && (vertices[(n + 1) % 4].cogerL() < 0))) {
if ((vertices[n].cogerL() < 0) && (vertices[(n + 1) % 4].cogerL() > 0)) {
aux1 = Figura::punto3Da2D(vertices[n], v, win); // A' no es virtual
aux2 = Figura::punto3Da2D(vertices[(n + 1) % 4], v, win); // B' es virtual
aux2 = Figura::solucionarVisibilidad(aux2, aux1); // B''
aux2D = Arista2D(&aux1, &aux2);
Cpintar.addArista2D(&aux2D);
}
else {
aux1 = Figura::punto3Da2D(vertices[n], v, win); // A' es virtual
aux2 = Figura::punto3Da2D(vertices[(n + 1) % 4], v, win); // B' no es virtual
aux1 = Figura::solucionarVisibilidad(aux1, aux2); // A''
aux2D = Arista2D(&aux1, &aux2);
Cpintar.addArista2D(&aux2D);
}
}
}
if (pintar) {
glColor3f(RGBcaras[0], RGBcaras[1], RGBcaras[2]);
if (Cpintar.cogerCont2() == Cpintar.cogerNumAristas()) {
Figura::calcularOrdenadas(&Cpintar);
Figura::pintarCara(&Cpintar, win, v);
}
}
glColor3f(RGBaristas[0], RGBaristas[1], RGBaristas[2]);
for(int i = 0; i < Cpintar.cogerCont2(); i++) {
if (Figura::pintarSegmentos(&(Cpintar.listarAristas() + i)->cogerP1(), &(Cpintar.listarAristas() + i)->cogerP2(), win))
Figura::drawLine(int((Cpintar.listarAristas() + i)->cogerP1().cogerX()), int((Cpintar.listarAristas() + i)->cogerP1().cogerY()), int((Cpintar.listarAristas() + i)->cogerP2().cogerX()), int((Cpintar.listarAristas() + i)->cogerP2().cogerY()));
}
Cpintar.erase();
}
void Xcuadrado::modRGBaristas(float r, float g, float b) {
RGBaristas[0] = r;
RGBaristas[1] = g;
RGBaristas[2] = b;
}
void Xcuadrado::modRGBcaras(float r, float g, float b) {
RGBcaras[0] = r;
RGBcaras[1] = g;
RGBcaras[2] = b;
}