Ignore:
Timestamp:
02/18/09 08:01:56 (15 years ago)
Author:
mattausch
Message:

played around with reprojection, cleaned up code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h

    r3243 r3318  
    2525        SimpleRay(const Vector3 &o, const Vector3 &d): mOrigin(o), mDirection(d) {} 
    2626 
    27         Vector3 Extrap(const float t) const  
     27        Vector3 Extrap(float t) const  
    2828        { 
    2929                return mOrigin + mDirection * t; 
     
    4141/** Axis alignedd box class. 
    4242    This is a box in 3-space, defined by min and max 
    43         corner vectors.  Many useful operations are defined. 
     43        corner vectors. Many useful operations are defined. 
    4444*/ 
    4545class AxisAlignedBox3 
     
    7070        /** Computes the mid point in the given axis. 
    7171        */ 
    72         float Center(const int axis) const; 
     72        float Center(int axis) const; 
    7373        /** The vertex of the box with the smallest values in all dimensions. 
    7474        */ 
    75         float Min(const int axis) const; 
     75        float Min(int axis) const; 
    7676        /** The vertex of the box with the largest values in all dimensions. 
    7777        */ 
    78         float Max(const int axis) const; 
     78        float Max(int axis) const; 
    7979        /** The extent of the box in the given axis. 
    8080        */ 
    81         float Size(const int axis) const; 
     81        float Size(int axis) const; 
    8282        /** Returns axis where box has largest extent. 
    8383        */ 
     
    138138        /** Expand the axis-aligned box to include given values in particular axis. 
    139139        */ 
    140         void Include(const int &axis, const float &newBound); 
     140        void Include(int axis, float newBound); 
    141141        /** Includes returns true if a includes b (completely) 
    142142        */ 
     
    243243        /** Returns the supporting plane of this face. 
    244244        */ 
    245         Plane3 GetPlane(const int face) const; 
     245        Plane3 GetPlane(int face) const; 
    246246        /** Returns  
    247247                0 if box intersects plane 
     
    358358 
    359359 
    360 // -------------------------------------------------------------------------- 
    361 // Implementation of inline (member) functions 
     360 
     361///////////////////////////////////////////////////////// 
     362//-- Implementation of inline (member) functions 
     363 
    362364 
    363365inline float AxisAlignedBox3::Radius() const  
     
    373375 
    374376 
    375 inline bool 
    376 Overlap(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 
     377inline bool Overlap(const AxisAlignedBox3 &x, 
     378                                        const AxisAlignedBox3 &y) 
    377379{ 
    378380        if (x.mMax.x < y.mMin.x || 
     
    381383                x.mMin.y > y.mMax.y || 
    382384                x.mMax.z < y.mMin.z || 
    383                 x.mMin.z > y.mMax.z) { 
     385                x.mMin.z > y.mMax.z) 
     386        { 
    384387                        return false; 
    385388        } 
     389 
    386390        return true; 
    387391} 
    388392 
    389 inline bool 
    390 OverlapS(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 
     393 
     394inline bool OverlapS(const AxisAlignedBox3 &x,  
     395                                         const AxisAlignedBox3 &y) 
    391396{ 
    392397        if (x.mMax.x <= y.mMin.x || 
     
    395400                x.mMin.y >= y.mMax.y || 
    396401                x.mMax.z <= y.mMin.z || 
    397                 x.mMin.z >= y.mMax.z) { 
     402                x.mMin.z >= y.mMax.z)  
     403        { 
    398404                        return false; 
    399405        } 
     406 
    400407        return true; 
    401408} 
    402409 
    403 inline bool 
    404 Overlap(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y, float eps) 
    405 { 
    406         if ( (x.mMax.x - eps) < y.mMin.x || 
     410 
     411inline bool Overlap(const AxisAlignedBox3 &x, 
     412                                        const AxisAlignedBox3 &y, 
     413                                        float eps) 
     414{ 
     415        if ((x.mMax.x - eps) < y.mMin.x || 
    407416                (x.mMin.x + eps) > y.mMax.x || 
    408417                (x.mMax.y - eps) < y.mMin.y || 
    409418                (x.mMin.y + eps) > y.mMax.y || 
    410419                (x.mMax.z - eps) < y.mMin.z || 
    411                 (x.mMin.z + eps) > y.mMax.z ) { 
     420                (x.mMin.z + eps) > y.mMax.z )  
     421        { 
    412422                        return false; 
    413423        } 
     424 
    414425        return true; 
    415426} 
    416427 
    417 inline AxisAlignedBox3 
    418 Intersect(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 
    419 { 
    420         if (x.Unbounded()) 
     428 
     429inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x, 
     430                                                                 const AxisAlignedBox3 &y) 
     431{ 
     432        if (x.Unbounded())  
     433        { 
    421434                return y; 
     435        } 
    422436        else 
    423                 if (y.Unbounded()) 
    424                         return x; 
     437        { 
     438                if (y.Unbounded()) return x; 
     439        } 
     440 
    425441        AxisAlignedBox3 ret = x; 
    426         if (Overlap(ret, y)) { 
     442 
     443        if (Overlap(ret, y))  
     444        { 
    427445                Maximize(ret.mMin, y.mMin); 
    428446                Minimize(ret.mMax, y.mMax); 
     447 
    429448                return ret; 
    430449        } 
    431         else      // Null intersection. 
     450        else // Null intersection 
     451        { 
    432452                return AxisAlignedBox3(Vector3(0), Vector3(0)); 
    433         // return AxisAlignedBox3(Vector3(0), Vector3(-1)); 
    434 } 
    435  
    436 inline AxisAlignedBox3 
    437 Union(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 
     453        } 
     454} 
     455 
     456 
     457inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x,  
     458                                                         const AxisAlignedBox3 &y) 
    438459{ 
    439460        Vector3 min = x.mMin; 
    440461        Vector3 max = x.mMax; 
     462 
    441463        Minimize(min, y.mMin); 
    442464        Maximize(max, y.mMax); 
     465 
    443466        return AxisAlignedBox3(min, max); 
    444467} 
    445468 
    446 inline AxisAlignedBox3 
    447 Transform(const AxisAlignedBox3 &box, const Matrix4x4 &tform) 
    448 { 
    449         Vector3 mmin(MAXFLOAT); 
    450         Vector3 mmax(-MAXFLOAT); 
     469 
     470inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box,  
     471                                                                 const Matrix4x4 &tform) 
     472{ 
     473        const Vector3 mmin(MAXFLOAT); 
     474        const Vector3 mmax(-MAXFLOAT); 
    451475         
    452476        AxisAlignedBox3 ret(mmin, mmax); 
     
    464488} 
    465489 
    466 inline float RatioOfOverlap(const AxisAlignedBox3 &box1, const AxisAlignedBox3 &box2) 
     490 
     491inline float RatioOfOverlap(const AxisAlignedBox3 &box1, 
     492                                                        const AxisAlignedBox3 &box2) 
    467493{ 
    468494        // return ratio of intersection to union 
     
    473499} 
    474500 
    475 inline int operator==(const AxisAlignedBox3 &A, const AxisAlignedBox3 &B) 
     501 
     502inline int operator==(const AxisAlignedBox3 &A,  
     503                                          const AxisAlignedBox3 &B) 
    476504{ 
    477505        return (A.mMin == B.mMin) && (A.mMax == B.mMax); 
Note: See TracChangeset for help on using the changeset viewer.