Changeset 3318 for GTP


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

played around with reprojection, cleaned up code

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
7 edited

Legend:

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

    r3202 r3318  
    2929{ 
    3030        return s << '[' << A.mMin.x << ", " << A.mMin.y << ", " << A.mMin.z << "][" 
    31                 << A.mMax.x << ", " << A.mMax.y << ", " << A.mMax.z << ']'; 
     31                     << A.mMax.x << ", " << A.mMax.y << ", " << A.mMax.z << ']'; 
    3232} 
    3333 
     
    3939        // read "[min.x, min.y, min.z][mMax.x, mMax.y, mMax.z]" 
    4040        return s >> a >> A.mMin.x >> a >> A.mMin.y >> a >> A.mMin.z >> a >> a 
    41                 >> A.mMax.x >> a >> A.mMax.y >> a >> A.mMax.z >> a; 
     41                     >> A.mMax.x >> a >> A.mMax.y >> a >> A.mMax.z >> a; 
    4242} 
    4343 
    4444 
    4545AxisAlignedBox3::AxisAlignedBox3()  
    46 { } 
    47  
    48  
    49 AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax) 
     46{} 
     47 
     48 
     49AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin, 
     50                                                                 const Vector3 &nMax) 
    5051: mMin(nMin), mMax(nMax) 
    5152{} 
     
    7273 
    7374        for (it = newpoly.mVertices.begin(); it != it_end; ++ it) 
     75        { 
    7476                Include(*it); 
     77        } 
    7578} 
    7679 
     
    8184 
    8285        for (it = polys.begin(); it != it_end; ++ it) 
     86        { 
    8387                Include(*(*it)); 
     88        } 
    8489} 
    8590 
     
    9499bool AxisAlignedBox3::IsCorrect() 
    95100{ 
    96         if ( (mMin.x > mMax.x) || 
     101        if ((mMin.x > mMax.x) || 
    97102                (mMin.y > mMax.y) || 
    98103                (mMin.z > mMax.z) ) 
     104        { 
    99105                return false; // box is not formed 
     106        } 
     107 
    100108        return true; 
    101109} 
    102110 
    103111 
    104 void AxisAlignedBox3::GetEdge(const int edge, Vector3 *a, Vector3 *b) const 
    105 { 
    106         switch(edge) { 
    107   case 0: 
    108           a->SetValue(mMin.x, mMin.y, mMin.z); 
    109           b->SetValue(mMin.x, mMin.y, mMax.z); 
    110           break; 
    111   case 1: 
    112           a->SetValue(mMin.x, mMin.y, mMin.z); 
    113           b->SetValue(mMin.x, mMax.y, mMin.z); 
    114           break; 
    115   case 2: 
    116           a->SetValue(mMin.x, mMin.y, mMin.z); 
    117           b->SetValue(mMax.x, mMin.y, mMin.z); 
    118           break; 
    119   case 3: 
    120           a->SetValue(mMax.x, mMax.y, mMax.z); 
    121           b->SetValue(mMax.x, mMax.y, mMin.z); 
    122           break; 
    123   case 4: 
    124           a->SetValue(mMax.x, mMax.y, mMax.z); 
    125           b->SetValue(mMax.x, mMin.y, mMax.z); 
    126           break; 
    127   case 5: 
    128           a->SetValue(mMax.x, mMax.y, mMax.z); 
    129           b->SetValue(mMin.x, mMax.y, mMax.z); 
    130           break; 
    131  
    132   case 6: 
    133           a->SetValue(mMin.x, mMin.y, mMax.z); 
    134           b->SetValue(mMin.x, mMax.y, mMax.z); 
    135           break; 
    136   case 7: 
    137           a->SetValue(mMin.x, mMin.y, mMax.z); 
    138           b->SetValue(mMax.x, mMin.y, mMax.z); 
    139           break; 
    140   case 8: 
    141           a->SetValue(mMin.x, mMax.y, mMin.z); 
    142           b->SetValue(mMin.x, mMax.y, mMax.z); 
    143           break; 
    144   case 9: 
    145           a->SetValue(mMin.x, mMax.y, mMin.z); 
    146           b->SetValue(mMax.x, mMax.y, mMin.z); 
    147           break; 
    148   case 10: 
    149           a->SetValue(mMax.x, mMin.y, mMin.z); 
    150           b->SetValue(mMax.x, mMax.y, mMin.z); 
    151           break; 
    152   case 11: 
    153           a->SetValue(mMax.x, mMin.y, mMin.z); 
    154           b->SetValue(mMax.x, mMin.y, mMax.z); 
    155           break; 
     112void AxisAlignedBox3::GetEdge(int edge,  
     113                                                          Vector3 *a,  
     114                                                          Vector3 *b) const 
     115{ 
     116        switch(edge)  
     117        { 
     118        case 0: 
     119                a->SetValue(mMin.x, mMin.y, mMin.z); 
     120                b->SetValue(mMin.x, mMin.y, mMax.z); 
     121                break; 
     122        case 1: 
     123                a->SetValue(mMin.x, mMin.y, mMin.z); 
     124                b->SetValue(mMin.x, mMax.y, mMin.z); 
     125                break; 
     126        case 2: 
     127                a->SetValue(mMin.x, mMin.y, mMin.z); 
     128                b->SetValue(mMax.x, mMin.y, mMin.z); 
     129                break; 
     130        case 3: 
     131                a->SetValue(mMax.x, mMax.y, mMax.z); 
     132                b->SetValue(mMax.x, mMax.y, mMin.z); 
     133                break; 
     134        case 4: 
     135                a->SetValue(mMax.x, mMax.y, mMax.z); 
     136                b->SetValue(mMax.x, mMin.y, mMax.z); 
     137                break; 
     138        case 5: 
     139                a->SetValue(mMax.x, mMax.y, mMax.z); 
     140                b->SetValue(mMin.x, mMax.y, mMax.z); 
     141                break; 
     142 
     143        case 6: 
     144                a->SetValue(mMin.x, mMin.y, mMax.z); 
     145                b->SetValue(mMin.x, mMax.y, mMax.z); 
     146                break; 
     147        case 7: 
     148                a->SetValue(mMin.x, mMin.y, mMax.z); 
     149                b->SetValue(mMax.x, mMin.y, mMax.z); 
     150                break; 
     151        case 8: 
     152                a->SetValue(mMin.x, mMax.y, mMin.z); 
     153                b->SetValue(mMin.x, mMax.y, mMax.z); 
     154                break; 
     155        case 9: 
     156                a->SetValue(mMin.x, mMax.y, mMin.z); 
     157                b->SetValue(mMax.x, mMax.y, mMin.z); 
     158                break; 
     159        case 10: 
     160                a->SetValue(mMax.x, mMin.y, mMin.z); 
     161                b->SetValue(mMax.x, mMax.y, mMin.z); 
     162                break; 
     163        case 11: 
     164                a->SetValue(mMax.x, mMin.y, mMin.z); 
     165                b->SetValue(mMax.x, mMin.y, mMax.z); 
     166                break; 
    156167        } 
    157168} 
     
    159170// returns the vertex indices in the range <0..7>, v = 4.x + 2.y + z, where 
    160171// x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 
    161 void 
    162 AxisAlignedBox3::GetEdge(const int edge, int  &aIdx, int &bIdx) const 
    163 { 
    164         switch(edge) { 
    165   case 0: aIdx = 0; bIdx = 1; break; 
    166   case 1: aIdx = 0; bIdx = 2; break; 
    167   case 2: aIdx = 0; bIdx = 4; break; 
    168   case 3: aIdx = 7; bIdx = 6; break; 
    169   case 4: aIdx = 7; bIdx = 5; break; 
    170   case 5: aIdx = 7; bIdx = 3; break; 
    171   case 6: aIdx = 1; bIdx = 3; break; 
    172   case 7: aIdx = 1; bIdx = 5; break; 
    173   case 8: aIdx = 2; bIdx = 3; break; 
    174   case 9: aIdx = 2; bIdx = 6; break; 
    175   case 10: aIdx = 4; bIdx = 6; break; 
    176   case 11: aIdx = 4; bIdx = 5; break; 
    177         } 
    178 } 
    179  
    180 void 
    181 AxisAlignedBox3::Include(const int &axis, const float &newBound) 
    182 { 
    183         switch (axis) { 
    184         case 0: { // x-axis 
    185                 if (mMin.x > newBound) 
    186                         mMin.x = newBound; 
    187                 if (mMax.x < newBound) 
    188                         mMax.x = newBound; 
    189                 break; 
    190                         } 
    191         case 1: { // y-axis 
    192                 if (mMin.y > newBound) 
    193                         mMin.y = newBound; 
    194                 if (mMax.y < newBound) 
    195                         mMax.y = newBound; 
    196                 break; 
    197                         } 
    198         case 2: { // z-axis 
    199                 if (mMin.z > newBound) 
    200                         mMin.z = newBound; 
    201                 if (mMax.z < newBound) 
    202                         mMax.z = newBound; 
    203                 break; 
    204                         } 
     172void AxisAlignedBox3::GetEdge(int edge, int  &aIdx, int &bIdx) const 
     173{ 
     174        switch(edge)  
     175        { 
     176        case 0: aIdx = 0; bIdx = 1; break; 
     177        case 1: aIdx = 0; bIdx = 2; break; 
     178        case 2: aIdx = 0; bIdx = 4; break; 
     179        case 3: aIdx = 7; bIdx = 6; break; 
     180        case 4: aIdx = 7; bIdx = 5; break; 
     181        case 5: aIdx = 7; bIdx = 3; break; 
     182        case 6: aIdx = 1; bIdx = 3; break; 
     183        case 7: aIdx = 1; bIdx = 5; break; 
     184        case 8: aIdx = 2; bIdx = 3; break; 
     185        case 9: aIdx = 2; bIdx = 6; break; 
     186        case 10: aIdx = 4; bIdx = 6; break; 
     187        case 11: aIdx = 4; bIdx = 5; break; 
     188        } 
     189} 
     190 
     191 
     192void AxisAlignedBox3::Include(int axis, float newBound) 
     193{ 
     194        switch (axis)  
     195        { 
     196        case 0:  
     197                { // x-axis 
     198                        if (mMin.x > newBound) mMin.x = newBound; 
     199                        if (mMax.x < newBound) mMax.x = newBound; 
     200                        break; 
     201                } 
     202        case 1:  
     203                { // y-axis 
     204                        if (mMin.y > newBound) mMin.y = newBound; 
     205                        if (mMax.y < newBound) mMax.y = newBound; 
     206                        break; 
     207                } 
     208        case 2:  
     209                { // z-axis 
     210                        if (mMin.z > newBound) mMin.z = newBound; 
     211                        if (mMax.z < newBound) mMax.z = newBound; 
     212                        break; 
     213                } 
    205214        } 
    206215} 
     
    213222} 
    214223 
    215 int 
    216 AxisAlignedBox3::IsInside(const Vector3 &v) const 
     224 
     225int AxisAlignedBox3::IsInside(const Vector3 &v) const 
    217226{ 
    218227        return !((v.x < mMin.x) || 
    219                     (v.x > mMax.x) || 
    220                         (v.y < mMin.y) || 
    221                         (v.y > mMax.y) || 
    222                         (v.z < mMin.z) || 
    223                         (v.z > mMax.z)); 
     228                     (v.x > mMax.x) || 
     229                         (v.y < mMin.y) || 
     230                         (v.y > mMax.y) || 
     231                         (v.z < mMin.z) || 
     232                         (v.z > mMax.z)); 
    224233} 
    225234 
     
    228237{ 
    229238        return (b.mMin.x >= mMin.x && 
    230                 b.mMin.y >= mMin.y && 
    231                 b.mMin.z >= mMin.z && 
    232                 b.mMax.x <= mMax.x && 
    233                 b.mMax.y <= mMax.y && 
    234                 b.mMax.z <= mMax.z); 
     239                b.mMin.y >= mMin.y && 
     240                        b.mMin.z >= mMin.z && 
     241                        b.mMax.x <= mMax.x && 
     242                        b.mMax.y <= mMax.y && 
     243                        b.mMax.z <= mMax.z); 
    235244} 
    236245 
    237246 
    238247// compute the coordinates of one vertex of the box 
    239 Vector3 AxisAlignedBox3::GetVertex(int xAxis, int yAxis, int zAxis) const 
     248Vector3 AxisAlignedBox3::GetVertex(int xAxis,  
     249                                                                   int yAxis,  
     250                                                                   int zAxis) const 
    240251{ 
    241252        Vector3 p; 
    242         if (xAxis) 
    243                 p.x = mMax.x; 
    244         else 
    245                 p.x = mMin.x; 
    246  
    247         if (yAxis) 
    248                 p.y = mMax.y; 
    249         else 
    250                 p.y = mMin.y; 
    251  
    252         if (zAxis) 
    253                 p.z = mMax.z; 
    254         else 
    255                 p.z = mMin.z; 
     253 
     254        p.x = xAxis ? mMax.x : mMin.x; 
     255        p.y = yAxis ? mMax.y : mMin.y; 
     256        p.z = zAxis ? mMax.z : mMin.z; 
     257 
    256258        return p; 
    257259} 
     
    304306{ 
    305307        Vector3 ext = mMax - mMin; 
    306  
    307         return 2.0f * (ext.x * ext.y + 
    308                 ext.x * ext.z + 
    309                 ext.y * ext.z); 
     308        return 2.0f * (ext.x * ext.y + ext.x * ext.z + ext.y * ext.z); 
    310309} 
    311310 
     
    318317 
    319318const int AxisAlignedBox3::bvertices[27][9] = 
    320 {                   // region number.. position 
     319{                                // region number .. position 
    321320        {5,1,3,2,6,4,-1,-1,-1},      // 0 .. x=0 y=0 z=0 
    322321        {4,5,1,3,2,0,-1,-1,-1},      // 1 .. x=0 y=0 z=1 
     
    361360// one to three triples: (axis, min_vertex, max_vertex), axis==-1(terminator) 
    362361const int AxisAlignedBox3::bfaces[27][10] = 
    363 {                              // region number .. position 
     362{                                // region number .. position 
    364363        {0,0,3,1,0,5,2,0,6,-1},      // 0 .. x=0 y=0 z=0 
    365364        {0,0,3,1,0,5,-1,-1,-1,-1},   // 1 .. x=0 y=0 z=1 
     
    473472// The sequence is ended by 15, number -1 is used as the separator 
    474473// between the vertices and coordinates. 
    475 const int 
    476 AxisAlignedBox3::cvertices[27][9] =  
    477 {                   // region number.. position 
     474const int AxisAlignedBox3::cvertices[27][9] =  
     475{                                // region number.. position 
    478476        {0,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D one vertex 
    479477        {0,1,-1,0,0,0,1,15,15},      // 1 .. x=0 y=0 z=1 D two vertices foll. by 2 
     
    536534//        the sequence start with 15 .. no further testing is necessary 
    537535//        in this case 
    538 const int 
    539 AxisAlignedBox3::csvertices[27][6] =  
    540 {                   // region number.. position 
     536const int AxisAlignedBox3::csvertices[27][6] =  
     537{                        // region number.. position 
    541538        {0,15,15,15,15,15},  // 0 .. x=0 y=0 z=0 D vertex only 
    542539        {8,0,0,0,1,15},      // 1 .. x=0 y=0 z=1 D two coords. 
     
    586583// For testing, if the AABB is whole in the sphere, it is enough 
    587584// to test only vertices, either 1,2,4, or 8. 
    588 const int 
    589 AxisAlignedBox3::fvertices[27][9] =  
    590 {                   // region number.. position 
     585const int AxisAlignedBox3::fvertices[27][9] =  
     586{                                // region number.. position 
    591587        {7,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D 
    592588        {6,7,15,15,15,15,15,15,15},  // 1 .. x=0 y=0 z=1 D 
     
    635631// The number of vertices is minimized using some assumptions 
    636632// about the ortogonality of vertices and sphere properties. 
    637 const int 
    638 AxisAlignedBox3::fsvertices[27][9] =  
    639 {                   // region number.. position 
     633const int AxisAlignedBox3::fsvertices[27][9] =  
     634{                                // region number.. position 
    640635        {7,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D 1 vertex 
    641636        {6,7,15,15,15,15,15,15,15},  // 1 .. x=0 y=0 z=1 D 2 vertices 
     
    686681        const float c = (float)(M_PI * 0.25); 
    687682 
    688         if (y < 0.0) { 
     683        if (y < 0.0) 
     684        { 
    689685                if (y < -1.0) 
    690686                        return c * (-2.0f + x / y); // for angle in <-PI/2, -PI/4) 
     
    692688                        return c * (y / x); // for angle in <-PI/4 , 0> 
    693689        } 
    694         else { 
     690        else  
     691        { 
    695692                if (y > 1.0) 
    696693                        return c * (2.0f - x / y); // for angle in <PI/4, PI/2> 
     
    702699 
    703700// This definition allows to be a point when answering true 
    704 bool 
    705 AxisAlignedBox3::IsCorrectAndNotPoint() const 
    706 { 
    707         if ( (mMin.x > mMax.x) || 
     701bool AxisAlignedBox3::IsCorrectAndNotPoint() const 
     702{ 
     703        if ((mMin.x > mMax.x) || 
    708704                (mMin.y > mMax.y) || 
    709                 (mMin.z > mMax.z) ) 
     705                (mMin.z > mMax.z)) 
     706        { 
    710707                return false; // box is not formed 
    711  
    712         if ( (mMin.x == mMax.x) && 
     708        } 
     709 
     710        if ((mMin.x == mMax.x) && 
    713711                (mMin.y == mMax.y) && 
    714                 (mMin.z == mMax.z) ) 
     712                (mMin.z == mMax.z)) 
     713        { 
    715714                return false; // degenerates to a point 
     715        } 
    716716 
    717717        return true; 
     
    721721bool AxisAlignedBox3::IsPoint() const 
    722722{ 
    723         if ( (mMin.x == mMax.x) && 
     723        if ((mMin.x == mMax.x) && 
    724724                (mMin.y == mMax.y) && 
    725                 (mMin.z == mMax.z) ) 
     725                (mMin.z == mMax.z)) 
     726        { 
    726727                return true; // degenerates to a point 
     728        } 
    727729 
    728730        return false; 
     
    732734bool AxisAlignedBox3::IsSingularOrIncorrect() const 
    733735{ 
    734         if ( (mMin.x >= mMax.x) || 
     736        if ((mMin.x >= mMax.x) || 
    735737                (mMin.y >= mMax.y) || 
    736                 (mMin.z >= mMax.z) ) 
     738                (mMin.z >= mMax.z)) 
     739        { 
    737740                return true; // box is not formed 
     741        } 
    738742 
    739743        return false; // has non-zero volume 
     
    757761 
    758762        // for x-axis 
    759         for (int i = 0; i < 3; i++, minp++, maxp++, pcenter++) { 
     763        for (int i = 0; i < 3; i ++, minp ++, maxp ++, pcenter ++) 
     764        { 
    760765                float minsqr = sqr(*minp - *pcenter); 
    761766                float maxsqr = sqr(*maxp - *pcenter); 
     767 
    762768                if (*pcenter < *minp) 
     769                {                
    763770                        sumMin += minsqr; 
     771                } 
    764772                else 
    765                         if (*pcenter > *maxp) 
    766                                 sumMin += maxsqr; 
     773                { 
     774                        if (*pcenter > *maxp) sumMin += maxsqr; 
     775                } 
     776 
    767777                sumMax += (minsqr > maxsqr) ? minsqr : maxsqr; 
    768778        } 
     
    773783 
    774784 
    775 void AxisAlignedBox3::Scale(const float scale)  
    776 { 
    777         Vector3 newSize = Size()*(scale*0.5f); 
     785void AxisAlignedBox3::Scale(float scale)  
     786{ 
     787        Vector3 newSize = Size() * (scale * 0.5f); 
    778788        Vector3 center = Center(); 
     789 
    779790        mMin = center - newSize; 
    780791        mMax = center + newSize; 
     
    784795void AxisAlignedBox3::Scale(const Vector3 &scale)  
    785796{ 
    786         Vector3 newSize = Size()*(scale*0.5f); 
     797        Vector3 newSize = Size() * (scale * 0.5f); 
    787798        Vector3 center = Center(); 
     799 
    788800        mMin = center - newSize; 
    789801        mMax = center + newSize; 
     
    817829 
    818830 
    819 float AxisAlignedBox3::Center(const int axis) const  
     831float AxisAlignedBox3::Center(int axis) const  
    820832{ 
    821833        return  0.5f * (mMin[axis] + mMax[axis]); 
     
    823835 
    824836 
    825 float AxisAlignedBox3::Min(const int axis) const  
     837float AxisAlignedBox3::Min(int axis) const  
    826838{ 
    827839        return mMin[axis]; 
     
    829841 
    830842 
    831 float AxisAlignedBox3::Max(const int axis) const  
     843float AxisAlignedBox3::Max(int axis) const  
    832844{ 
    833845        return  mMax[axis]; 
     
    835847 
    836848 
    837 float AxisAlignedBox3::Size(const int axis) const  
     849float AxisAlignedBox3::Size(int axis) const  
    838850{ 
    839851        return  Max(axis) - Min(axis); 
     
    937949 
    938950 
    939 void AxisAlignedBox3::SetMin(int axis, const float value)  
     951void AxisAlignedBox3::SetMin(int axis, float value)  
    940952{ 
    941953        mMin[axis] = value; 
     
    943955 
    944956 
    945 void AxisAlignedBox3::SetMax(int axis, const float value)  
     957void AxisAlignedBox3::SetMax(int axis, float value)  
    946958{ 
    947959        mMax[axis] = value; 
     
    952964void AxisAlignedBox3::Reduce(int axis, int right, float value)  
    953965{ 
    954         if ((value >=mMin[axis]) && (value <= mMax[axis])) 
     966        if ((value >= mMin[axis]) && (value <= mMax[axis])) 
    955967        { 
    956968                if (right) 
     
    9911003                if (*si < *ei)  
    9921004                { 
    993                         if (*si > *bmax || *ei < *bmin) 
    994                                 return false; 
     1005                        if (*si > *bmax || *ei < *bmin) return false; 
    9951006 
    9961007                        const float di = *ei - *si; 
     
    10011012                else  
    10021013                { 
    1003                         if (*ei > *bmax || *si < *bmin) 
    1004                                 return false; 
     1014                        if (*ei > *bmax || *si < *bmin) return false; 
    10051015 
    10061016                        const float di = *ei - *si; 
     
    10121022                if (st > fst) fst = st; 
    10131023                if (et < fet) fet = et; 
    1014                 if (fet < fst) 
    1015                         return false; 
     1024                if (fet < fst) return false; 
    10161025 
    10171026                ++ bmin; ++ bmax; 
     
    10191028        } 
    10201029 
    1021         //*time = fst; 
    10221030        return true; 
    10231031} 
     
    11171125        //-- compute classification of vertices 
    11181126 
    1119         for (int i = 0; i < 8; ++i) 
     1127        for (int i = 0; i < 8; ++ i) 
    11201128        { 
    11211129                GetVertex(i, vtx); 
    11221130                side[i] = plane.Side(vtx); 
     1131 
    11231132                if (side[i] > 0) 
    11241133                        onFrontSide = true; 
     
    11351144        { 
    11361145                Vector3 ptA, ptB; 
     1146 
    11371147                for (int i = 0; i < 12; ++ i) 
    11381148                { 
     
    11591169                // compute center of mass 
    11601170                for (i = 0; i < (int)planePoly->mVertices.size(); ++ i) 
     1171                { 
    11611172                        centerOfMass += planePoly->mVertices[i]; 
    1162                  
     1173                } 
     1174 
    11631175                centerOfMass /= (float)planePoly->mVertices.size(); 
    11641176 
     
    11701182                { 
    11711183                    float angle =  
    1172                       Angle(refVec, centerOfMass - planePoly->mVertices[i], plane.mNormal); 
     1184                                Angle(refVec, centerOfMass - planePoly->mVertices[i], plane.mNormal); 
    11731185                     
    11741186                    vertexData.push_back(VertexData(planePoly->mVertices[i], angle)); 
     
    11791191                // update vertices 
    11801192                for (i = 1; i < (int)planePoly->mVertices.size(); ++ i) 
     1193                { 
    11811194                        planePoly->mVertices[i] = vertexData[i - 1].mVertex; 
     1195                } 
    11821196        } 
    11831197        else if (planePoly->mVertices.size() == 3) 
     
    12191233 
    12201234 
    1221 /*int AxisAlignedBox3::Side(const Plane3 &plane) const 
    1222 { 
    1223         Vector3 v; 
    1224         int i, m=3, M=-3, s; 
    1225  
    1226         for (i=0;i<8;i++)  
    1227         { 
    1228                 GetVertex(i, v); 
    1229          
    1230                 if((s = plane.Side(v)) < m) m=s; 
    1231                 if(s > M) M=s; 
    1232                 if (m && m==-M) return 0; 
    1233         } 
    1234  
    1235         return (m == M) ? m : m + M; 
    1236 } 
    1237 */ 
    1238  
    12391235int AxisAlignedBox3::Side(const Plane3 &plane) const 
    12401236{ 
     
    12871283 
    12881284 
    1289  
    1290 bool AxisAlignedBox3::Intersects(const SimpleRay &ray, float &tnear, float &tfar) const 
     1285bool AxisAlignedBox3::Intersects(const SimpleRay &ray, 
     1286                                                                 float &tnear,  
     1287                                                                 float &tfar) const 
    12911288{ 
    12921289        tnear = -1e20f; 
     
    13021299        { 
    13031300                if ((origin.x < mMin.x) || (origin.x > mMax.x))  
     1301                { 
    13041302                        return false; // origin not between planes 
     1303                } 
    13051304        } 
    13061305        else 
     
    13111310                t2 = (mMax.x - origin.x) / dir.x; 
    13121311                 
    1313                 if (t1 > t2) 
    1314                         swap(t1, t2); 
    1315                  
    1316                 if (t1 > tnear) 
    1317                         tnear = t1; 
    1318                  
    1319                 if (t2 < tfar) 
    1320                         tfar = t2; 
    1321                  
    1322                 if (tnear > tfar) 
    1323                         return false; 
    1324                  
    1325                 if (tfar < 0) 
    1326                         return false; 
     1312                if (t1 > t2) swap(t1, t2); 
     1313                if (t1 > tnear) tnear = t1; 
     1314                if (t2 < tfar) tfar = t2; 
     1315                if (tnear > tfar) return false; 
     1316                if (tfar < 0) return false; 
    13271317        } 
    13281318 
    13291319        if (dir.y == 0) // ray is parallel to the planes 
    13301320        { 
    1331                 if ((origin.y < mMin.y) || (origin.y > mMax.y))  
     1321                if ((origin.y < mMin.y) || (origin.y > mMax.y)) 
     1322                { 
    13321323                        return false; // origin not between planes) 
     1324                } 
    13331325        } 
    13341326        else 
     
    13371329                t2 = (mMax.y - origin.y) / dir.y;  
    13381330                 
    1339                 if (t1 > t2) 
    1340                         swap(t1, t2); 
    1341                  
    1342                 if (t1 > tnear) 
    1343                         tnear = t1; 
    1344                  
    1345                 if (t2 < tfar) 
    1346                         tfar = t2; 
    1347                  
    1348                 if (tnear > tfar) 
    1349                         return false; 
    1350                  
    1351                 if (tfar < 0) 
    1352                         return false; 
     1331                if (t1 > t2) swap(t1, t2); 
     1332                if (t1 > tnear) tnear = t1; 
     1333                if (t2 < tfar) tfar = t2; 
     1334                if (tnear > tfar) return false; 
     1335                if (tfar < 0) return false; 
    13531336        } 
    13541337 
    13551338        if (dir.z == 0) // ray is parallel to the planes 
    13561339        { 
    1357                 if ((origin.z < mMin.z) || (origin.z > mMax.z))  
     1340                if ((origin.z < mMin.z) || (origin.z > mMax.z)) 
     1341                { 
    13581342                        return false; // origin not between planes) 
     1343                } 
    13591344        } 
    13601345        else 
     
    13631348                t2 = (mMax.z - origin.z) / dir.z;  
    13641349                 
    1365                 if (t1 > t2) 
    1366                         swap(t1, t2); 
    1367                  
    1368                 if (t1 > tnear) 
    1369                         tnear = t1; 
    1370                  
    1371                 if (t2 < tfar) 
    1372                         tfar = t2; 
    1373                  
    1374                 if (tnear > tfar) 
    1375                         return false; 
    1376                  
    1377                 if (tfar < 0) 
    1378                         return false; 
     1350                if (t1 > t2) swap(t1, t2); 
     1351                if (t1 > tnear) tnear = t1; 
     1352                if (t2 < tfar) tfar = t2; 
     1353                if (tnear > tfar) return false; 
     1354                if (tfar < 0) return false; 
    13791355        } 
    13801356 
  • 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); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3316 r3318  
    635635#if 1 
    636636 
    637 #if 0 
     637#if 1 
     638        // vienna positions 
    638639        VertexArray positions; 
    639640        positions.push_back(Vector3(478.398f, 268.0f, 181.3)); 
     
    644645#else 
    645646 
     647        // sibenik positions 
    646648        VertexArray positions; 
    647649        //positions.push_back(Vector3(6.07307, 8.20723, 6.7)); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3315 r3318  
    88//#define NUM_SAMPLES 8 
    99//#define NUM_SAMPLES 16 
    10 //#define NUM_SAMPLES 24 
    11 #define NUM_SAMPLES 48 
     10#define NUM_SAMPLES 24 
     11//#define NUM_SAMPLES 48 
    1212 
    1313//#define MIN_SAMPLES 48 
     
    6161#define NUM_DOF_TABS 16 
    6262 
    63 #define USE_GTX 
     63//#define USE_GTX 
    6464 
    6565#define SSAO_FILTER_RADIUS 5 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3305 r3318  
    161161        if (col.w < DEPTH_THRESHOLD) 
    162162        { 
     163        { 
    163164                OUT.illum_col.xyz = col.xyz * max(2e-2f, 1.0f - ao.x); 
    164165                //OUT.illum_col.xyz = col.xyz * ao.x; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg

    r3317 r3318  
    232232        if (depth < DEPTH_THRESHOLD) 
    233233        { 
    234                 OUT.illum_col.xyz = col.xyz * max(1e-3f, 1.0f - ao.x); 
    235                 //OUT.illum_col.xyz = max(1e-3f, 1.0f - ao.x); 
     234                //OUT.illum_col.xyz = col.xyz * max(1e-3f, 1.0f - ao.x); 
     235                OUT.illum_col.xyz = max(1e-3f, 1.0f - ao.x); 
    236236        } 
    237237        else 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3316 r3318  
    4343 
    4444 
     45float ComputeConvergence(uniform sampler2D tex, float2 texCoord, float2 res) 
     46{ 
     47        // get the minimum convergence by exactly sampling the 4 surrounding 
     48        // texels in the old texture, otherwise flickering because convergence 
     49        // will be interpolated when upsampling and filter size does not match! 
     50 
     51        float4 texelCenterConv; 
     52        const float2 offs(1.0f / res.x, 1.0f / res.y); 
     53 
     54        // get position exactly between texel centers 
     55        float2 center = (floor(texCoord * res) + float2(.5f)) * offs; 
     56        //center.x = (floor(texCoord.x * res.x - .5f) + 1.0f) / res.x; 
     57        //center.y = (floor(texCoord.y * res.y - .5f) + 1.0f) / res.y; 
     58        //center.y = (floor(texCoord.y * res.y) + .5f) * yOffs; 
     59 
     60        /*texelCenterConv.x = tex2Dlod(tex, float4(center + float2( xoffs,  yoffs), 0, 0)).y; 
     61        texelCenterConv.y = tex2Dlod(tex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 
     62        texelCenterConv.z = tex2Dlod(tex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 
     63        texelCenterConv.w = tex2Dlod(tex, float4(center + float2(-xoffs,  yoffs), 0, 0)).y; 
     64 
     65        const float m1 = min(texelCenterConv.x, texelCenterConv.y); 
     66        const float m2 = min(texelCenterConv.z, texelCenterConv.w); 
     67 
     68        const float convergence = min(m1, m2);*/ 
     69 
     70        const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y; 
     71 
     72        return convergence; 
     73} 
    4574 
    4675/** This shader computes the reprojection and stores  
     
    107136        { 
    108137                // pixel valid => retrieve the convergence weight 
    109                 float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 
     138                /*float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 
    110139                float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 
    111140                float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y; 
    112141                float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y; 
    113142 
    114                 w = min(min(w1, w2), min(w3, w4)); 
     143                w = min(min(w1, w2), min(w3, w4));*/ 
     144                 
     145                w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f)); 
    115146                //w = oldPixel.y; 
    116147        } 
Note: See TracChangeset for help on using the changeset viewer.