bool AABB::Intersects(const Line &line, float *dNear, float *dFar) const { float tNear, tFar; bool success = IntersectLineAABB(line.pos, line.dir, *this, tNear, tFar); if (dNear) *dNear = tNear; if (dFar) *dFar = tFar; return success; }
bool AABB::Intersects(const LineSegment &lineSegment, float *dNear, float *dFar) const { float tNear, tFar; bool success = IntersectLineAABB(lineSegment.a, lineSegment.Dir(), *this, tNear, tFar); success = (tNear >= 0.f && tNear*tNear <= lineSegment.LengthSq()); if (dNear) *dNear = tNear / lineSegment.Length(); if (dFar) *dFar = tFar / lineSegment.Length(); return success; }
bool AABB::Intersects(const LineSegment &lineSegment, float &dNear, float &dFar) const { vec dir = lineSegment.b - lineSegment.a; float len = dir.Length(); if (len <= 1e-4f) // Degenerate line segment? Fall back to point-in-AABB test. { dNear = 0.f; dFar = 1.f; return Contains(lineSegment.a); } float invLen = 1.f / len; dir *= invLen; dNear = 0.f; dFar = len; bool hit = IntersectLineAABB(lineSegment.a, dir, dNear, dFar); dNear *= invLen; dFar *= invLen; return hit; }
bool LightmapGenerator::CheckShadow(const RLIGHT* plight, const RCONVEXPOLYGONINFO* poly, const rboundingbox& bbox, const v3& pnormal, const v3& diff, int lightmapsize, int j, int k, int au, int av, int ax) { if ((plight->dwFlags & RM_FLAG_CASTSHADOW) == 0 || (poly->dwFlags & RM_FLAG_RECEIVESHADOW) == 0) return false; rvector position; position[au] = bbox.vmin[au] + ((float)k / (float)lightmapsize)*diff[au]; position[av] = bbox.vmin[av] + ((float)j / (float)lightmapsize)*diff[av]; position[ax] = (-poly->plane.d - pnormal[au] * position[au] - pnormal[av] * position[av]) / pnormal[ax]; float fDistanceToPolygon = Magnitude(position - plight->Position); RBSPPICKINFO bpi; if (bsp.PickShadow(plight->Position, position, &bpi)) { float fDistanceToPickPos = Magnitude(bpi.PickPos - plight->Position); if (fDistanceToPolygon > fDistanceToPickPos + Tolerance) return true; } #ifdef _WIN32 for (auto& ObjectInfo : bsp.m_ObjectList) { if (!ObjectInfo.pVisualMesh) return false; rmatrix inv = Inverse(ObjectInfo.pVisualMesh->m_WorldMat); rvector origin = plight->Position * inv; rvector target = position * inv; rvector dir = target - origin; rvector dirorigin = position - plight->Position; rvector vOut; rboundingbox bbox; bbox.vmin = ObjectInfo.pVisualMesh->m_vBMin; bbox.vmax = ObjectInfo.pVisualMesh->m_vBMax; auto bBBTest = IntersectLineAABB(origin, dir, bbox); float t; if (bBBTest && ObjectInfo.pVisualMesh->Pick(plight->Position, dirorigin, &vOut, &t)) { rvector PickPos = plight->Position + vOut*t; return true; } } #else assert(false); #endif return false; }
bool AABB::Intersects(const Line &line, float &dNear, float &dFar) const { dNear = -FLOAT_INF; dFar = FLOAT_INF; return IntersectLineAABB(line.pos, line.dir, dNear, dFar); }
bool AABB::Intersects(const Ray &ray, float &dNear, float &dFar) const { dNear = 0.f; dFar = FLOAT_INF; return IntersectLineAABB(ray.pos, ray.dir, dNear, dFar); }