-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent.cpp
66 lines (58 loc) · 1.7 KB
/
current.cpp
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
#include "current.h"
Current::Current(double x1,double y1,double x2,double y2,double r,bool f):x1{x1},x2{x2},y1{y1},y2{y2},entranceRadius{r},forcedToTransfer{f}
{
}
cVector3d Current::getForceFeedback(double x, double y){
double dist1 = sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
double dist2 = sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
if(dist1 <= entranceRadius){
inArea1 = true;
}else if(dist2 <= entranceRadius){
inArea2 = true;
}else{
inArea1 = false;
inArea2 = false;
}
}
void Current::transferTriggered(double x,double y){
triggered = true;
transferFinished = false;
transferStartx = inArea1?x1:x2;
transferStarty = inArea1?y1:y2;
}
cVector3d Current::updatePosition(double x, double y){
double dist1 = sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
double dist2 = sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
if(inArea1){
if(dist2<(entranceRadius/2)){
transferFinished = true;
inArea1 = false;
inArea2 = true;
}
}
else if(inArea2){
if(dist1<(entranceRadius/2)){
transferFinished = true;
inArea1 = true;
inArea2 = false;
}
}
else std::cout<<"ERROR! - in current update position";
}
cVector3d Current::getSpeed(){
cVector3d speed(0.0,0.0,0.0);
double totalspeed = 5;
double deltax = 0.0;
double deltay = 0.0;
if(inArea1){
deltax = x2-transferStartx;
deltay = y2-transferStarty;
}else{
deltax = x1-transferStartx;
deltay = y1-transferStarty;
}
double longest = sqrt(deltax*deltax+deltay*deltay);
speed(0) = totalspeed*deltax/longest;
speed(1) = totalspeed*deltay/longest;
return speed;
}