//\=============================================================================================================================== //\ Distance to a wall with a counter clockwise rotated normal //\=============================================================================================================================== float Vector2::DistToWallCCWNormal(const Vector2& start, const Vector2& end) const { Vector2 p = start - end; p.Normalise(); Vector2 n = p.PerpCCW(); Vector2 q = *this - start; float d = DotProd(q, n); return d; }
Vector2 Vector2::WallCollisionCCWNormal(const Vector2& start, const Vector2& end, const Vector2& dir, const float& bounce) const { Vector2 p = start - end; p.Normalise(); Vector2 n = p.PerpCCW(); Vector2 q = *this - start; float d = DotProd(q, n); if (d < 0.f) { Vector2 v2 = dir - (1 + bounce) * (DotProd(dir, n) * n); v2.Normalise(); return v2; } return *this + dir; }