Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip origin enclosed checks if origin had been enclosed before
Browse files Browse the repository at this point in the history
notgiven688 committed Apr 1, 2024
1 parent c5f8900 commit 54435dc
Showing 3 changed files with 35 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/Drawables/Showcase.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/* Copyright <2021> <Thorben Linneweber>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
using System;
using System.Reflection;
@@ -160,8 +160,8 @@ public void Detect()
}

// crude way of saving distances to file
// if(success) System.IO.File.AppendAllText("data.txt", separation.ToString() + "\n");
// else System.IO.File.AppendAllText("data.txt", 0.ToString() + "\n");
if(success) System.IO.File.AppendAllText("data.txt", separation.ToString() + "\n");
else System.IO.File.AppendAllText("data.txt", 0.ToString() + "\n");
}

private void HandleInput(FrameEventArgs e)
@@ -173,7 +173,7 @@ bool IsSwitched(Keys key) =>

if (KeyState.IsKeyDown(Keys.K)) distance -= 0.03f * timescale;
if (KeyState.IsKeyDown(Keys.L)) distance += 0.03f * timescale;

if (IsSwitched(Keys.R)) autorotate = !autorotate;
if (IsSwitched(Keys.T)) advancerotation = true;
if (IsSwitched(Keys.N)) NextRandomShapes();
7 changes: 6 additions & 1 deletion src/GJKEPA.cs
Original file line number Diff line number Diff line change
@@ -310,6 +310,11 @@ public bool Solve(out JVector point1, out JVector point2, out JVector normal, ou
// search for the closest triangle and check if the origin is enclosed
int closestIndex = -1;
double currentMin = double.MaxValue;

// We can skip the test for enclosed origin if the origin was
// already enclosed once.
bool skipTest = originEnclosed;

originEnclosed = true;

for (int i = 0; i < tCount; i++)
@@ -320,7 +325,7 @@ public bool Solve(out JVector point1, out JVector point2, out JVector normal, ou
closestIndex = i;
}

if(!Triangles[i].FacingOrigin) originEnclosed = false;
if(!Triangles[i].FacingOrigin) originEnclosed = skipTest;
}

ctri = Triangles[closestIndex];
26 changes: 22 additions & 4 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/* Copyright <2021> <Thorben Linneweber>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
using System;

@@ -92,6 +92,24 @@ static void Main()
return;
#endif

JVector a = new(-94.250046d, 0.123543d, - 90.249962d);
JVector b = new(106.249962d, 0.123360d, 110.250031d);
JVector c = new JVector(105.749954d, 0.123543d, 109.750038d);
JVector center = new(5.999900d, -100.126549d, 10.000000d);

JVector.Subtract(a, b, out JVector u);
JVector.Subtract(a, c, out JVector v);

float uX = (float)a.X - (float)b.X;
float uY = (float)a.Y - (float)b.Y;
float uZ = (float)a.Z - (float)b.Z;

JVector.Cross(u, v, out JVector normal);

double delta = JVector.Dot(normal, a - center);

double delta2 = JVector.Dot(normal, a);


GameWindowSettings gws = GameWindowSettings.Default;
NativeWindowSettings nws = NativeWindowSettings.Default;

0 comments on commit 54435dc

Please sign in to comment.