1. Point Entity::MTV(Entity other)
2. {
3. // GETTING ORIENTED BOUNDING SHAPE:
4. vector<Point> shape1 = this->getOrientedShape();
5. vector<Point> shape2 = other.getOrientedShape();
6.
7. // GETTING NUMBER OF FACES FOR EACH ENTITY:
8. int total1 = shape1.size();
9. int total2 = shape2.size();
10.
11. // INITIALIZING OVERLAP VARIABLE:
12. float overlap = FLT_MAX;
13. Point smallest = Point(0, 0);
14.
15. // FOR EACH FACE RELATIVE TO THIS ENTITY:
16. for(int i = 0; i < total1; i++)
17. {
18. // GET CURRENT FACE:
19. Point face(shape1[i].x - shape1[(i + 1) % total1].x, shape1[i].y - shape1[(i + 1) % total1].y);
20.
21. // GET CURRENT AXIS PERPENDICULAR TO THE CURRENT FACE:
22. Point axis(-face.y, face.x);
23.
24. // NORMALIZE THE AXIS:
25. axis /= sqrt(axis.x * axis.x + axis.y * axis.y);
26.
27. // GET MAXIMUM AND MINIMUM POSSIBLE VALUES OF A FLOAT:
28. Point overlap1(FLT_MAX, -FLT_MAX);
29. Point overlap2(FLT_MAX, -FLT_MAX);
30.
31. // GET THE MAXIMUM AND MINIMUM VALUES OF THIS ENTITY RELATIVE TO THE AXIS:
32. for(int j = 0; j < total1; j++)
33. {
34. float proj1 = ((axis.x * shape1[j].x) + (axis.y * shape1[j].y)) / ((axis.x * axis.x) + (axis.y * axis.y));
35. overlap1.x = min(proj1, overlap1.x);
36. overlap1.y = max(proj1, overlap1.y);
37. }
38.
39. // GET THE MAXIMUM AND MINIMUM VALUES OF THE OTHER ENTITY RELATIVE TO THE AXIS:
40. for(int j = 0; j < total2; j++)
41. {
42. float proj2 = ((axis.x * shape2[j].x) + (axis.y * shape2[j].y)) / ((axis.x * axis.x) + (axis.y * axis.y));
43. overlap2.x = min(proj2, overlap2.x);
44. overlap2.y = max(proj2, overlap2.y);
45. }
46.
47. // EXIT IF THE PROJECTIONS DO NOT OVERLAP:
48. if(overlap1.x > overlap2.y || overlap1.y < overlap2.x)
49. {
50. overlap = 0;
51. return smallest * overlap;
52. }
53.
54. // FIND THE SMALLEST OVERLAP:
55. smallest = axis;
56. if(overlap1.y > overlap2.x)
57. {
58. overlap = min(overlap, overlap1.y - overlap2.x);
59. } else if(overlap1.x > overlap2.y) {
60. overlap = min(overlap, overlap1.x - overlap2.y);
61. }
62. }
63.
64. // IF ON ALL AXIS AN OVERLAP OCCURS THEN THE ENTITIES ARE INTERSECTING:
65. return smallest * overlap;
66. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: ‘Point’ does not name a type
stdout
Standard output is empty