forked from rcatolino/bubbles-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actor.cpp
140 lines (123 loc) · 2.59 KB
/
actor.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
136
137
138
139
140
#include "actor.h"
#include <QtCore/qmath.h>
Actor::Actor()
{
}
Actor::Actor(QString id, float x, float y, float z,
float vx, float vy, float vz)
{
this->id = id;
this->x = x;
this->y = y;
this->z = z;
this->vx = vx;
this->vy = vy;
this->vz = vz;
}
Actor::Actor(QVariantMap map)
{
//Safegard 'cause default value changes ...
x = y = z = vx = vy = vz = cube = 0;
width = height = length = 0.0;
id = map["id"].toString();
x = map["x"].toInt();
y = map["y"].toInt();
z = map["z"].toInt();
vx = map["vx"].toInt();
vy = map["vy"].toInt();
vz = map["vz"].toInt();
width = map["w"].toFloat();
height = map["h"].toFloat();
length = map["l"].toFloat();
cube = map["cube"].toInt();
}
/*
vector Actor::getPos()
{
return vector(x,y,z);
}
vector Actor::getSight()
{
return vector(vx,vy,vz);
}
*/
float Actor::getDistance(const Actor * self)
{
float sx = self->getX();
float sy = self->getY();
float sz = self->getZ();
return sqrt((x-sx)*(x-sx)+(y-sy)*(y-sy)+(z-sz)*(z-sz));
}
QString Actor::toString()
{
QString str = "name : " + id + " x:" + x + " y:" + y + " z:" + z;
return str;
}
QString Actor::getId() const{
return id;
}
float Actor::getX() const{
return x;
}
float Actor::getY() const{
return y;
}
float Actor::getZ() const{
return z;
}
float Actor::getVx() const{
return vx;
}
float Actor::getVy() const{
return vy;
}
float Actor::getVz() const{
return vz;
}
float Actor::getWidth() const{
return width;
}
float Actor::getLength() const{
return length;
}
float Actor::getHeight() const{
return height;
}
bool Actor::operator ==(const Actor& a) const{
return (id == a.id);
}
int Actor::getCube()
{
return cube;
}
void Actor::update(QVariantMap map)
{
//Position
if (map.contains("x"))
x = map["x"].toInt();
if (map.contains("y"))
y = map["y"].toInt();
if (map.contains("z"))
z = map["z"].toInt();
//Color
if (map.contains("r"))
r = map["r"].toInt();
if (map.contains("g"))
g = map["g"].toInt();
if (map.contains("b"))
b = map["b"].toInt();
if (map.contains("vx"))
vx = map["vx"].toFloat();
if (map.contains("vy"))
vy = map["vy"].toFloat();
if (map.contains("vz"))
vz = map["vz"].toFloat();
if (map.contains("w"))
width = map["w"].toFloat();
if (map.contains("h"))
height = map["h"].toFloat();
if (map.contains("l"))
length = map["l"].toFloat();
if (map.contains("cube"))
cube = map["cube"].toInt();
}