-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovingObject.cpp
More file actions
42 lines (34 loc) · 1.12 KB
/
MovingObject.cpp
File metadata and controls
42 lines (34 loc) · 1.12 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
#include <simplecpp>
#include "MovingObject.h"
using namespace simplecpp;
void MovingObject::nextStep(double t) {
if(paused) { return; }
for(size_t i=0; i<parts.size(); i++){
parts[i]->move(vx*t, vy*t);
}
vx += ax*t;
vy += ay*t;
} // End MovingObject::nextStep()
double MovingObject::getXPos() {
return (parts.size() > 0) ? parts[0]->getX() : -1;
}
double MovingObject::getYPos() {
return (parts.size() > 0) ? parts[0]->getY() : -1;
}
void MovingObject::reset_all(double argx, double argy, double speed, double angle_deg, double argax, double argay, bool argpaused, bool rtheta) {
for(size_t i=0; i<parts.size(); i++){
parts[i]->moveTo(argx, argy);
}
double angle_rad = angle_deg*PI/180.0;
double argvx = speed*cos(angle_rad);
double argvy = -speed*sin(angle_rad);
vx = argvx; vy = argvy; ax = argax; ay = argay; paused = argpaused;
} // End MovingObject::reset_all()
void MovingObject::getAttachedTo(MovingObject *m) {
double xpos = m->getXPos();
double ypos = m->getYPos();
for(size_t i=0; i<parts.size(); i++){
parts[i]->moveTo(xpos, ypos);
}
initMO(m->vx, m->vy, m->ax, m->ay, m->paused);
}