summaryrefslogtreecommitdiff
path: root/libs/ode-0.16.1/OPCODE/Ice/IceSegment.cpp
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-10-01 20:59:36 -0500
committersanine <sanine.not@pm.me>2022-10-01 20:59:36 -0500
commitc5fc66ee58f2c60f2d226868bb1cf5b91badaf53 (patch)
tree277dd280daf10bf77013236b8edfa5f88708c7e0 /libs/ode-0.16.1/OPCODE/Ice/IceSegment.cpp
parent1cf9cc3408af7008451f9133fb95af66a9697d15 (diff)
add ode
Diffstat (limited to 'libs/ode-0.16.1/OPCODE/Ice/IceSegment.cpp')
-rw-r--r--libs/ode-0.16.1/OPCODE/Ice/IceSegment.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/libs/ode-0.16.1/OPCODE/Ice/IceSegment.cpp b/libs/ode-0.16.1/OPCODE/Ice/IceSegment.cpp
new file mode 100644
index 0000000..cd9ceb7
--- /dev/null
+++ b/libs/ode-0.16.1/OPCODE/Ice/IceSegment.cpp
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Contains code for segments.
+ * \file IceSegment.cpp
+ * \author Pierre Terdiman
+ * \date April, 4, 2000
+ */
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Segment class.
+ * A segment is defined by S(t) = mP0 * (1 - t) + mP1 * t, with 0 <= t <= 1
+ * Alternatively, a segment is S(t) = Origin + t * Direction for 0 <= t <= 1.
+ * Direction is not necessarily unit length. The end points are Origin = mP0 and Origin + Direction = mP1.
+ *
+ * \class Segment
+ * \author Pierre Terdiman
+ * \version 1.0
+ */
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Precompiled Header
+#include "Stdafx.h"
+
+using namespace IceMaths;
+
+float Segment::SquareDistance(const Point& point, float* t) const
+{
+ Point Diff = point - mP0;
+ Point Dir = mP1 - mP0;
+ float fT = Diff | Dir;
+
+ if(fT<=0.0f)
+ {
+ fT = 0.0f;
+ }
+ else
+ {
+ float SqrLen= Dir.SquareMagnitude();
+ if(fT>=SqrLen)
+ {
+ fT = 1.0f;
+ Diff -= Dir;
+ }
+ else
+ {
+ fT /= SqrLen;
+ Diff -= fT*Dir;
+ }
+ }
+
+ if(t) *t = fT;
+
+ return Diff.SquareMagnitude();
+}