Changeset 3318
- Timestamp:
- 02/18/09 08:01:56 (16 years ago)
- 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 29 29 { 30 30 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 << ']'; 32 32 } 33 33 … … 39 39 // read "[min.x, min.y, min.z][mMax.x, mMax.y, mMax.z]" 40 40 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; 42 42 } 43 43 44 44 45 45 AxisAlignedBox3::AxisAlignedBox3() 46 { } 47 48 49 AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax) 46 {} 47 48 49 AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin, 50 const Vector3 &nMax) 50 51 : mMin(nMin), mMax(nMax) 51 52 {} … … 72 73 73 74 for (it = newpoly.mVertices.begin(); it != it_end; ++ it) 75 { 74 76 Include(*it); 77 } 75 78 } 76 79 … … 81 84 82 85 for (it = polys.begin(); it != it_end; ++ it) 86 { 83 87 Include(*(*it)); 88 } 84 89 } 85 90 … … 94 99 bool AxisAlignedBox3::IsCorrect() 95 100 { 96 if ( 101 if ((mMin.x > mMax.x) || 97 102 (mMin.y > mMax.y) || 98 103 (mMin.z > mMax.z) ) 104 { 99 105 return false; // box is not formed 106 } 107 100 108 return true; 101 109 } 102 110 103 111 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; 112 void 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; 156 167 } 157 168 } … … 159 170 // returns the vertex indices in the range <0..7>, v = 4.x + 2.y + z, where 160 171 // 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 } 172 void 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 192 void 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 } 205 214 } 206 215 } … … 213 222 } 214 223 215 int 216 AxisAlignedBox3::IsInside(const Vector3 &v) const224 225 int AxisAlignedBox3::IsInside(const Vector3 &v) const 217 226 { 218 227 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)); 224 233 } 225 234 … … 228 237 { 229 238 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); 235 244 } 236 245 237 246 238 247 // compute the coordinates of one vertex of the box 239 Vector3 AxisAlignedBox3::GetVertex(int xAxis, int yAxis, int zAxis) const 248 Vector3 AxisAlignedBox3::GetVertex(int xAxis, 249 int yAxis, 250 int zAxis) const 240 251 { 241 252 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 256 258 return p; 257 259 } … … 304 306 { 305 307 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); 310 309 } 311 310 … … 318 317 319 318 const int AxisAlignedBox3::bvertices[27][9] = 320 { // region number.. position319 { // region number .. position 321 320 {5,1,3,2,6,4,-1,-1,-1}, // 0 .. x=0 y=0 z=0 322 321 {4,5,1,3,2,0,-1,-1,-1}, // 1 .. x=0 y=0 z=1 … … 361 360 // one to three triples: (axis, min_vertex, max_vertex), axis==-1(terminator) 362 361 const int AxisAlignedBox3::bfaces[27][10] = 363 { // region number .. position362 { // region number .. position 364 363 {0,0,3,1,0,5,2,0,6,-1}, // 0 .. x=0 y=0 z=0 365 364 {0,0,3,1,0,5,-1,-1,-1,-1}, // 1 .. x=0 y=0 z=1 … … 473 472 // The sequence is ended by 15, number -1 is used as the separator 474 473 // between the vertices and coordinates. 475 const int 476 AxisAlignedBox3::cvertices[27][9] = 477 { // region number.. position 474 const int AxisAlignedBox3::cvertices[27][9] = 475 { // region number.. position 478 476 {0,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D one vertex 479 477 {0,1,-1,0,0,0,1,15,15}, // 1 .. x=0 y=0 z=1 D two vertices foll. by 2 … … 536 534 // the sequence start with 15 .. no further testing is necessary 537 535 // in this case 538 const int 539 AxisAlignedBox3::csvertices[27][6] = 540 { // region number.. position 536 const int AxisAlignedBox3::csvertices[27][6] = 537 { // region number.. position 541 538 {0,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D vertex only 542 539 {8,0,0,0,1,15}, // 1 .. x=0 y=0 z=1 D two coords. … … 586 583 // For testing, if the AABB is whole in the sphere, it is enough 587 584 // to test only vertices, either 1,2,4, or 8. 588 const int 589 AxisAlignedBox3::fvertices[27][9] = 590 { // region number.. position 585 const int AxisAlignedBox3::fvertices[27][9] = 586 { // region number.. position 591 587 {7,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D 592 588 {6,7,15,15,15,15,15,15,15}, // 1 .. x=0 y=0 z=1 D … … 635 631 // The number of vertices is minimized using some assumptions 636 632 // about the ortogonality of vertices and sphere properties. 637 const int 638 AxisAlignedBox3::fsvertices[27][9] = 639 { // region number.. position 633 const int AxisAlignedBox3::fsvertices[27][9] = 634 { // region number.. position 640 635 {7,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D 1 vertex 641 636 {6,7,15,15,15,15,15,15,15}, // 1 .. x=0 y=0 z=1 D 2 vertices … … 686 681 const float c = (float)(M_PI * 0.25); 687 682 688 if (y < 0.0) { 683 if (y < 0.0) 684 { 689 685 if (y < -1.0) 690 686 return c * (-2.0f + x / y); // for angle in <-PI/2, -PI/4) … … 692 688 return c * (y / x); // for angle in <-PI/4 , 0> 693 689 } 694 else { 690 else 691 { 695 692 if (y > 1.0) 696 693 return c * (2.0f - x / y); // for angle in <PI/4, PI/2> … … 702 699 703 700 // This definition allows to be a point when answering true 704 bool 705 AxisAlignedBox3::IsCorrectAndNotPoint() const 706 { 707 if ( (mMin.x > mMax.x) || 701 bool AxisAlignedBox3::IsCorrectAndNotPoint() const 702 { 703 if ((mMin.x > mMax.x) || 708 704 (mMin.y > mMax.y) || 709 (mMin.z > mMax.z) ) 705 (mMin.z > mMax.z)) 706 { 710 707 return false; // box is not formed 711 712 if ( (mMin.x == mMax.x) && 708 } 709 710 if ((mMin.x == mMax.x) && 713 711 (mMin.y == mMax.y) && 714 (mMin.z == mMax.z) ) 712 (mMin.z == mMax.z)) 713 { 715 714 return false; // degenerates to a point 715 } 716 716 717 717 return true; … … 721 721 bool AxisAlignedBox3::IsPoint() const 722 722 { 723 if ( 723 if ((mMin.x == mMax.x) && 724 724 (mMin.y == mMax.y) && 725 (mMin.z == mMax.z) ) 725 (mMin.z == mMax.z)) 726 { 726 727 return true; // degenerates to a point 728 } 727 729 728 730 return false; … … 732 734 bool AxisAlignedBox3::IsSingularOrIncorrect() const 733 735 { 734 if ( 736 if ((mMin.x >= mMax.x) || 735 737 (mMin.y >= mMax.y) || 736 (mMin.z >= mMax.z) ) 738 (mMin.z >= mMax.z)) 739 { 737 740 return true; // box is not formed 741 } 738 742 739 743 return false; // has non-zero volume … … 757 761 758 762 // 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 { 760 765 float minsqr = sqr(*minp - *pcenter); 761 766 float maxsqr = sqr(*maxp - *pcenter); 767 762 768 if (*pcenter < *minp) 769 { 763 770 sumMin += minsqr; 771 } 764 772 else 765 if (*pcenter > *maxp) 766 sumMin += maxsqr; 773 { 774 if (*pcenter > *maxp) sumMin += maxsqr; 775 } 776 767 777 sumMax += (minsqr > maxsqr) ? minsqr : maxsqr; 768 778 } … … 773 783 774 784 775 void AxisAlignedBox3::Scale( constfloat scale)776 { 777 Vector3 newSize = Size() *(scale*0.5f);785 void AxisAlignedBox3::Scale(float scale) 786 { 787 Vector3 newSize = Size() * (scale * 0.5f); 778 788 Vector3 center = Center(); 789 779 790 mMin = center - newSize; 780 791 mMax = center + newSize; … … 784 795 void AxisAlignedBox3::Scale(const Vector3 &scale) 785 796 { 786 Vector3 newSize = Size() *(scale*0.5f);797 Vector3 newSize = Size() * (scale * 0.5f); 787 798 Vector3 center = Center(); 799 788 800 mMin = center - newSize; 789 801 mMax = center + newSize; … … 817 829 818 830 819 float AxisAlignedBox3::Center( constint axis) const831 float AxisAlignedBox3::Center(int axis) const 820 832 { 821 833 return 0.5f * (mMin[axis] + mMax[axis]); … … 823 835 824 836 825 float AxisAlignedBox3::Min( constint axis) const837 float AxisAlignedBox3::Min(int axis) const 826 838 { 827 839 return mMin[axis]; … … 829 841 830 842 831 float AxisAlignedBox3::Max( constint axis) const843 float AxisAlignedBox3::Max(int axis) const 832 844 { 833 845 return mMax[axis]; … … 835 847 836 848 837 float AxisAlignedBox3::Size( constint axis) const849 float AxisAlignedBox3::Size(int axis) const 838 850 { 839 851 return Max(axis) - Min(axis); … … 937 949 938 950 939 void AxisAlignedBox3::SetMin(int axis, constfloat value)951 void AxisAlignedBox3::SetMin(int axis, float value) 940 952 { 941 953 mMin[axis] = value; … … 943 955 944 956 945 void AxisAlignedBox3::SetMax(int axis, constfloat value)957 void AxisAlignedBox3::SetMax(int axis, float value) 946 958 { 947 959 mMax[axis] = value; … … 952 964 void AxisAlignedBox3::Reduce(int axis, int right, float value) 953 965 { 954 if ((value >= mMin[axis]) && (value <= mMax[axis]))966 if ((value >= mMin[axis]) && (value <= mMax[axis])) 955 967 { 956 968 if (right) … … 991 1003 if (*si < *ei) 992 1004 { 993 if (*si > *bmax || *ei < *bmin) 994 return false; 1005 if (*si > *bmax || *ei < *bmin) return false; 995 1006 996 1007 const float di = *ei - *si; … … 1001 1012 else 1002 1013 { 1003 if (*ei > *bmax || *si < *bmin) 1004 return false; 1014 if (*ei > *bmax || *si < *bmin) return false; 1005 1015 1006 1016 const float di = *ei - *si; … … 1012 1022 if (st > fst) fst = st; 1013 1023 if (et < fet) fet = et; 1014 if (fet < fst) 1015 return false; 1024 if (fet < fst) return false; 1016 1025 1017 1026 ++ bmin; ++ bmax; … … 1019 1028 } 1020 1029 1021 //*time = fst;1022 1030 return true; 1023 1031 } … … 1117 1125 //-- compute classification of vertices 1118 1126 1119 for (int i = 0; i < 8; ++ i)1127 for (int i = 0; i < 8; ++ i) 1120 1128 { 1121 1129 GetVertex(i, vtx); 1122 1130 side[i] = plane.Side(vtx); 1131 1123 1132 if (side[i] > 0) 1124 1133 onFrontSide = true; … … 1135 1144 { 1136 1145 Vector3 ptA, ptB; 1146 1137 1147 for (int i = 0; i < 12; ++ i) 1138 1148 { … … 1159 1169 // compute center of mass 1160 1170 for (i = 0; i < (int)planePoly->mVertices.size(); ++ i) 1171 { 1161 1172 centerOfMass += planePoly->mVertices[i]; 1162 1173 } 1174 1163 1175 centerOfMass /= (float)planePoly->mVertices.size(); 1164 1176 … … 1170 1182 { 1171 1183 float angle = 1172 1184 Angle(refVec, centerOfMass - planePoly->mVertices[i], plane.mNormal); 1173 1185 1174 1186 vertexData.push_back(VertexData(planePoly->mVertices[i], angle)); … … 1179 1191 // update vertices 1180 1192 for (i = 1; i < (int)planePoly->mVertices.size(); ++ i) 1193 { 1181 1194 planePoly->mVertices[i] = vertexData[i - 1].mVertex; 1195 } 1182 1196 } 1183 1197 else if (planePoly->mVertices.size() == 3) … … 1219 1233 1220 1234 1221 /*int AxisAlignedBox3::Side(const Plane3 &plane) const1222 {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 1239 1235 int AxisAlignedBox3::Side(const Plane3 &plane) const 1240 1236 { … … 1287 1283 1288 1284 1289 1290 bool AxisAlignedBox3::Intersects(const SimpleRay &ray, float &tnear, float &tfar) const 1285 bool AxisAlignedBox3::Intersects(const SimpleRay &ray, 1286 float &tnear, 1287 float &tfar) const 1291 1288 { 1292 1289 tnear = -1e20f; … … 1302 1299 { 1303 1300 if ((origin.x < mMin.x) || (origin.x > mMax.x)) 1301 { 1304 1302 return false; // origin not between planes 1303 } 1305 1304 } 1306 1305 else … … 1311 1310 t2 = (mMax.x - origin.x) / dir.x; 1312 1311 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; 1327 1317 } 1328 1318 1329 1319 if (dir.y == 0) // ray is parallel to the planes 1330 1320 { 1331 if ((origin.y < mMin.y) || (origin.y > mMax.y)) 1321 if ((origin.y < mMin.y) || (origin.y > mMax.y)) 1322 { 1332 1323 return false; // origin not between planes) 1324 } 1333 1325 } 1334 1326 else … … 1337 1329 t2 = (mMax.y - origin.y) / dir.y; 1338 1330 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; 1353 1336 } 1354 1337 1355 1338 if (dir.z == 0) // ray is parallel to the planes 1356 1339 { 1357 if ((origin.z < mMin.z) || (origin.z > mMax.z)) 1340 if ((origin.z < mMin.z) || (origin.z > mMax.z)) 1341 { 1358 1342 return false; // origin not between planes) 1343 } 1359 1344 } 1360 1345 else … … 1363 1348 t2 = (mMax.z - origin.z) / dir.z; 1364 1349 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; 1379 1355 } 1380 1356 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r3243 r3318 25 25 SimpleRay(const Vector3 &o, const Vector3 &d): mOrigin(o), mDirection(d) {} 26 26 27 Vector3 Extrap( constfloat t) const27 Vector3 Extrap(float t) const 28 28 { 29 29 return mOrigin + mDirection * t; … … 41 41 /** Axis alignedd box class. 42 42 This is a box in 3-space, defined by min and max 43 corner vectors. 43 corner vectors. Many useful operations are defined. 44 44 */ 45 45 class AxisAlignedBox3 … … 70 70 /** Computes the mid point in the given axis. 71 71 */ 72 float Center( constint axis) const;72 float Center(int axis) const; 73 73 /** The vertex of the box with the smallest values in all dimensions. 74 74 */ 75 float Min( constint axis) const;75 float Min(int axis) const; 76 76 /** The vertex of the box with the largest values in all dimensions. 77 77 */ 78 float Max( constint axis) const;78 float Max(int axis) const; 79 79 /** The extent of the box in the given axis. 80 80 */ 81 float Size( constint axis) const;81 float Size(int axis) const; 82 82 /** Returns axis where box has largest extent. 83 83 */ … … 138 138 /** Expand the axis-aligned box to include given values in particular axis. 139 139 */ 140 void Include( const int &axis, const float &newBound);140 void Include(int axis, float newBound); 141 141 /** Includes returns true if a includes b (completely) 142 142 */ … … 243 243 /** Returns the supporting plane of this face. 244 244 */ 245 Plane3 GetPlane( constint face) const;245 Plane3 GetPlane(int face) const; 246 246 /** Returns 247 247 0 if box intersects plane … … 358 358 359 359 360 // -------------------------------------------------------------------------- 361 // Implementation of inline (member) functions 360 361 ///////////////////////////////////////////////////////// 362 //-- Implementation of inline (member) functions 363 362 364 363 365 inline float AxisAlignedBox3::Radius() const … … 373 375 374 376 375 inline bool 376 Overlap(const AxisAlignedBox3 &x,const AxisAlignedBox3 &y)377 inline bool Overlap(const AxisAlignedBox3 &x, 378 const AxisAlignedBox3 &y) 377 379 { 378 380 if (x.mMax.x < y.mMin.x || … … 381 383 x.mMin.y > y.mMax.y || 382 384 x.mMax.z < y.mMin.z || 383 x.mMin.z > y.mMax.z) { 385 x.mMin.z > y.mMax.z) 386 { 384 387 return false; 385 388 } 389 386 390 return true; 387 391 } 388 392 389 inline bool 390 OverlapS(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 393 394 inline bool OverlapS(const AxisAlignedBox3 &x, 395 const AxisAlignedBox3 &y) 391 396 { 392 397 if (x.mMax.x <= y.mMin.x || … … 395 400 x.mMin.y >= y.mMax.y || 396 401 x.mMax.z <= y.mMin.z || 397 x.mMin.z >= y.mMax.z) { 402 x.mMin.z >= y.mMax.z) 403 { 398 404 return false; 399 405 } 406 400 407 return true; 401 408 } 402 409 403 inline bool 404 Overlap(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y, float eps) 405 { 406 if ( (x.mMax.x - eps) < y.mMin.x || 410 411 inline bool Overlap(const AxisAlignedBox3 &x, 412 const AxisAlignedBox3 &y, 413 float eps) 414 { 415 if ((x.mMax.x - eps) < y.mMin.x || 407 416 (x.mMin.x + eps) > y.mMax.x || 408 417 (x.mMax.y - eps) < y.mMin.y || 409 418 (x.mMin.y + eps) > y.mMax.y || 410 419 (x.mMax.z - eps) < y.mMin.z || 411 (x.mMin.z + eps) > y.mMax.z ) { 420 (x.mMin.z + eps) > y.mMax.z ) 421 { 412 422 return false; 413 423 } 424 414 425 return true; 415 426 } 416 427 417 inline AxisAlignedBox3 418 Intersect(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 419 { 420 if (x.Unbounded()) 428 429 inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x, 430 const AxisAlignedBox3 &y) 431 { 432 if (x.Unbounded()) 433 { 421 434 return y; 435 } 422 436 else 423 if (y.Unbounded()) 424 return x; 437 { 438 if (y.Unbounded()) return x; 439 } 440 425 441 AxisAlignedBox3 ret = x; 426 if (Overlap(ret, y)) { 442 443 if (Overlap(ret, y)) 444 { 427 445 Maximize(ret.mMin, y.mMin); 428 446 Minimize(ret.mMax, y.mMax); 447 429 448 return ret; 430 449 } 431 else // Null intersection. 450 else // Null intersection 451 { 432 452 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 457 inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x, 458 const AxisAlignedBox3 &y) 438 459 { 439 460 Vector3 min = x.mMin; 440 461 Vector3 max = x.mMax; 462 441 463 Minimize(min, y.mMin); 442 464 Maximize(max, y.mMax); 465 443 466 return AxisAlignedBox3(min, max); 444 467 } 445 468 446 inline AxisAlignedBox3 447 Transform(const AxisAlignedBox3 &box, const Matrix4x4 &tform) 448 { 449 Vector3 mmin(MAXFLOAT); 450 Vector3 mmax(-MAXFLOAT); 469 470 inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box, 471 const Matrix4x4 &tform) 472 { 473 const Vector3 mmin(MAXFLOAT); 474 const Vector3 mmax(-MAXFLOAT); 451 475 452 476 AxisAlignedBox3 ret(mmin, mmax); … … 464 488 } 465 489 466 inline float RatioOfOverlap(const AxisAlignedBox3 &box1, const AxisAlignedBox3 &box2) 490 491 inline float RatioOfOverlap(const AxisAlignedBox3 &box1, 492 const AxisAlignedBox3 &box2) 467 493 { 468 494 // return ratio of intersection to union … … 473 499 } 474 500 475 inline int operator==(const AxisAlignedBox3 &A, const AxisAlignedBox3 &B) 501 502 inline int operator==(const AxisAlignedBox3 &A, 503 const AxisAlignedBox3 &B) 476 504 { 477 505 return (A.mMin == B.mMin) && (A.mMax == B.mMax); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3316 r3318 635 635 #if 1 636 636 637 #if 0 637 #if 1 638 // vienna positions 638 639 VertexArray positions; 639 640 positions.push_back(Vector3(478.398f, 268.0f, 181.3)); … … 644 645 #else 645 646 647 // sibenik positions 646 648 VertexArray positions; 647 649 //positions.push_back(Vector3(6.07307, 8.20723, 6.7)); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3315 r3318 8 8 //#define NUM_SAMPLES 8 9 9 //#define NUM_SAMPLES 16 10 //#define NUM_SAMPLES 2411 #define NUM_SAMPLES 4810 #define NUM_SAMPLES 24 11 //#define NUM_SAMPLES 48 12 12 13 13 //#define MIN_SAMPLES 48 … … 61 61 #define NUM_DOF_TABS 16 62 62 63 #define USE_GTX63 //#define USE_GTX 64 64 65 65 #define SSAO_FILTER_RADIUS 5 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3305 r3318 161 161 if (col.w < DEPTH_THRESHOLD) 162 162 { 163 { 163 164 OUT.illum_col.xyz = col.xyz * max(2e-2f, 1.0f - ao.x); 164 165 //OUT.illum_col.xyz = col.xyz * ao.x; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
r3317 r3318 232 232 if (depth < DEPTH_THRESHOLD) 233 233 { 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); 236 236 } 237 237 else -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3316 r3318 43 43 44 44 45 float 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 } 45 74 46 75 /** This shader computes the reprojection and stores … … 107 136 { 108 137 // 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; 110 139 float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 111 140 float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y; 112 141 float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y; 113 142 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)); 115 146 //w = oldPixel.y; 116 147 }
Note: See TracChangeset
for help on using the changeset viewer.