This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
/
Tiro.cpp
135 lines (111 loc) · 3.21 KB
/
Tiro.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "Tiro.h"
Tiro::Tiro() {
transformacao = new Transformacao();
this->velocidadeTiro = 0.0;
this->tiro = new Circle();
this->fatorEscala = 0.0;
this->fatorEscalaInverso = 0.0;
this->cx = 0.0;
this->cy = 0.0;
this->cz = 0.0;
this->raio = 0.0;
this->anguloGiro = 0.0;
this->anguloMira = 0.0;
this->posX = 0.0;
this->posY = 0.0;
this->anguloGiro = 0.0;
}
Tiro::Tiro(float fatorEscala, float fatorEscalaInverso, float cx, float cy,float cz,
float raio, float anguloGiro, float anguloMira, float miraHeight,
float posX, float posY) {
transformacao = new Transformacao(fatorEscala, cx, cy, raio, anguloGiro,
anguloMira, miraHeight, posX, posY);
this->velocidadeTiro = 0.0;
this->tiro = new Circle();
this->fatorEscala = fatorEscala;
this->fatorEscalaInverso = fatorEscalaInverso;
this->cx = cx;
this->cy = cy;
this->cz = cz;
this->raio = raio;
this->anguloGiro = anguloGiro;
this->anguloMira = anguloMira;
this->posX = posX;
this->posY = posY;
this->miraHeight = miraHeight;
}
Tiro::~Tiro() {
}
void Tiro::carregarInformacoes() {
XMLDocument* doc = new XMLDocument();
doc->LoadFile("tiro.svg");
if (doc == NULL) {
cout << "Problema ao abrir arquivo .svg\n";
exit(1);
}
XMLElement* svg = doc->FirstChildElement("svg");
if (svg == NULL) {
cout
<< "Erro na hora de encontrar Element 'svg'! Finalizando programa...\n";
exit(1);
}
XMLElement* circleElem = svg->FirstChildElement("circle");
if (circleElem == NULL) {
cout
<< "Erro na hora de encontrar Element 'circle'! Finalizando programa...\n";
exit(1);
}
this->tiro->setValues(circleElem);
}
void Tiro::desenharTiro(bool vision3d, float altura) {
if (this->transformacao != NULL) {
this->transformacao->definirTransformacao(fatorEscala, this->cx,
this->cy, this->cz, this->raio, this->anguloGiro, this->anguloMira,
this->miraHeight, this->posX, this->posY);
this->transformacao->iniciarTransformacao(true, false);
}
float zTranslated = 1000;
glTranslatef(0, 0, zTranslated);
if (vision3d) {
glPushMatrix();
glutSolidSphere(this->tiro->getR(), 50, 50);
glPopMatrix();
} else {
this->tiro->desenharCircle(0.0, 0.0, 0.0);
}
this->transformacao->fecharTransformacao();
}
bool Tiro::verificarLimites(float limiteSuperior, float limiteInferior,
float limiteEsquerdo, float limiteDireito) {
if (this->posX > limiteDireito || this->posX < limiteEsquerdo
|| this->posY < limiteSuperior || this->posY > limiteInferior) {
return false;
} else
return true;
}
void Tiro::movimentarParaFrente() {
this->posX = this->posX
+ this->velocidadeTiro
* cos(
(270 + this->anguloGiro) * M_PI / 180
+ (this->anguloMira) * M_PI / 180);
this->posY += this->velocidadeTiro
* sin(
(270 + this->anguloGiro) * M_PI / 180
+ (this->anguloMira) * M_PI / 180);
}
void Tiro::movimentarParaTras() {
this->posX -= this->velocidadeTiro
* cos(
(270 + this->anguloGiro) * M_PI / 180
+ (this->anguloMira) * M_PI / 180);
this->posY -= this->velocidadeTiro
* sin(
(270 + this->anguloGiro) * M_PI / 180
+ (this->anguloMira) * M_PI / 180);
}
void Tiro::showValues() {
cout << "Tiro\n";
this->tiro->showValues();
cout << "Velocidade Tiro: " << this->velocidadeTiro << "\n";
}