From 1d405bd0883ba0919c34b30f50d56ae6debc17f8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 10 Jun 2019 17:09:54 +0800 Subject: [PATCH] 1 --- server/gameserver/collision.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/server/gameserver/collision.cc b/server/gameserver/collision.cc index 517cff5..de069db 100644 --- a/server/gameserver/collision.cc +++ b/server/gameserver/collision.cc @@ -5,6 +5,8 @@ #include #include +#include "collision.h" + bool IntersectSegmentCircle(Vector2D p0, Vector2D p1, Vector2D pos, float rad) { Vector2D t = p1 - p0; @@ -29,6 +31,37 @@ bool IntersectSegmentCircle(Vector2D p0, Vector2D p1, Vector2D pos, float rad) bool IntersectSegmentAabb(Vector2D p0, Vector2D p1, Vector2D _min, Vector2D _max) { +#if 1 + Vector2D c = (_min + _max) * 0.5f; + Vector2D e = _max - c; + Vector2D m = (p0 + p1) * 0.5f; + Vector2D d = p1 - m; + m = m - c; + + float adx = std::abs(d.x); + if (std::abs(m.x) > e.x + adx) { + return false; + } + float ady = std::abs(d.y); + if (std::abs(m.y) > e.y + ady) { + return false; + } +#if 1 + if (p0.x > p1.x) { + float tmp = p0.x; + p0.x = p1.x; + p1.x = tmp; + } + if (p0.y > p1.y) { + float tmp = p0.y; + p0.y = p1.y; + p1.y = tmp; + } + return IntersectAabbAabb(p0, p1, _min, _max); +#else + return true; +#endif +#else float t = 0.0f; float d = FLT_MAX; Vector2D n = p0; @@ -63,6 +96,7 @@ bool IntersectSegmentAabb(Vector2D p0, Vector2D p1, Vector2D _min, Vector2D _max return false; } return true; +#endif } bool IntersectAabbCircle(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b_rad)