-
Notifications
You must be signed in to change notification settings - Fork 3
/
EntityGrabber.angelscript
51 lines (45 loc) · 1.2 KB
/
EntityGrabber.angelscript
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
funcdef bool GRAB_VALIDATE(ETHEntity@ entity);
class EntityGrabber
{
private ETHEntityArray m_entities;
EntityGrabber(const vector2 &in point, const float radius, GRAB_VALIDATE@ validate)
{
ETHEntityArray ents;
getEntitiesFromNeighbourBuckets(GetBucket(point), 1, ents);
for (uint t = 0; t < ents.size(); t++)
{
if (!validate(@ents[t]))
continue;
ETHPhysicsController@ sim = ents[t].GetPhysicsController();
if (sim is null)
continue;
if (sim.GetShape() == BS_CIRCLE)
{
const float radiusSum = (ents[t].GetCollisionBox().size.x * g_scale.scale(0.5f)) + radius;
if (squaredDistance(ents[t].GetPositionXY(), point) < radiusSum * radiusSum)
{
ETHEntity@ temp = ents[t];
m_entities.push_back(temp);
}
}
else
{
const vector3 collisionSize = ents[t].GetCollisionBox().size * g_scale.getScale();
Shape shape(ents[t].GetPositionXY(), vector2(collisionSize.x, collisionSize.y), ents[t].GetAngle(), true);
if (shape.overlapSphere(point, radius))
{
ETHEntity@ temp = ents[t];
m_entities.push_back(temp);
}
}
}
}
uint size() const
{
return m_entities.size();
}
ETHEntity@ get(const uint t)
{
return m_entities[t];
}
}