-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSGlobalScale.angelscript
More file actions
97 lines (84 loc) · 2.01 KB
/
Copy pathSGlobalScale.angelscript
File metadata and controls
97 lines (84 loc) · 2.01 KB
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
class SGlobalScale
{
private float m_scaleFactor;
private float m_absoluteSize;
SGlobalScale(const float _absoluteSize)
{
m_absoluteSize = _absoluteSize;
updateScaleFactor(DEFAULT_SCALE_HEIGHT);
}
/// Checks the current screen dimension to keep scale up-to-date.
/// Avoids "fake screen sizes" like the one in Android 3.x
void updateScaleFactor(const float _absoluteSize)
{
m_absoluteSize = _absoluteSize;
m_scaleFactor = GetScreenSize().y / m_absoluteSize;
}
float getAbsoluteSize()
{
return m_absoluteSize;
}
float getScale()
{
return m_scaleFactor;
}
float scale(const float v)
{
return m_scaleFactor * v;
}
vector2 scale(const vector2 v)
{
return m_scaleFactor * v;
}
vector3 scale(const vector3 v)
{
return m_scaleFactor * v;
}
void scaleEntity(ETHEntity@ entity)
{
float individualScale = 1.0f;
if (entity.CheckCustomData("scale") != DT_NODATA)
{
individualScale = entity.GetFloat("scale");
}
entity.Scale(getScale() * individualScale);
entity.SetPosition(entity.GetPosition() * getScale());
// multiplyCustomData(entity, "speed");
}
collisionBox getAbsoluteCollisionBox(ETHEntity@ entity)
{
collisionBox box = entity.GetCollisionBox();
box.pos *= getScale();
box.size *= getScale();
if (entity.GetAngle() != 0.0f)
{
matrix4x4 m = rotateZ(degreeToRadian(entity.GetAngle()));
box.pos = multiply(box.pos, m);
}
box.pos += entity.GetPosition();
return box;
}
void multiplyCustomData(ETHEntity@ entity, const string name)
{
if (entity.CheckCustomData(name) == DT_FLOAT)
entity.MultiplyFloat(name, getScale());
}
void scaleEntities()
{
ETHEntityArray entities;
GetAllEntitiesInScene(entities);
for (uint t=0; t<entities.size(); t++)
{
if (entities[t].CheckCustomData("scalable") == DT_NODATA || entities[t].GetUInt("scalable") != 0)
{
scaleEntity(entities[t]);
}
if (entities[t].CheckCustomData("hidden") != DT_NODATA)
{
entities[t].Hide(true);
}
}
ResolveJoints();
}
}
SGlobalScale g_scale(480);