-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvelocityvector.cpp
More file actions
32 lines (25 loc) · 849 Bytes
/
Copy pathvelocityvector.cpp
File metadata and controls
32 lines (25 loc) · 849 Bytes
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
#include "velocityvector.hpp"
#include <complex>
VelocityVector::VelocityVector(Ship* shipref): ship(shipref)
{
shape.setSize(Vector2f(2,100));
shape.setFillColor(Color::Red);
}
void VelocityVector::applyGravity(){}
void VelocityVector::update()
{
shape.setPosition(ship->getPosition());
// set position in the middle of the ship
Vector2f velocity = ship->getVelocity();
std::complex<float> cvelo{velocity.x, velocity.y};
// set new length and angle.
// length is scaled a bit for better visibility.
// the angle has to be converted to degrees and then transformed
// to match the axis orientation of the Shape rotation system.
shape.setSize(Vector2f(2, abs(cvelo) * 10));
shape.setRotation(arg(cvelo) * 180.0f / M_PI - 90.0f);
}
RectangleShape VelocityVector::getShape()
{
return shape;
}