fix aabb <-> aabb bug

This commit is contained in:
aozhiwei 2020-04-30 00:28:54 +08:00
commit 62cad93ca2
3 changed files with 10 additions and 2 deletions

View File

@ -80,8 +80,9 @@ namespace a8
a8::Vec2 b_v = (b_max - b_min) * 0.5f; a8::Vec2 b_v = (b_max - b_min) * 0.5f;
a8::Vec2 b_center = b_min + b_v; a8::Vec2 b_center = b_min + b_v;
a8::Vec2 z = b_center - a_center; a8::Vec2 z = b_center - a_center;
float u = a_v.x + b_v.x - std::abs(z.x); float u1 = a_v.x + b_v.x - std::abs(z.x);
return u > 0; float u2 = a_v.y + b_v.y - std::abs(z.y);
return u1 > 0 && u2 > 0;
} }
bool IntersectCircleCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad) bool IntersectCircleCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad)

View File

@ -76,6 +76,12 @@ namespace a8
return a1 / 3.1415926f; return a1 / 3.1415926f;
} }
float Vec2::CalcAngleEx(const Vec2& b)
{
float a1 = acos(Dot(b) / Norm() / b.Norm());
return a1 / 3.1415926f;
}
Vec2 Vec2::FromAngle(float angle) Vec2 Vec2::FromAngle(float angle)
{ {
Vec2 vec2; Vec2 vec2;

View File

@ -13,6 +13,7 @@ namespace a8
void Normalize(); void Normalize();
void Rotate(float angle); void Rotate(float angle);
float CalcAngle(const Vec2& b); float CalcAngle(const Vec2& b);
float CalcAngleEx(const Vec2& b);
static Vec2 FromAngle(float angle); static Vec2 FromAngle(float angle);
float Distance(const Vec2& b); float Distance(const Vec2& b);