-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharm.cpp
More file actions
55 lines (39 loc) · 1.2 KB
/
Copy patharm.cpp
File metadata and controls
55 lines (39 loc) · 1.2 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
#include "arm.hpp"
#include <cmath>
Arm::Arm() : Arm(sf::Vector2f(0.0f,0.0f),100.0f , 0.2f) {
}
Arm::Arm(float length, float speed) : Arm(sf::Vector2f(0.0f,0.0f),length , speed) {
}
Arm::Arm(sf::Vector2f position, float length, float speed) {
mThickness = ARM_WIDTH;
mLength = length;
mSpeed = speed;
mLine.setSize(sf::Vector2f(length,mThickness));
mLine.setOrigin(0,mThickness/2);
mLine.setPosition(position);
mLine.setFillColor(sf::Color::White);
}
void Arm::rotate(float angle) {
mLine.rotate(angle);
}
void Arm::attachTo(Arm &lastArm){
const float radian_angle = (lastArm.getRotation()) * (M_PI/180.0f);
float posX = lastArm.getPosition().x + lastArm.mLength * std::cos(radian_angle);
float posY = lastArm.getPosition().y + lastArm.mLength * std::sin(radian_angle);
mLine.setPosition(sf::Vector2f(posX, posY));
}
void Arm::setPosition(sf::Vector2f position) {
mLine.setPosition(position);
}
void Arm::draw(sf::RenderWindow &window) const{
window.draw(mLine);
}
float Arm::getRotation() const{
return mLine.getRotation();
}
sf::Vector2f Arm::getPosition() const{
return mLine.getPosition();
}
float Arm::getSpeed() const{
return mSpeed;
}