Changeset 2913
- Timestamp:
- 09/08/08 00:52:31 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp
r2911 r2913 1153 1153 1154 1154 1155 Plane3 AxisAlignedBox3::GetPlane( constint face) const1155 Plane3 AxisAlignedBox3::GetPlane(int face) const 1156 1156 { 1157 1157 switch (face) 1158 1158 { 1159 1160 1159 case 0: 1160 return Plane3(Vector3(0, -1, 0), mMin); 1161 case 1: 1162 return Plane3(Vector3(0, 1, 0), mMax); 1163 case 2: 1161 1164 return Plane3(Vector3(-1, 0, 0), mMin); 1162 case 1:1165 case 3: 1163 1166 return Plane3(Vector3(1, 0, 0), mMax); 1164 case 2:1165 return Plane3(Vector3(0, -1, 0), mMin);1166 case 3:1167 return Plane3(Vector3(0, 1, 0), mMax);1168 1167 case 4: 1169 1168 return Plane3(Vector3(0, 0, -1), mMin); … … 1176 1175 } 1177 1176 1177 1178 /*int AxisAlignedBox3::Side(const Plane3 &plane) const 1179 { 1180 Vector3 v; 1181 int i, m=3, M=-3, s; 1182 1183 for (i=0;i<8;i++) 1184 { 1185 GetVertex(i, v); 1186 1187 if((s = plane.Side(v)) < m) m=s; 1188 if(s > M) M=s; 1189 if (m && m==-M) return 0; 1190 } 1191 1192 return (m == M) ? m : m + M; 1193 } 1194 */ 1178 1195 1179 1196 int AxisAlignedBox3::Side(const Plane3 &plane) const … … 1203 1220 1204 1221 1205 Polyhedron *AxisAlignedBox3::CalcIntersection(Polyhedron *polyhedron) const 1206 { 1207 Polyhedron *oldPolyhedron = new Polyhedron(*polyhedron); 1208 1222 Polyhedron *AxisAlignedBox3::CalcIntersection(const Polyhedron &polyhedron) const 1223 { 1224 Polyhedron *oldPolyhedron = new Polyhedron(polyhedron); 1225 1226 if (!oldPolyhedron->Valid()) cerr << "******************* not valid!! ************* " << endl; 1227 1209 1228 Polyhedron *newPolyhedron = NULL; 1210 1229 1211 1230 for (int i = 0; i < 6; ++ i) 1212 1231 { 1213 Polyhedron *newPolyhedron = oldPolyhedron->CalcIntersection(GetPlane(i)); 1232 newPolyhedron = oldPolyhedron->CalcIntersection(GetPlane(i)); 1233 1234 if (!newPolyhedron || !newPolyhedron->Valid()) 1235 { 1236 DEL_PTR(newPolyhedron); 1237 cerr << "polyhedron not valid or NULL!" << endl; 1238 1239 return NULL; 1240 } 1241 1214 1242 DEL_PTR(oldPolyhedron); 1215 1216 if (!newPolyhedron) 1217 return NULL; 1243 oldPolyhedron = newPolyhedron; 1218 1244 } 1219 1245 … … 1222 1248 1223 1249 1224 } 1225 1250 1251 bool AxisAlignedBox3::Intersects(const SimpleRay &ray, float &tnear, float &tfar) const 1252 { 1253 tnear = -1e20f; 1254 tfar = 1e20f; 1255 1256 const Vector3 origin = ray.mOrigin; 1257 const Vector3 dir = ray.mDirection; 1258 1259 float t1, t2; 1260 1261 // ray is parallel to the planes 1262 if (dir.x == 0) 1263 { 1264 if ((origin.x < mMin.x) || (origin.x > mMax.x)) 1265 return false; // origin not between planes 1266 } 1267 else 1268 { 1269 // time at which ray intersects minimum X plane 1270 t1 = (mMin.x - origin.x) / dir.x; 1271 // time at which ray intersects maximum X plane 1272 t2 = (mMax.x - origin.x) / dir.x; 1273 1274 if (t1 > t2) 1275 swap(t1, t2); 1276 1277 if (t1 > tnear) 1278 tnear = t1; 1279 1280 if (t2 < tfar) 1281 tfar = t2; 1282 1283 if (tnear > tfar) 1284 return false; 1285 1286 if (tfar < 0) 1287 return false; 1288 } 1289 1290 if (dir.y == 0) // ray is parallel to the planes 1291 { 1292 if ((origin.y < mMin.y) || (origin.y > mMax.y)) 1293 return false; // origin not between planes) 1294 } 1295 else 1296 { 1297 t1 = (mMin.y - origin.y) / dir.y; 1298 t2 = (mMax.y - origin.y) / dir.y; 1299 1300 if (t1 > t2) 1301 swap(t1, t2); 1302 1303 if (t1 > tnear) 1304 tnear = t1; 1305 1306 if (t2 < tfar) 1307 tfar = t2; 1308 1309 if (tnear > tfar) 1310 return false; 1311 1312 if (tfar < 0) 1313 return false; 1314 } 1315 1316 if (dir.z == 0) // ray is parallel to the planes 1317 { 1318 if ((origin.z < mMin.z) || (origin.z > mMax.z)) 1319 return false; // origin not between planes) 1320 } 1321 else 1322 { 1323 t1 = (mMin.z - origin.z) / dir.z; 1324 t2 = (mMax.z - origin.z) / dir.z; 1325 1326 if (t1 > t2) 1327 swap(t1, t2); 1328 1329 if (t1 > tnear) 1330 tnear = t1; 1331 1332 if (t2 < tfar) 1333 tfar = t2; 1334 1335 if (tnear > tfar) 1336 return false; 1337 1338 if (tfar < 0) 1339 return false; 1340 } 1341 1342 return true; 1343 } 1344 1345 1346 } 1347 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r2911 r2913 6 6 #include "Vector3.h" 7 7 #include "common.h" 8 #9 8 10 9 … … 16 15 class Polygon3; 17 16 class Polyhedron; 17 18 19 struct SimpleRay 20 { 21 SimpleRay() {} 22 23 SimpleRay(const Vector3 &o, const Vector3 &d): mOrigin(o), mDirection(d) {} 24 25 Vector3 mOrigin; 26 Vector3 mDirection; 27 28 Vector3 Extrap(const float t) const 29 { 30 return mOrigin + mDirection * t; 31 } 32 }; 18 33 19 34 … … 178 193 /** Returns cross section of the plane as a polygon. 179 194 */ 180 Polygon3 * AxisAlignedBox3::CrossSection(const Plane3 &plane) const;195 Polygon3 *CrossSection(const Plane3 &plane) const; 181 196 /** Returns the supporting plane of this face. 182 197 */ 183 Plane3 AxisAlignedBox3::GetPlane(const int face) const;198 Plane3 GetPlane(const int face) const; 184 199 /** Returns 185 200 0 if box intersects plane … … 190 205 /** Calculates the intersection of the polyhedron with the box. 191 206 */ 192 Polyhedron *CalcIntersection(Polyhedron *polyhedron) const; 193 207 Polyhedron *CalcIntersection(const Polyhedron &polyhedron) const; 208 209 210 bool Intersects(const SimpleRay &ray, float &tnear, float &tfar) const; 194 211 195 212 //////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2911 r2913 151 151 float fov = mFovy; 152 152 153 const float aspectRatio = GetAspect(); 154 153 155 const float w_near = 2.0f * tan(fov * 0.5f) * z_near; 154 const float h_near = w_near / GetAspect();156 const float h_near = w_near / aspectRatio; 155 157 156 158 const float w_far = 2.0f * tan(fov * 0.5f) * z_far; 157 const float h_far = w_far / GetAspect();159 const float h_far = w_far / aspectRatio; 158 160 159 161 const Vector3 fc = pos + view * z_far; … … 196 198 } 197 199 198 199 Polyhedron *Camera::CalcClippedFrustum(const AxisAlignedBox3 &box) const200 {201 Vector3 ftl, ftr, fbl, fbr;202 Vector3 ntl, ntr, nbl, nbr;203 204 VertexArray sides[6];205 206 ComputeBasePoints(ftl, ftr, fbl, fbr,ntl, ntr, nbl, nbr);207 //ComputePoints(ftl, ftr, fbl, fbr,ntl, ntr, nbl, nbr);208 209 for (int i = 0; i < 6; i ++)210 sides[i].resize(4);211 212 // left, right213 sides[0][0] = ntl; sides[0][1] = ftl; sides[0][2] = fbl; sides[0][3] = nbl;214 sides[1][0] = ntr; sides[1][1] = ftr; sides[1][2] = fbr; sides[1][3] = nbr;215 // bottom, top216 sides[2][0] = ntl; sides[2][1] = ftl; sides[2][2] = ftr; sides[2][3] = ntr;217 sides[3][0] = nbl; sides[3][1] = fbl; sides[3][2] = fbr; sides[3][3] = nbr;218 // near, far219 sides[4][0] = ntl; sides[4][1] = ntr; sides[4][2] = nbr; sides[4][3] = nbl;220 sides[5][0] = ntl; sides[5][1] = ntr; sides[5][2] = nbr; sides[5][3] = nbl;221 222 223 //////////224 //-- compute polyhedron225 226 PolygonContainer polygons;227 228 for (int i = 0; i < 6; ++ i)229 {230 Polygon3 *poly = new Polygon3(sides[i]);231 polygons.push_back(poly);232 }233 234 Polyhedron *p = new Polyhedron(polygons);235 236 //Polyhedron *clippedPolyhedron = box.CalcIntersection(po);237 //DEL_PTR(p);238 239 //return clippedPolyhedron;240 return p;241 }242 200 243 201 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r2911 r2913 109 109 void SetDirection(const Vector3 &direction); 110 110 111 /** Calculates the intersection of the frustum with the box,112 returns resultin polyhedron as array of polygons.113 */114 Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;115 116 117 111 protected: 118 112 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r2782 r2913 3 3 4 4 // standard headers 5 #include "AxisAlignedBox3.h" 5 6 #include <iomanip> 7 6 8 using namespace std; 7 9 … … 648 650 } 649 651 650 } 652 653 Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box) 654 { 655 Matrix4x4 m; 656 657 /* m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]); 658 m.x[1][0] = .0f; 659 m.x[2][0] = .0f; 660 m.x[3][0] = -(box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]); 661 662 m.x[0][1] = .0f; 663 m.x[1][1] = 2.0f / (box.Max()[1] - box.Min()[1]); 664 m.x[2][1] = .0f; 665 m.x[3][1] = -(box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]); 666 667 m.x[0][2] = .0f; 668 m.x[1][2] = .0f; 669 m.x[2][2] = 2.0f / (box.Max()[2] - box.Min()[2]); 670 m.x[3][2] = -(box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]); 671 672 m.x[0][3] = .0f; 673 m.x[1][3] = .0f; 674 m.x[2][3] = .0f; 675 m.x[3][3] = 1.0f;*/ 676 677 m.x[0][0] = -2.0f / (box.Max()[0] - box.Min()[0]); 678 m.x[1][0] = .0f; 679 m.x[2][0] = .0f; 680 m.x[3][0] = (box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]); 681 682 m.x[0][1] = .0f; 683 m.x[1][1] = -2.0f / (box.Max()[1] - box.Min()[1]); 684 m.x[2][1] = .0f; 685 m.x[3][1] = (box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]); 686 687 m.x[0][2] = .0f; 688 m.x[1][2] = .0f; 689 m.x[2][2] = -2.0f / (box.Max()[2] - box.Min()[2]); 690 m.x[3][2] = (box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]); 691 692 m.x[0][3] = .0f; 693 m.x[1][3] = .0f; 694 m.x[2][3] = .0f; 695 m.x[3][3] = 1.0f; 696 697 return m; 698 } 699 700 701 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
r2782 r2913 9 9 10 10 class Vector3; 11 class AxisAlignedBox3; 11 12 12 13 … … 108 109 friend Vector3 GetTranslation(const Matrix4x4 &M); 109 110 111 friend Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box); 112 110 113 // Overloaded output operator. 111 114 friend std::ostream& operator<< (std::ostream &s, const Matrix4x4 &M); … … 148 151 Vector3 TransformNormal(const Matrix4x4 &M, const Vector3 &v); 149 152 Vector3 GetTranslation(const Matrix4x4 &M); 153 Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box); 150 154 151 155 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.cpp
r2782 r2913 12 12 mD = -DotProd(b, mNormal); 13 13 } 14 15 16 /*Plane3::Plane3(const Vector3 &normal, float dist):17 mNormal(normal), mD(dist)18 {19 }*/20 14 21 15 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polygon3.cpp
r2912 r2913 135 135 else if (classification == FRONT_SIDE) 136 136 return 1; 137 // plane splits polygon 137 138 // plane splits polygon or is coincident 138 139 return 0; 139 140 } … … 203 204 if (mVertices.size() < 3) 204 205 return false; 205 206 #if 0 206 207 // matt: removed for performance issues 207 208 // check if area exceeds certain size … … 224 225 vtx = *it; 225 226 } 226 227 #endif 227 228 return true; 228 229 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polygon3.h
r2912 r2913 18 18 struct Triangle3; 19 19 20 21 22 typedef std::vector<Vector3> VertexArray;23 20 24 21 … … 70 67 @returns true if polygon is valid. 71 68 */ 72 bool Valid( constfloat epsilon) const;69 bool Valid(float epsilon) const; 73 70 /** Returns the surface normal. 74 71 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp
r2912 r2913 83 83 84 84 85 85 86 float Polyhedron::GetVolume() const 86 87 { … … 124 125 { 125 126 int boxSide = mBox.Side(plane); 127 126 128 // plane does not intersect bounding box 127 129 if (boxSide != 0) return boxSide; … … 135 137 const int side = (*it)->Side(plane, epsilon); 136 138 137 if (side != 0) 139 if (side == 0) // intersects polygon => intersects 140 return 0; 141 else if (side != 0) 138 142 { 139 143 if (side == -s) … … 178 182 if (mPolygons.size() < 3) 179 183 return false; 180 else 181 return true; 184 185 const Vector3 center = CenterOfMass(); 186 187 PolygonContainer::const_iterator pit, pit_end = mPolygons.end(); 188 189 for (pit = mPolygons.begin(); pit != pit_end; ++ pit) 190 { 191 Polygon3 *poly = *pit; 192 Plane3 plane = poly->GetSupportingPlane(); 193 194 float dist = plane.Distance(center); 195 //cout << "dist: " << dist<< endl; 196 if (dist > 0) 197 return false; 198 } 199 return true; 182 200 } 183 201 … … 189 207 190 208 if (intersect == 1) 209 { 191 210 // on the other side of the plane, the intersection is empty 192 return NULL; 211 return NULL; 212 } 193 213 else if (intersect == -1) 194 return NULL;214 { 195 215 // does not intersect, just return a copy 196 //return new Polyhedron(*this); 216 return new Polyhedron(*this); 217 } 218 219 // polyhedron is intersected: create new polyhedron 220 Polyhedron *clippedPolyhedron = new Polyhedron(); 197 221 198 222 199 223 ////////// 200 //-- finally,create and add new polygon to close polyhedron224 //-- create and add new polygon to close polyhedron 201 225 202 226 // get cross section of new polygon … … 206 230 planePoly = SplitPolygon(planePoly); 207 231 208 // something is wrong, probably some numerical error : just bail out232 // something is wrong, probably some numerical error 209 233 if (!planePoly) 210 234 { 211 235 cerr << "should not happen" << endl; 212 return NULL;//new Polyhedron(*this); 213 } 214 215 Polyhedron *clippedPolyhedron = new Polyhedron(); 236 return new Polyhedron(*this); 237 } 216 238 217 239 // add the new polygon to the polyhedron … … 221 243 222 244 ///////////// 223 //-- plane splits all polygons245 //-- clip polyhedron: plane splits all polygons 224 246 225 247 for (int i = 0; i < (int)mPolygons.size(); ++ i) … … 260 282 } 261 283 } 262 263 284 264 285 return clippedPolyhedron; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.h
r2912 r2913 73 73 inline friend std::ostream &operator<<(std::ostream &s, const Polyhedron &a); 74 74 75 76 77 75 protected: 78 76 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2911 r2913 108 108 if (!polyhedron) return; 109 109 110 cout << "here3" << endl;111 112 110 for (size_t i = 0; i < polyhedron->NumPolygons(); ++ i) 113 111 { … … 133 131 134 132 135 void ShadowMap::CalcFocussedFrustum(const Matrix4x4 &camProjView, 136 const Matrix4x4 &lightProjView, 137 Matrix4x4 &focussed) 138 { 133 void ShadowMap::IncludeLightVolume(const Polyhedron &polyhedron, 134 VertexArray &frustumPoints, 135 const Vector3 lightDir, 136 const AxisAlignedBox3 &sceneBox 137 ) 138 { 139 // we don't need closed form anymore => just store vertices 140 VertexArray vertices; 141 polyhedron.CollectVertices(vertices); 142 143 // we 'look' at each point and calculate intersections of rays with scene bounding box 144 VertexArray::const_iterator it, it_end = vertices.end(); 145 146 cout << "=================" << endl; 147 148 for (it = vertices.begin(); it != it_end; ++ it) 149 { 150 Vector3 v = *it; 151 152 frustumPoints.push_back(v); 153 154 // hack: get point surely outside of box 155 v -= Magnitude(mSceneBox.Diagonal()) * lightDir; 156 157 //cout << "pt: " << v << endl; 158 SimpleRay ray(v, lightDir); 159 160 float tNear, tFar; 161 162 if (sceneBox.Intersects(ray, tNear, tFar)) 163 { 164 Vector3 newpt = ray.Extrap(tNear); 165 Vector3 newpt2 = ray.Extrap(tFar); 166 167 frustumPoints.push_back(newpt); 168 169 if (newpt.z < 220) 170 cout << "ipt: " << newpt << " " << *it << endl; 171 } 172 } 173 } 174 175 176 bool ShadowMap::CalcLightProjection(Matrix4x4 &lightProj) 177 { 178 DEL_PTR(polyhedron); 179 180 139 181 /////////////////// 140 //-- First step: calc clipped frustum 141 142 DEL_PTR(polyhedron); 143 polyhedron = mCamera->CalcClippedFrustum(mSceneBox); 144 145 if (polyhedron) 146 { 147 // second step: focus light frustum on clipped frustum 148 Frustum lightFrustum(lightProjView); 149 150 for (int i = 0; i < 6; ++ i) 151 { 152 // the clipping planes look outward the frustum, 153 // so distances > 0 mean that a point is outside 154 const float invLength = 1.0f / Magnitude(lightFrustum.mClipPlanes[i].mNormal); 155 156 lightFrustum.mClipPlanes[i].mD *= invLength; 157 lightFrustum.mClipPlanes[i].mNormal *= invLength; 158 } 159 160 //lightFrustum.EnclosePolyhedron(*polyhedron); 161 lightFrustum.ExtractTransformation(focussed); 162 } 182 //-- First step: calc frustum clipped by scene box 183 184 polyhedron = CalcClippedFrustum(mSceneBox); 185 186 if (!polyhedron) return false; // something is wrong 187 188 // include the part of the light volume that "sees" the frustum 189 // we only require frustum vertices 190 191 VertexArray frustumPoints; 192 IncludeLightVolume(*polyhedron, frustumPoints, mShadowCam->GetDirection(), mSceneBox); 193 194 195 /////////////// 196 //-- transform points from world view to light view and calculate extremal points 197 198 AxisAlignedBox3 extremalPoints; 199 extremalPoints.Initialize(); 200 201 Matrix4x4 lightView; 202 mShadowCam->GetModelViewMatrix(lightView); 203 204 //Matrix4x4 inverseCamView; 205 //mCamera->GetModelViewMatrix(inverseCamView); 206 //Invert(inverseCamView); 207 208 //Matrix4x4 m = inverseCamView * lightView; 209 210 VertexArray::const_iterator it, it_end = frustumPoints.end(); 211 212 for (it = frustumPoints.begin(); it != it_end; ++ it) 213 { 214 Vector3 pt = *it; 215 216 //pt = inverseCamView * pt; 217 pt = lightView * pt; 218 //v = m * v; 219 220 extremalPoints.Include(pt); 221 //cout << "pt: " << pt << endl; 222 } 223 224 // focus projection matrix on the extremal points 225 lightProj = GetFittingProjectionMatrix(extremalPoints); 226 227 /*Vector3 pmax = extremalPoints.Max(); 228 Vector3 pmin = extremalPoints.Min(); 229 230 cout << "min: " << lightProj * pmin << endl; 231 cout << "max: " << lightProj * pmax << endl; 232 233 for (it = frustumPoints.begin(); it != it_end; ++ it) 234 { 235 Vector3 pt = *it; 236 237 pt = lightView * pt; 238 pt = lightProj * pt; 239 240 cout << "pt: " << pt << endl; 241 }*/ 242 243 return true; 244 } 245 246 247 Polyhedron *ShadowMap::CalcClippedFrustum(const AxisAlignedBox3 &box) const 248 { 249 Vector3 ftl, ftr, fbl, fbr; 250 Vector3 ntl, ntr, nbl, nbr; 251 252 VertexArray sides[6]; 253 254 mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 255 256 for (int i = 0; i < 6; ++ i) 257 sides[i].resize(4); 258 259 // left, right 260 sides[0][0] = ftl; sides[0][1] = fbl; sides[0][2] = nbl; sides[0][3] = ntl; 261 sides[1][0] = fbr; sides[1][1] = ftr; sides[1][2] = ntr; sides[1][3] = nbr; 262 // bottom, top 263 sides[2][0] = fbl; sides[2][1] = fbr; sides[2][2] = nbr; sides[2][3] = nbl; 264 sides[3][0] = ftr; sides[3][1] = ftl; sides[3][2] = ntl; sides[3][3] = ntr; 265 // near, far 266 sides[4][0] = ntr; sides[4][1] = ntl; sides[4][2] = nbl; sides[4][3] = nbr; 267 sides[5][0] = ftl; sides[5][1] = ftr; sides[5][2] = fbr; sides[5][3] = fbl; 268 269 //sides[4][0] = ntl; sides[4][1] = ntr; sides[4][2] = nbr; sides[4][3] = nbl; 270 //sides[5][0] = ftr; sides[5][1] = ftl; sides[5][2] = fbl; sides[5][3] = fbr; 271 272 273 274 ////////// 275 //-- compute polyhedron 276 277 PolygonContainer polygons; 278 279 for (int i = 0; i < 6; ++ i) 280 { 281 Polygon3 *poly = new Polygon3(sides[i]); 282 polygons.push_back(poly); 283 } 284 285 Polyhedron *p = new Polyhedron(polygons); 286 //return p; 287 288 Polyhedron *clippedPolyhedron = box.CalcIntersection(*p); 289 290 DEL_PTR(p); 291 292 293 return clippedPolyhedron; 163 294 } 164 295 … … 169 300 const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 170 301 171 mShadowCam->SetDirection(mLight->GetDirection()); 172 302 const Vector3 dir = mLight->GetDirection(); 303 //const Vector3 dir(0, 0, 1); 304 305 mShadowCam->SetDirection(dir); 306 307 //cout << "lightdir: " << mShadowCam->GetDirection() << endl; 308 173 309 // set position so that we can see the whole scene 174 310 Vector3 pos = mSceneBox.Center(); 175 311 176 Matrix4x4 camView;177 mCamera->GetModelViewMatrix(camView);178 179 pos -= mLight->GetDirection()* Magnitude(mSceneBox.Diagonal() * 0.5f);180 //mShadowCam->SetPosition(pos);312 //Matrix4x4 camView; 313 //mCamera->GetModelViewMatrix(camView); 314 315 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 316 mShadowCam->SetPosition(pos); 181 317 182 318 mFbo->Bind(); … … 199 335 glEnable(GL_DEPTH_TEST); 200 336 337 338 // setup projection 339 /*glMatrixMode(GL_PROJECTION); 340 glLoadIdentity(); 341 glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal())); 342 343 Matrix4x4 dummyMat; 344 glGetFloatv(GL_PROJECTION_MATRIX, (float *)dummyMat.x); 345 cout << "old:\n" << dummyMat << endl; 346 */ 347 Matrix4x4 lightView, lightProj; 348 349 mShadowCam->GetModelViewMatrix(lightView); 350 351 CalcLightProjection(lightProj); 352 201 353 glMatrixMode(GL_PROJECTION); 202 354 glPushMatrix(); 203 glLoadIdentity(); 204 205 // setup projection 206 glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal())); 207 355 glLoadMatrixf((float *)lightProj.x); 356 357 //cout << "new:\n" << lightProj << endl; 208 358 209 359 glMatrixMode(GL_MODELVIEW); … … 211 361 glLoadIdentity(); 212 362 213 // setup shadow camera214 363 mShadowCam->SetupCameraView(); 364 365 mLightProjView = lightView * lightProj; 215 366 216 367 217 368 ////////////// 218 369 //-- compute texture matrix 219 220 Matrix4x4 lightView, lightProj;221 222 mShadowCam->GetModelViewMatrix(lightView);223 mShadowCam->GetProjectionMatrix(lightProj);224 225 Matrix4x4 oldLightProjView = lightView * lightProj;226 Matrix4x4 newLightProj;227 228 CalcFocussedFrustum(projView, lightProj, newLightProj);229 //CalcFocussedFrustum(projView, oldLightProjView, newLightProj);230 231 Matrix4x4 dummyMat;232 glGetFloatv(GL_PROJECTION_MATRIX, (float *)dummyMat.x);233 234 235 cout << "old:\n" << dummyMat << endl;236 237 238 glMatrixMode(GL_PROJECTION);239 glLoadMatrixf((float *)newLightProj.x);240 241 glMatrixMode(GL_MODELVIEW);242 //glLoadIdentity();243 244 Matrix4x4 dummyMat3;245 glGetFloatv(GL_PROJECTION_MATRIX, (float *)dummyMat3.x);246 247 cout << "new:\n" << newLightProj << endl;248 249 lightView = camView;250 mLightProjView = lightView * newLightProj;251 //mLightProjView = newLightProj;252 253 //cout << "old: \n" << oldLightProjView << " new: \n " << mLightProjView << endl;254 255 256 370 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 257 371 0.0f, 0.5f, 0.0f, 0.5f, … … 260 374 261 375 mTextureMatrix = mLightProjView * biasMatrix; 262 //mTextureMatrix = oldLightProjView * biasMatrix;263 376 264 377 … … 279 392 280 393 glPopAttrib(); 281 /* 394 #if 0 282 395 float *data = new float[mSize * mSize]; 283 396 … … 288 401 289 402 PrintGLerror("shadow map"); 290 */ 403 #endif 291 404 FrameBufferObject::Release(); 292 405 } … … 305 418 306 419 420 307 421 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2911 r2913 6 6 #include "AxisAlignedBox3.h" 7 7 #include "Matrix4x4.h" 8 8 9 #include <Cg/cg.h> 9 10 #include <Cg/cgGL.h> … … 58 59 protected: 59 60 60 void CalcFocussedFrustum(const Matrix4x4 &camProjView, 61 const Matrix4x4 &lightProjView, 62 Matrix4x4 &focussed); 61 /** Calculates the intersection of the frustum with the box, 62 returns resultin polyhedron as array of polygons. 63 */ 64 Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const; 63 65 66 67 bool CalcLightProjection(Matrix4x4 &lightProj); 68 69 void IncludeLightVolume(const Polyhedron &polyhedron, 70 VertexArray &frustumPoints, 71 const Vector3 lightDir, 72 const AxisAlignedBox3 &sceneBox); 73 74 75 ////////////// 64 76 65 77 /// the scene bounding box -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
r2911 r2913 151 151 glDisable(GL_DEPTH_TEST); 152 152 153 //RenderFrustum();153 RenderFrustum(); 154 154 155 155 ShadowMap::DrawPolys(); … … 183 183 mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 184 184 185 //mCamera->SetF186 185 glLineWidth(2); 187 186 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2911 r2913 334 334 /////////////////////////// 335 335 336 camera = new Camera(winWidth, winHeight, fov);336 camera = new Camera(winWidth, winHeight, 60);//fov); 337 337 camera->SetNear(nearDist); 338 camera->SetFar(1000 00);338 camera->SetFar(1000); 339 339 340 340 camera->SetDirection(camDir); 341 342 341 camera->SetPosition(camPos); 343 342 … … 432 431 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 433 432 434 //bvh->SetCamera(camera);433 camera->SetFar(Magnitude(bvh->GetBox().Diagonal())); 435 434 436 435 InitCg(); … … 1546 1545 // hack: set far plane for viz 1547 1546 //camera->SetFar(0.35f * Magnitude(box.Diagonal())); 1548 camera->SetFar(1);1547 //camera->SetFar(1000); 1549 1548 1550 1549 const float offs = box.Size().x * 0.3f; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
r2911 r2913 30 30 struct LODLevel; 31 31 class Polygon3; 32 class Vector3; 32 33 33 34 … … 493 494 typedef std::vector<Polygon3 *> PolygonContainer; 494 495 496 typedef std::vector<Vector3> VertexArray; 497 498 495 499 static std::ofstream Debug("debug.log"); 496 500
Note: See TracChangeset
for help on using the changeset viewer.