mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 14:41:49 +01:00
Collision reworked into a Collision Namespace
Added basic player (Needs work)
This commit is contained in:
@@ -580,7 +580,7 @@ bool utils::Raycast( const Point2f* vertices, const size_t nrVertices, const Poi
|
||||
HitInfo linesHitInfo{};
|
||||
linesHitInfo.lambda = lambda1;
|
||||
linesHitInfo.intersectPoint = Point2f{ rayP1.x + ( ( rayP2.x - rayP1.x ) * lambda1 ), rayP1.y + ( ( rayP2.y - rayP1.y ) * lambda1 ) };
|
||||
linesHitInfo.normal = Vector2f{ q2 - q1 }.Orthogonal( ).Normalized( );
|
||||
linesHitInfo.normal = Vector2f{ q2.x - q1.x, q2.y - q2.y }.Orthogonal( ).Normalized( );
|
||||
hits.push_back(linesHitInfo);
|
||||
}
|
||||
}
|
||||
@@ -645,7 +645,7 @@ float utils::DistPointLineSegment( const Point2f& p, const Point2f& a, const Po
|
||||
|
||||
// Closest point is between A and B, calc intersection point
|
||||
Vector2f intersection{ abNorm.DotProduct(ap) * abNorm + Vector2f{ a } };
|
||||
return Vector2f{ p - intersection }.Length( );
|
||||
return Vector2f{ p.x - intersection.x, p.y - intersection.y }.Length( );
|
||||
}
|
||||
|
||||
bool utils::IntersectRectLine(const Rectf& r, const Point2f& p1, const Point2f& p2, float& intersectMin, float& intersectMax)
|
||||
@@ -693,9 +693,12 @@ bool utils::IsRectInRect(const Rectf& r1, const Rectf& r2) {
|
||||
bool utils::RayVsRect(const Point2f& rayOrigin, const Point2f& rayDir, const Rectf& target,
|
||||
Point2f& contactPoint, Point2f& contactNormal, float& t_hit_near) {
|
||||
|
||||
Point2f t_near = Point2f{(target.BottomLeft() - rayOrigin).x / rayDir.x, (target.BottomLeft() - rayOrigin).y / rayDir.y};
|
||||
Point2f t_far = Point2f{(target.BottomLeft() + Point2f{target.width, target.height} - rayOrigin).x / rayDir.x, (target.BottomLeft() + Point2f{target.width, target.height} - rayOrigin).y / rayDir.y};
|
||||
// Point2f t_near = Point2f{(target.BottomLeft() - rayOrigin).x / rayDir.x, (target.BottomLeft() - rayOrigin).y / rayDir.y};
|
||||
// Point2f t_far = Point2f{(target.BottomLeft() + Point2f{target.width, target.height} - rayOrigin).x / rayDir.x, (target.BottomLeft() + Point2f{target.width, target.height} - rayOrigin).y / rayDir.y};
|
||||
|
||||
Point2f t_near{};
|
||||
Point2f t_far{};
|
||||
|
||||
if(std::isnan(t_far.y) || std::isnan(t_far.x)) return false;
|
||||
if(std::isnan(t_near.y) || std::isnan(t_near.x)) return false;
|
||||
|
||||
@@ -724,7 +727,6 @@ bool utils::RayVsRect(const Point2f& rayOrigin, const Point2f& rayDir, const Rec
|
||||
contactNormal = Point2f{0, -1};
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user