-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSector.cpp
More file actions
71 lines (49 loc) · 2.15 KB
/
Sector.cpp
File metadata and controls
71 lines (49 loc) · 2.15 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
#include "Sector.h"
#include <Math.h>
#define PI (3.141592653589793)
Sector::Sector(int x, int y, int radius, int piece)
{
Pie = Circular_arc(x, y, (radius / 20)*9, (radius / 20), -9 + (piece * 18), 9 + (piece * 18));
Treble = Circular_arc(x, y, (radius / 20)*10, (radius / 20)*9, -9 + (piece * 18), 9 + (piece * 18));
Fat = Circular_arc(x, y, (radius / 20)*19, (radius / 20)*10, -9 + (piece * 18), 9 + (piece * 18));
Double = Circular_arc(x, y, (radius / 20)*20, (radius / 20)*19, -9 + (piece * 18), 9 + (piece * 18));
}
sf::ConvexShape Sector::Circular_arc(double x, double y, double endRadius, double startRadius, double startAngle, double endAngle)
{
sf::ConvexShape convex;
convex.setPointCount(40);
// Lower left
double currentX{ x + startRadius * sin(startAngle * PI / 180) };
double currentY{ y - startRadius * cos(startAngle * PI / 180) };
convex.setPoint(0, sf::Vector2f(currentX, currentY));
// Upper left
currentX = x + endRadius * sin(startAngle * PI / 180);
currentY = y - endRadius * cos(startAngle * PI / 180);
convex.setPoint(1, sf::Vector2f(currentX, currentY));
int pointsOnArc{ 18 };
double DegreeInRad{ 0.0174532925 };
// Upper Accross
for (int i{ 0 }; i < pointsOnArc; ++i)
{
// TODO: Sort formula out properly
currentX = cos(DegreeInRad) * (currentX - x) - sin(DegreeInRad) * (currentY - y) + x;
currentY = sin(DegreeInRad) * (currentX - x) + cos(DegreeInRad) * (currentY - y) + y;
convex.setPoint(i + 2, sf::Vector2f(currentX, currentY));
}
// Upper right
currentX = x + endRadius * sin(endAngle * PI / 180);
currentY = y - endRadius * cos(endAngle * PI / 180);
convex.setPoint(20, sf::Vector2f(currentX, currentY));
// Lower right
currentX = x + startRadius * sin(endAngle * PI / 180);
currentY = y - startRadius * cos(endAngle * PI / 180);
convex.setPoint(21, sf::Vector2f(currentX, currentY));
// Lower across
for (int i{ 0 }; i < pointsOnArc; ++i)
{
currentX = cos(-DegreeInRad) * (currentX - x) - sin(-DegreeInRad) * (currentY - y) + x;
currentY = sin(-DegreeInRad) * (currentX - x) + cos(-DegreeInRad) * (currentY - y) + y;
convex.setPoint(i + 22, sf::Vector2f(currentX, currentY));
}
return convex;
}