Changeset 2124 for GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
- Timestamp:
- 02/19/07 02:51:22 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r2070 r2124 209 209 int 210 210 AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 211 float *tmin,212 float *tmax) const211 float *tmin, 212 float *tmax) const 213 213 { 214 214 float minx, maxx, miny, maxy, minz, maxz; … … 301 301 int 302 302 AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 303 float *tmin,304 float *tmax) const303 float *tmin, 304 float *tmax) const 305 305 { 306 306 const float dirEps = 1e-8f; … … 396 396 // of intersection with the ray; it returns 1 if the ray hits 397 397 // the bounding box and 0 if it does not. 398 int 399 AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax, 400 EFaces &entryFace, EFaces &exitFace) const 398 int AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax, 399 EFaces &entryFace, EFaces &exitFace) const 401 400 { 402 401 float minx, maxx, miny, maxy, minz, maxz; … … 532 531 533 532 // computes the signed distances for case tmin<tmax and tmax>0 534 int 535 AxisAlignedBox3::GetMinMaxT(const Ray &ray, float *tmin, float *tmax, 536 EFaces &entryFace, EFaces &exitFace) const 533 int AxisAlignedBox3::GetMinMaxT(const Ray &ray, 534 float *tmin, 535 float *tmax, 536 EFaces &entryFace, 537 EFaces &exitFace) const 537 538 { 538 539 if (!ComputeMinMaxT(ray, tmin, tmax, entryFace, exitFace)) … … 583 584 b.mMax.y <= mMax.y && 584 585 b.mMax.z <= mMax.z); 585 586 586 } 587 587 588 588 589 589 // compute the coordinates of one vertex of the box 590 Vector3 591 AxisAlignedBox3::GetVertex(int xAxis, int yAxis, int zAxis) const 590 Vector3 AxisAlignedBox3::GetVertex(int xAxis, int yAxis, int zAxis) const 592 591 { 593 592 Vector3 p; … … 2389 2388 } 2390 2389 2391 /* 2392 int inline GetIntersection(const float fDst1, 2393 const float fDst2, 2394 const Vector3 p1, 2395 const Vector3 p2, 2396 const Vector3 &hit) 2397 { 2398 if ((fDst1 * fDst2) >= 0.0f) 2399 return 0; 2400 2401 if (fDst1 == fDst2) 2402 return 0; 2403 2404 hit = p1 + (p2 - p1) * (-fDst1 / (fDst2 - fDst1)); 2405 2406 return 1; 2407 } 2408 2409 2410 int inline InBox( CVec3 Hit, CVec3 B1, CVec3 B2, const int Axis) { 2411 if ( Axis==1 && Hit.z > B1.z && Hit.z < B2.z && Hit.y > B1.y && Hit.y < B2.y) return 1; 2412 if ( Axis==2 && Hit.z > B1.z && Hit.z < B2.z && Hit.x > B1.x && Hit.x < B2.x) return 1; 2413 if ( Axis==3 && Hit.x > B1.x && Hit.x < B2.x && Hit.y > B1.y && Hit.y < B2.y) return 1; 2414 return 0; 2415 } 2416 2417 // returns true if line (L1, L2) intersects with the box (B1, B2) 2418 // returns intersection point in Hit 2419 int CheckLineBox( CVec3 B1, CVec3 B2, CVec3 L1, CVec3 L2, CVec3 &Hit) 2420 { 2421 if (L2.x < B1.x && L1.x < B1.x) return false; 2422 if (L2.x > B2.x && L1.x > B2.x) return false; 2423 if (L2.y < B1.y && L1.y < B1.y) return false; 2424 if (L2.y > B2.y && L1.y > B2.y) return false; 2425 if (L2.z < B1.z && L1.z < B1.z) return false; 2426 if (L2.z > B2.z && L1.z > B2.z) return false; 2427 if (L1.x > B1.x && L1.x < B2.x && 2428 L1.y > B1.y && L1.y < B2.y && 2429 L1.z > B1.z && L1.z < B2.z) 2430 {Hit = L1; 2431 return true;} 2432 if ( (GetIntersection( L1.x-B1.x, L2.x-B1.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 )) 2433 || (GetIntersection( L1.y-B1.y, L2.y-B1.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 )) 2434 || (GetIntersection( L1.z-B1.z, L2.z-B1.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 )) 2435 || (GetIntersection( L1.x-B2.x, L2.x-B2.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 )) 2436 || (GetIntersection( L1.y-B2.y, L2.y-B2.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 )) 2437 || (GetIntersection( L1.z-B2.z, L2.z-B2.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 ))) 2438 return true; 2439 2440 return false; 2441 } 2442 */ 2443 2444 } 2445 2390 2391 bool AxisAlignedBox3::Intersects(const Vector3 &lStart, 2392 const Vector3 &lEnd) const 2393 { 2394 float st, et, fst = 0, fet = 1; 2395 float const *bmin = &mMin.x; 2396 float const *bmax = &mMax.x; 2397 float const *si = &lStart.x; 2398 float const *ei = &lEnd.x; 2399 2400 for (int i = 0; i < 3; ++ i) 2401 { 2402 if (*si < *ei) 2403 { 2404 if (*si > *bmax || *ei < *bmin) 2405 return false; 2406 2407 const float di = *ei - *si; 2408 2409 st = (*si < *bmin)? (*bmin - *si) / di : 0; 2410 et = (*ei > *bmax)? (*bmax - *si) / di : 1; 2411 } 2412 else 2413 { 2414 if (*ei > *bmax || *si < *bmin) 2415 return false; 2416 2417 const float di = *ei - *si; 2418 2419 st = (*si > *bmax)? (*bmax - *si) / di : 0; 2420 et = (*ei < *bmin)? (*bmin - *si) / di : 1; 2421 } 2422 2423 if (st > fst) fst = st; 2424 if (et < fet) fet = et; 2425 if (fet < fst) 2426 return false; 2427 2428 ++ bmin; ++ bmax; 2429 ++ si; ++ ei; 2430 } 2431 2432 //*time = fst; 2433 return true; 2434 } 2435 2436 } 2437
Note: See TracChangeset
for help on using the changeset viewer.