bool Plane::Intersects(const Line &line, float *dist) const { float t; bool intersects = IntersectLinePlane(normal, this->d, line.pos, line.dir, t); if (dist) *dist = t; return intersects; }
bool Plane::Intersects(const Ray &ray, float *d) const { float t; bool success = IntersectLinePlane(PointOnPlane(), normal, ray.pos, ray.dir, &t); if (d) *d = t; return success && t >= 0.f; }
bool Plane::Intersects(const Ray &ray, float *dist) const { float t; bool success = IntersectLinePlane(normal, this->d, ray.pos, ray.dir, t); if (dist) *dist = t; return success && t >= 0.f; }
bool Plane::Intersects(const LineSegment &lineSegment, float *d) const { float t; bool success = IntersectLinePlane(PointOnPlane(), normal, lineSegment.a, lineSegment.Dir(), &t); const float lineSegmentLength = lineSegment.Length(); if (d) *d = t / lineSegmentLength; return success && t >= 0.f && t <= lineSegmentLength; }
bool Plane::Intersects(const LineSegment &lineSegment, float *dist) const { float t; bool success = IntersectLinePlane(normal, this->d, lineSegment.a, lineSegment.Dir(), t); const float lineSegmentLength = lineSegment.Length(); if (dist) *dist = t / lineSegmentLength; return success && t >= 0.f && t <= lineSegmentLength; }
BOOL cCollision::IntersectAABBLine( cAABB& AABB,cLine& Line,D3DXVECTOR3* pPosCross/*=NULL*/,D3DXVECTOR3* pVecReflection/*=NULL*/ ) { for (int iside=0;iside<6;iside++) { if (IntersectLinePlane(Line,AABB.GetPlane(iside),pPosCross,pVecReflection)) { return TRUE; } } return FALSE; }
int Plane::Clip(const Line &line, Ray &outRay) const { float t; bool intersects = IntersectLinePlane(normal, d, line.pos, line.dir, t); if (!intersects) { if (SignedDistance(line.pos) <= 0.f) return 0; // Discard the whole line, it's completely behind the plane. else return 2; // The whole line is in the positive halfspace. Keep all of it. } outRay.pos = line.pos + line.dir * t; // The intersection point if (Dot(line.dir, normal) >= 0.f) outRay.dir = line.dir; else outRay.dir = -line.dir; return 1; // Clipping resulted in a ray being generated. }
bool Plane::Clip(vec &a, vec &b) const { float t; bool intersects = IntersectLinePlane(normal, d, a, b-a, t); if (!intersects || t <= 0.f || t >= 1.f) { if (SignedDistance(a) <= 0.f) return false; // Discard the whole line segment, it's completely behind the plane. else return true; // The whole line segment is in the positive halfspace. Keep all of it. } vec pt = a + (b-a) * t; // The intersection point. // We are either interested in the line segment [a, pt] or the segment [pt, b]. Which one is in the positive side? if (IsOnPositiveSide(a)) b = pt; else a = pt; return true; }
bool Plane::Intersects(const Line &line, float *d) const { return IntersectLinePlane(PointOnPlane(), normal, line.pos, line.dir, d); }
extern bool CollisionUtils::IntersectLineAxisBox(Vector a_lineStart, Vector a_lineEnd, Vector a_boxPos, Vector a_boxDimensions, Vector & a_intersection_OUT) { // Check the dimensions of the line against the box const Vector halfDim = a_boxDimensions * 0.5f; // Check the front plane of the box first Vector planeCentre = Vector(a_boxPos.GetX(), a_boxPos.GetY() - halfDim.GetY(), a_boxPos.GetZ()); if (IntersectLinePlane(a_lineStart, a_lineEnd, planeCentre, Vector(0.0f, -1.0f, 0.0f), a_intersection_OUT)) { if (fabsf(a_intersection_OUT.GetX() - planeCentre.GetX()) <= halfDim.GetX() && fabsf(a_intersection_OUT.GetY() - planeCentre.GetY()) <= halfDim.GetY() && fabsf(a_intersection_OUT.GetZ() - planeCentre.GetZ()) <= halfDim.GetZ()) { return true; } } // Check back plane planeCentre = Vector(a_boxPos.GetX(), a_boxPos.GetY() + halfDim.GetY(), a_boxPos.GetZ()); if (IntersectLinePlane(a_lineStart, a_lineEnd, planeCentre, Vector(0.0f, 1.0f, 0.0f), a_intersection_OUT)) { if (fabsf(a_intersection_OUT.GetX() - planeCentre.GetX()) <= halfDim.GetX() && fabsf(a_intersection_OUT.GetY() - planeCentre.GetY()) <= halfDim.GetY() && fabsf(a_intersection_OUT.GetZ() - planeCentre.GetZ()) <= halfDim.GetZ()) { return true; } } // Check left plane planeCentre = Vector(a_boxPos.GetX() - halfDim.GetX(), a_boxPos.GetY(), a_boxPos.GetZ()); if (IntersectLinePlane(a_lineStart, a_lineEnd, planeCentre, Vector(-1.0f, 0.0f, 0.0f), a_intersection_OUT)) { if (fabsf(a_intersection_OUT.GetX() - planeCentre.GetX()) <= halfDim.GetX() && fabsf(a_intersection_OUT.GetY() - planeCentre.GetY()) <= halfDim.GetY() && fabsf(a_intersection_OUT.GetZ() - planeCentre.GetZ()) <= halfDim.GetZ()) { return true; } } // Check right plane planeCentre = Vector(a_boxPos.GetX() + halfDim.GetX(), a_boxPos.GetY(), a_boxPos.GetZ()); if (IntersectLinePlane(a_lineStart, a_lineEnd, planeCentre, Vector(1.0f, 0.0f, 0.0f), a_intersection_OUT)) { if (fabsf(a_intersection_OUT.GetX() - planeCentre.GetX()) <= halfDim.GetX() && fabsf(a_intersection_OUT.GetY() - planeCentre.GetY()) <= halfDim.GetY() && fabsf(a_intersection_OUT.GetZ() - planeCentre.GetZ()) <= halfDim.GetZ()) { return true; } } // Check top plane planeCentre = Vector(a_boxPos.GetX(), a_boxPos.GetY(), a_boxPos.GetZ() + halfDim.GetZ()); if (IntersectLinePlane(a_lineStart, a_lineEnd, planeCentre, Vector(0.0f, 0.0f, 1.0f), a_intersection_OUT)) { if (fabsf(a_intersection_OUT.GetX() - planeCentre.GetX()) <= halfDim.GetX() && fabsf(a_intersection_OUT.GetY() - planeCentre.GetY()) <= halfDim.GetY() && fabsf(a_intersection_OUT.GetZ() - planeCentre.GetZ()) <= halfDim.GetZ()) { return true; } } // Check bottom plane planeCentre = Vector(a_boxPos.GetX(), a_boxPos.GetY(), a_boxPos.GetZ() - halfDim.GetZ()); if (IntersectLinePlane(a_lineStart, a_lineEnd, planeCentre, Vector(0.0f, 0.0f, -1.0f), a_intersection_OUT)) { if (fabsf(a_intersection_OUT.GetX() - planeCentre.GetX()) <= halfDim.GetX() && fabsf(a_intersection_OUT.GetY() - planeCentre.GetY()) <= halfDim.GetY() && fabsf(a_intersection_OUT.GetZ() - planeCentre.GetZ()) <= halfDim.GetZ()) { return true; } } return false; }