summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.codelite/.tern-port2
-rw-r--r--.codelite/PSP.session6
-rw-r--r--.codelite/PSP.tagsbin80476160 -> 80476160 bytes
-rw-r--r--.codelite/compilation.dbbin24576 -> 24576 bytes
-rw-r--r--.codelite/refactoring.dbbin505856 -> 520192 bytes
-rw-r--r--Project/Bus.cpp75
-rw-r--r--Project/Project.mk2
-rw-r--r--Project/Release/Bus.cpp.obin27137 -> 28409 bytes
-rw-r--r--Project/Release/PSP-UFU.exebin3286539 -> 3287771 bytes
9 files changed, 68 insertions, 17 deletions
diff --git a/.codelite/.tern-port b/.codelite/.tern-port
index 357baad..8fe3316 100644
--- a/.codelite/.tern-port
+++ b/.codelite/.tern-port
@@ -1 +1 @@
-54323 \ No newline at end of file
+55053 \ No newline at end of file
diff --git a/.codelite/PSP.session b/.codelite/PSP.session
index 34afdab..b3371e9 100644
--- a/.codelite/PSP.session
+++ b/.codelite/PSP.session
@@ -5,7 +5,7 @@
<TabInfoArray Name="TabInfoArray">
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Workspace.cpp" Name="FileName"/>
- <int Value="513" Name="FirstVisibleLine"/>
+ <int Value="493" Name="FirstVisibleLine"/>
<int Value="494" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
@@ -19,8 +19,8 @@
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Bus.cpp" Name="FileName"/>
- <int Value="60" Name="FirstVisibleLine"/>
- <int Value="87" Name="CurrentLine"/>
+ <int Value="72" Name="FirstVisibleLine"/>
+ <int Value="106" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags
index 2ee8699..e60cc61 100644
--- a/.codelite/PSP.tags
+++ b/.codelite/PSP.tags
Binary files differ
diff --git a/.codelite/compilation.db b/.codelite/compilation.db
index 7d1ba60..0b0e4e5 100644
--- a/.codelite/compilation.db
+++ b/.codelite/compilation.db
Binary files differ
diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db
index 8999262..e55b6d9 100644
--- a/.codelite/refactoring.db
+++ b/.codelite/refactoring.db
Binary files differ
diff --git a/Project/Bus.cpp b/Project/Bus.cpp
index 96bff55..847308d 100644
--- a/Project/Bus.cpp
+++ b/Project/Bus.cpp
@@ -76,23 +76,74 @@ bool Bus::Contains(wxPoint2DDouble position) const
bool Bus::Intersects(wxRect2DDouble rect) const
{
- wxPoint2DDouble m_rectCorners[2] = {m_rect.GetLeftTop(), m_rect.GetRightBottom()};
+ if(m_angle == 0.0 || m_angle == 180.0) return m_rect.Intersects(rect);
- wxPoint2DDouble rectCorners[2] = {rect.GetLeftTop(), rect.GetRightBottom()};
+ wxPoint2DDouble m_rectCorners[4] = {m_rect.GetLeftTop(), m_rect.GetLeftBottom(), m_rect.GetRightBottom(),
+ m_rect.GetRightTop()};
+ wxPoint2DDouble rectCorners[4] = {rect.GetLeftTop(), rect.GetLeftBottom(), rect.GetRightBottom(),
+ rect.GetRightTop()};
- // Rotate the rect corners
- for(int i = 0; i < 2; i++) {
- rectCorners[i] = RotateAtPosition(rectCorners[i], -m_angle);
+ // Rotate the m_rect corners
+ for(int i = 0; i < 4; i++) {
+ m_rectCorners[i] = RotateAtPosition(m_rectCorners[i], m_angle);
}
- //[Ref] http://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other
- //[Ref2] http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604
- // if (RectA.X1 < RectB.X2 && RectA.X2 > RectB.X1 && RectA.Y1 < RectB.Y2 && RectA.Y2 > RectB.Y1)
- if(m_rectCorners[0].m_x < rectCorners[1].m_x && m_rectCorners[1].m_x > rectCorners[0].m_x &&
- m_rectCorners[0].m_y < rectCorners[1].m_y && m_rectCorners[1].m_y > rectCorners[0].m_y)
- return true;
+ //[Ref] http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604
- return false;
+ // Find the rectangles axis to project
+ wxPoint2DDouble axis[4] = {m_rectCorners[3] - m_rectCorners[0], m_rectCorners[3] - m_rectCorners[2],
+ rectCorners[3] - rectCorners[0], rectCorners[3] - rectCorners[2]};
+
+ // Calculate the projected points to each axis
+ wxPoint2DDouble m_rectProjPts[4][4]; // [axis][corner]
+ wxPoint2DDouble rectProjPts[4][4]; // [axis][corner]
+ for(int i = 0; i < 4; i++) {
+ double den = axis[i].m_x * axis[i].m_x + axis[i].m_y * axis[i].m_y;
+ for(int j = 0; j < 4; j++) {
+ double m_rectProj = (m_rectCorners[j].m_x * axis[i].m_x + m_rectCorners[j].m_y * axis[i].m_y) / den;
+ double rectProj = (rectCorners[j].m_x * axis[i].m_x + rectCorners[j].m_y * axis[i].m_y) / den;
+
+ m_rectProjPts[i][j] = wxPoint2DDouble(m_rectProj * axis[i].m_x, m_rectProj * axis[i].m_y);
+ rectProjPts[i][j] = wxPoint2DDouble(rectProj * axis[i].m_x, rectProj * axis[i].m_y);
+ }
+ }
+
+ // Calculate the scalar value to identify the max and min values on projections
+ double m_rectScalar[4][4]; //[axis][corner]
+ double rectScalar[4][4]; //[axis][corner]
+ for(int i = 0; i < 4; i++) {
+ for(int j = 0; j < 4; j++) {
+ m_rectScalar[i][j] = m_rectProjPts[i][j].m_x * axis[i].m_x + m_rectProjPts[i][j].m_y * axis[i].m_y;
+ rectScalar[i][j] = rectProjPts[i][j].m_x * axis[i].m_x + rectProjPts[i][j].m_y * axis[i].m_y;
+ }
+ }
+ // Identify the max and min values
+ double m_rectMin[4];
+ double m_rectMax[4];
+ double rectMin[4];
+ double rectMax[4];
+
+ for(int i = 0; i < 4; i++) {
+ m_rectMax[i] = m_rectScalar[i][0];
+ rectMax[i] = rectScalar[i][0];
+ m_rectMin[i] = m_rectScalar[i][0];
+ rectMin[i] = rectScalar[i][0];
+
+ for(int j = 1; j < 4; j++) {
+ if(m_rectMax[i] < m_rectScalar[i][j]) m_rectMax[i] = m_rectScalar[i][j];
+ if(rectMax[i] < rectScalar[i][j]) rectMax[i] = rectScalar[i][j];
+
+ if(m_rectMin[i] > m_rectScalar[i][j]) m_rectMin[i] = m_rectScalar[i][j];
+ if(rectMin[i] > rectScalar[i][j]) rectMin[i] = rectScalar[i][j];
+ }
+ }
+
+ // Check if any segment don't overlap
+ for(int i = 0; i < 4; i++) {
+ if(!(rectMin[i] <= m_rectMax[i] && rectMax[i] >= m_rectMin[i])) return false;
+ }
+
+ return true;
// return rect.Intersects(m_rect);
}
bool Bus::PickboxContains(wxPoint2DDouble position)
diff --git a/Project/Project.mk b/Project/Project.mk
index 2a6d78f..7bc77fb 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Thales
-Date :=23/08/2016
+Date :=24/08/2016
CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC
diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o
index ca53709..0f40d0a 100644
--- a/Project/Release/Bus.cpp.o
+++ b/Project/Release/Bus.cpp.o
Binary files differ
diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe
index 9af8de7..64a92de 100644
--- a/Project/Release/PSP-UFU.exe
+++ b/Project/Release/PSP-UFU.exe
Binary files differ