summaryrefslogtreecommitdiff
path: root/src/collision/ColSphere.cpp
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2020-11-14 22:13:32 +0200
committerSergeanur <s.anureev@yandex.ua>2020-11-16 00:36:54 +0200
commit9bb8ebaa1011dc1dc70e3d5bf70c9a55c44b976c (patch)
tree3dcbab653ba34fa1fdc273887bd377603c4ff4f2 /src/collision/ColSphere.cpp
parent26c6908d2552f6032c7440f25e1ad608959ebf0b (diff)
Make collision code placement more like original (+ small fixes)
# Conflicts: # premake5.lua # src/CMakeLists.txt # src/collision/Collision.cpp # src/core/Collision.h
Diffstat (limited to 'src/collision/ColSphere.cpp')
-rw-r--r--src/collision/ColSphere.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/collision/ColSphere.cpp b/src/collision/ColSphere.cpp
new file mode 100644
index 00000000..65f02860
--- /dev/null
+++ b/src/collision/ColSphere.cpp
@@ -0,0 +1,27 @@
+#include "common.h"
+#include "ColSphere.h"
+#include "General.h"
+
+void
+CColSphere::Set(float radius, const CVector &center, uint8 surf, uint8 piece)
+{
+ this->radius = radius;
+ this->center = center;
+ this->surface = surf;
+ this->piece = piece;
+}
+
+bool
+CColSphere::IntersectRay(CVector const& from, CVector const& dir, CVector &entry, CVector &exit)
+{
+ CVector distToCenter = from - center;
+ float distToTouchSqr = distToCenter.MagnitudeSqr() - sq(radius);
+ float root1, root2;
+
+ if (!CGeneral::SolveQuadratic(1.0f, DotProduct(distToCenter, dir) * 2.f, distToTouchSqr, root1, root2))
+ return false;
+
+ entry = from + dir * root1;
+ exit = from + dir * root2;
+ return true;
+} \ No newline at end of file