-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMob.cpp
71 lines (61 loc) · 1.11 KB
/
Mob.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
/* The mob is a base class for essentially any object that will exist within the cylinder.
* The class itself is pretty simple. Explanation of the variables is in the header.
*/
using namespace std;
#include "Mob.h"
void Mob::saveMatrix()
{
glGetFloatv(GL_MODELVIEW_MATRIX, trans);
glPopMatrix();
}
void Mob::loadMatrix()
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadMatrixf(trans);
}
Mob::Mob()
{
init();
}
Mob::Mob(GLfloat np, GLfloat naz, GLfloat nh)
{
pos.p = np;
pos.az = naz;
pos.h = nh;
init();
}
Mob::Mob(CylVector p)
{
pos.p = p.p;
pos.az = p.az;
pos.h = p.h;
init();
}
bool Mob::init()
{
texture = 0;
nodel = false;
delnow = false;
nodraw = false;
return false;
}
void Mob::rotate(GLfloat angle, GLfloat dx, GLfloat dy, GLfloat dz)
{
loadMatrix();
glRotatef(angle, dx, dy, dz);
saveMatrix();
}
void Mob::translate(GLfloat dp, GLfloat daz, GLfloat dh)
{
pos.p += dp;
pos.az = fmodf(pos.az + daz, M_PI*2);
pos.h += dh;
pos.print();
}
void Mob::update(float dt)
{
loadMatrix();
translate(dt*velocity.x, dt*velocity.y, dt*velocity.z);
saveMatrix();
}