-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPVector.cpp
More file actions
78 lines (66 loc) · 1.49 KB
/
PVector.cpp
File metadata and controls
78 lines (66 loc) · 1.49 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
#include "PVector.h"
#include <math.h>
PVector::PVector(float posx, float posy){
sizex = posx;
sizey = posy;
auxx = posx;
auxy = posy;
x = 0;
y = 0;
}
PVector::~PVector(void)
{
}
float PVector::getX() { return x; }
float PVector::getY() { return y; }
float PVector::getSizeX() { return sizex; }
float PVector::getSizeY() { return sizey; }
float PVector::getAuxx() { return auxx; }
float PVector::getAuxy() { return auxy; }
float PVector::getAngle(float vx, float vy){
// cross product
double ny = (sizex * vy) - (vx * sizey);
// dot product
double nx = (sizex * vx) + (sizey * vy);
return atan2(ny, nx);
}
void PVector::addSum(float tx, float ty){
x += tx;
y += ty;
}
void PVector::addSum2(float tx, float ty){
sizex+= tx;
sizey+= ty;
}
void PVector::setXY(float nx, float ny){
x = nx;
y = ny;
}
void PVector::setSizeY(float ny){
sizey = ny;
}
void PVector::setSizeX(float nx){
sizex = nx;
}
void PVector::setSizeXY(float nx, float ny){
sizex = nx;
sizey = ny;
auxx = nx;
auxy = ny;
}
float PVector::getNorma(){
return sqrt((sizex * sizex) + (sizey * sizey));
}
float PVector::getUnitarioX(){
return sizex / getNorma();
}
float PVector::getUnitarioY(){
return sizey / getNorma();
}
void PVector::rotate(float angle){
//angle = angle * (3.14159265358979/180);
float newx = sizex * cos(angle) - sizey * sin(angle);
float newy = sizex * sin(angle) + sizey * cos(angle);
sizex = newx;
sizey = newy;
}