Changeset 2740 for GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
- Timestamp:
- 06/05/08 18:48:10 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r2723 r2740 9 9 #include "VssRay.h" 10 10 #include "IntersectableWrapper.h" 11 12 11 #include "SimpleRay.h" 13 12 #include <cassert> 14 13 15 14 15 16 16 using namespace std; 17 17 18 namespace GtpVisibilityPreprocessor { 18 19 namespace GtpVisibilityPreprocessor 20 { 19 21 20 22 #define FATAL Debug … … 2632 2634 } 2633 2635 2634 } 2635 2636 2637 Rectangle3 AxisAlignedBox3::GetNearestFace(const Vector3 &pt) const 2638 { 2639 float minDist = 1e20f; 2640 int face = 0; 2641 2642 if ((pt.x - mMin.x) < minDist) {minDist = (pt.x - mMin.x); face = 0;} 2643 if ((mMax.x - pt.x) < minDist) {minDist = (mMax.x - pt.x); face = 1;} 2644 if ((pt.y - mMin.y) < minDist) {minDist = (pt.y - mMin.y); face = 2;} 2645 if ((mMax.y - pt.y) < minDist) {minDist = (mMax.y - pt.y); face = 3;} 2646 if ((pt.z - mMin.z) < minDist) {minDist = (pt.z - mMin.z); face = 4;} 2647 if ((mMax.z - pt.z) < minDist) {minDist = (mMax.z - pt.z); face = 5;} 2648 2649 return GetFace(face); 2650 } 2651 2652 2653 bool AxisAlignedBox3::Intersects(const SimpleRay &ray, float &tnear, float &tfar) const 2654 { 2655 tnear = -1e20f; 2656 tfar = 1e20f; 2657 2658 const Vector3 origin = ray.mOrigin; 2659 const Vector3 dir = ray.mDirection; 2660 2661 float t1, t2; 2662 2663 // ray is parallel to the planes 2664 if (dir.x == 0) 2665 { 2666 if ((origin.x < mMin.x) || (origin.x > mMax.x)) 2667 return false; // origin not between planes 2668 } 2669 else 2670 { 2671 // time at which ray intersects minimum X plane 2672 t1 = (mMin.x - origin.x) / dir.x; 2673 // time at which ray intersects maximum X plane 2674 t2 = (mMax.x - origin.x) / dir.x; 2675 2676 if (t1 > t2) 2677 swap(t1, t2); 2678 2679 if (t1 > tnear) 2680 tnear = t1; 2681 2682 if (t2 < tfar) 2683 tfar = t2; 2684 2685 if (tnear > tfar) 2686 return false; 2687 2688 if (tfar < 0) 2689 return false; 2690 } 2691 2692 if (dir.y == 0) // ray is parallel to the planes 2693 { 2694 if ((origin.y < mMin.y) || (origin.y > mMax.y)) 2695 return false; // origin not between planes) 2696 } 2697 else 2698 { 2699 t1 = (mMin.y - origin.y) / dir.y; 2700 t2 = (mMax.y - origin.y) / dir.y; 2701 2702 if (t1 > t2) 2703 swap(t1, t2); 2704 2705 if (t1 > tnear) 2706 tnear = t1; 2707 2708 if (t2 < tfar) 2709 tfar = t2; 2710 2711 if (tnear > tfar) 2712 return false; 2713 2714 if (tfar < 0) 2715 return false; 2716 } 2717 2718 if (dir.z == 0) // ray is parallel to the planes 2719 { 2720 if ((origin.z < mMin.z) || (origin.z > mMax.z)) 2721 return false; // origin not between planes) 2722 } 2723 else 2724 { 2725 t1 = (mMin.z - origin.z) / dir.z; 2726 t2 = (mMax.z - origin.z) / dir.z; 2727 2728 if (t1 > t2) 2729 swap(t1, t2); 2730 2731 if (t1 > tnear) 2732 tnear = t1; 2733 2734 if (t2 < tfar) 2735 tfar = t2; 2736 2737 if (tnear > tfar) 2738 return false; 2739 2740 if (tfar < 0) 2741 return false; 2742 } 2743 2744 return true; 2745 } 2746 2747 } 2748
Note: See TracChangeset
for help on using the changeset viewer.