-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.hpp
77 lines (64 loc) · 1.14 KB
/
Utils.hpp
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
#ifndef _UTILS_HPP
#define _UTILS_HPP
#include <sifteo/math.h>
static Side oppositeSide(Side s)
{
switch(s)
{
case TOP: return BOTTOM;
case RIGHT: return LEFT;
case BOTTOM: return TOP;
case LEFT: return RIGHT;
default: return TOP;
}
}
static Float2 sideDirection(Side s)
{
Float2 d;
switch(s)
{
case TOP: d.set(0, -1); break;
case RIGHT: d.set(1, 0); break;
case BOTTOM: d.set(0, 1); break;
case LEFT: d.set(-1, 0); break;
default: break;
}
return d;
}
static Float2 getSidePos(Side s)
{
Float2 p;
p.set(64, 64);
p += sideDirection(s)*64;
return p;
}
static Float2 rot90CCW(Float2 d)
{
Float2 r;
r.set( -d.y, d.x );
return r;
}
static Float2 rot90CW(Float2 d)
{
Float2 r;
r.set( d.y, -d.x );
return r;
}
static Float2 toSpritePos( Float2 p, const AssetImage& img, bool doClamp = false )
{
p.x -= img.pixelWidth()/2.0;
p.y -= img.pixelHeight()/2.0;
if( doClamp )
{
p.x = clamp( p.x, 0.0f, 128.0f-img.pixelWidth() );
p.y = clamp( p.y, 0.0f, 128.0f-img.pixelHeight() );
}
return p;
}
static Float2 clampPos( Float2 p )
{
p.x = clamp(p.x, 0.0f, 128.0f);
p.y = clamp(p.y, 0.0f, 128.0f);
return p;
}
#endif