-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcannon.cpp
72 lines (54 loc) · 1.47 KB
/
cannon.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
/*
* File: cannon.cpp
* Author: 2019202344
*
* Created on 6 de Dezembro de 2019, 19:54
*/
#include "cannon.h"
#include "cube.h"
wf_object_t* cannon_t::sModel = NULL;
cannon_t::cannon_t(const vector3f& offset) :
offset(offset) {
}
void cannon_t::init(wf_object_loader_t& loader) {
sModel = loader.loadRes("canhao");
sModel->scale(1 / loader.getMostDistantVertex().length());
}
void cannon_t::draw() {
glPushMatrix();
{
glTranslatef(offset.x, offset.y, offset.z);
glRotatef(horizontal, 0, 0, 1);
glRotatef(-vertical, 0, 1, 0);
float length = getLength();
glScaled(length, length, length);
// glScaled(10, 10, 10);
glRotatef(-90, 0, 0, 1);
drawAxis(1);
if (sModel == NULL) {
// glScaled(getLength() / 2, 1, 1);
// glTranslatef(1, 0, 0);
drawCube();
} else {
sModel->draw();
}
}
glPopMatrix();
}
void cannon_t::setInputAxis(float x, float y) {
const float maxAngle = 30;
horizontal = -(x * 2 * maxAngle - maxAngle);
vertical = -(y * 2 * maxAngle - maxAngle);
}
vector3f cannon_t::getDirection() const {
return getDirection(0, 0);
}
vector3f cannon_t::getDirection(float h, float v) const {
float r;
float z;
const float dr = M_PI / 180.0f;
sincosf(vertical * dr + v, &z, &r);
float x, y;
sincosf(horizontal * dr + h, &y, &x);
return vector3f(r * x, r * y, z);
}