-
Notifications
You must be signed in to change notification settings - Fork 0
/
QVector2D.pde
45 lines (37 loc) · 915 Bytes
/
QVector2D.pde
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
// PVector doesn’t have a rotate method, so I’m subclassing it
// and because I suck at math, I also make it two-dimensional only so
// I won’t have to implement rotation on a z-axis
class QVector2D extends PVector
{
QVector2D (float x, float y)
{
super(x, y, 0);
}
QVector2D ()
{
super();
}
QVector2D (QVector2D _vector)
{
super(_vector.x, _vector.y, 0);
}
void rotate (float _angle)
{
float angle = (float) Math.toRadians(_angle);
float xNew = cos(angle) * this.x - sin(angle) * this.y;
float yNew = cos(angle) * this.y + sin(angle) * this.x;
this.set(xNew, yNew, 0);
}
void set (float x, float y)
{
this.set(x, y, 0);
}
QVector2D get ()
{
return new QVector2D(this.x, this.y);
}
float angleBetween (QVector2D v)
{
return PVector.angleBetween(new PVector(this.x, this.y, 0), new PVector(v.x, v.y, 0));
}
}