- Timestamp:
- 10/26/08 18:29:27 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/SimpleTri.cpp
r3012 r3070 28 28 29 29 30 SimpleVec SimpleTri::Get Center() const30 SimpleVec SimpleTri::GetWorldCenter() const 31 31 { 32 32 return (mVertices[0] + mVertices[1] + mVertices[2]) / 3.0f; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/SimpleTri.h
r3012 r3070 15 15 SimpleVec GetNormal() const; 16 16 17 SimpleVec Get Center() const;17 SimpleVec GetWorldCenter() const; 18 18 19 19 float GetSpatialAngle(const SimpleVec &point) const; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp
r3065 r3070 1505 1505 1506 1506 1507 } 1508 1507 int AxisAlignedBox3::MajorAxis() const 1508 { 1509 const Vector3 sizeVec = mMax - mMin; 1510 1511 int axis; 1512 1513 if (sizeVec.x > sizeVec.y) axis = (sizeVec.x > sizeVec.z) ? 0 : 2; 1514 else axis = (sizeVec.y > sizeVec.z) ? 1 : 2; 1515 1516 return axis; 1517 } 1518 1519 1520 } 1521 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r2951 r3070 65 65 66 66 float Size(const int axis) const; 67 68 // Read-only const access tomMin and max vectors using references 67 /** Returns axis where box has largest extent. 68 */ 69 int MajorAxis() const; 70 /** Read-only const access tomMin and max vectors using references 71 */ 69 72 const Vector3& Min() const; 70 73 const Vector3& Max() const; … … 91 94 float Radius() const { return 0.5f * Magnitude(Size()); } 92 95 float SqrRadius() const { return 0.5f * SqrMagnitude(Size()); } 93 94 // Return whether the box is unbounded. Unbounded boxes appear95 // when unbounded objects such as quadric surfaces are included.96 /** Return whether the box is unbounded. Unbounded boxes appear 97 when unbounded objects such as quadric surfaces are included. 98 */ 96 99 bool Unbounded() const; 97 100 … … 127 130 */ 128 131 void Scale(float scale); 129 132 /** Scale box non-uniformally 133 */ 130 134 void Scale(const Vector3 &scale); 131 135 /** Translates the box with the factor. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3069 r3070 151 151 152 152 153 154 inline AxisAlignedBox3 ComputeBoundingBox(SceneEntity **entities, int numEntities) 155 { 156 AxisAlignedBox3 box = entities[0]->GetWorldBoundingBox(); 157 158 for (int i = 1; i < numEntities; ++ i) 159 { 160 box.Include(entities[i]->GetWorldBoundingBox()); 161 } 162 163 return box; 164 } 165 166 153 167 Bvh::Bvh() 154 168 { … … 419 433 if (!mDynamicEntities.empty()) 420 434 { 421 UpdateDynamicBranch(); 435 if (!mDynamicRoot) 436 CreateDynamicBranch(); 437 438 UpdateDynamicBranch(mDynamicRoot); 422 439 } 423 440 } … … 448 465 { 449 466 SceneEntity *ent = entities[i]; 450 float dist = ent->Get TransformedBoundingBox().GetMaxDistance(sNearPlane);467 float dist = ent->GetWorldBoundingBox().GetMaxDistance(sNearPlane); 451 468 452 469 if (dist > maxDist) maxDist = dist; … … 800 817 801 818 802 void Bvh::ComputeBvhStats() 803 { 819 void Bvh::ComputeBvhStats(BvhNode *root, BvhStats &bvhStats) 820 { 821 bvhStats.Reset(); 804 822 std::stack<BvhNode *> nodeStack; 805 nodeStack.push( mRoot);823 nodeStack.push(root); 806 824 807 825 int numVirtualLeaves = 0; 826 int numGeometry = 0; 808 827 809 828 while (!nodeStack.empty()) … … 815 834 { 816 835 ++ numVirtualLeaves; 836 numGeometry += node->CountPrimitives(); 817 837 818 838 BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 819 839 820 mBvhStats.mTriangles += CountTriangles(leaf);821 mBvhStats.mLeafSA += leaf->mBox.SurfaceArea();822 mBvhStats.mLeafVol += leaf->mBox.GetVolume();840 bvhStats.mTriangles += CountTriangles(leaf); 841 bvhStats.mLeafSA += leaf->mBox.SurfaceArea(); 842 bvhStats.mLeafVol += leaf->mBox.GetVolume(); 823 843 } 824 844 else 825 845 { 826 mBvhStats.mInteriorSA += node->mBox.SurfaceArea();827 mBvhStats.mInteriorVol += node->mBox.GetVolume();846 bvhStats.mInteriorSA += node->mBox.SurfaceArea(); 847 bvhStats.mInteriorVol += node->mBox.GetVolume(); 828 848 829 849 BvhInterior *interior = static_cast<BvhInterior *>(node); … … 834 854 } 835 855 836 mBvhStats.mGeometryRatio = mGeometrySize / (float)numVirtualLeaves; 837 mBvhStats.mTriangleRatio = mBvhStats.mTriangles / (float)numVirtualLeaves; 838 } 839 840 841 void Bvh::PrintBvhStats() const 842 { 843 cout << "\n******** bvh stats: ***********" << endl; 844 cout << "interiorNodesSA = " << mBvhStats.mInteriorSA / mRoot->mBox.SurfaceArea() << endl; 845 cout << "leafNodesSA = " << mBvhStats.mLeafSA / mRoot->mBox.SurfaceArea() << endl; 846 cout << "interiorNodesVolume = " << mBvhStats.mInteriorVol / mRoot->mBox.GetVolume() << endl; 847 cout << "leafNodesVolume = " << mBvhStats.mLeafVol / mRoot->mBox.GetVolume() << endl; 848 849 cout << "geometry per leaf: " << mBvhStats.mGeometryRatio << endl; 850 cout << "triangles per leaf: " << mBvhStats.mTriangleRatio << endl; 851 cout << "**************" << endl << endl; 856 bvhStats.mGeometryRatio = (float)numGeometry / numVirtualLeaves; 857 bvhStats.mTriangleRatio = (float)bvhStats.mTriangles / numVirtualLeaves; 858 bvhStats.mLeaves = numVirtualLeaves; 859 } 860 861 862 void Bvh::PrintBvhStats(const BvhStats &bvhStats) const 863 { 864 cout << "\n============ BVH statistics =============" << endl; 865 cout << "interiorNodesSA = " << bvhStats.mInteriorSA / mRoot->mBox.SurfaceArea() << endl; 866 cout << "leafNodesSA = " << bvhStats.mLeafSA / mRoot->mBox.SurfaceArea() << endl; 867 cout << "interiorNodesVolume = " << bvhStats.mInteriorVol / mRoot->mBox.GetVolume() << endl; 868 cout << "leafNodesVolume = " << bvhStats.mLeafVol / mRoot->mBox.GetVolume() << endl; 869 870 cout << "geometry per leaf: " << bvhStats.mGeometryRatio << endl; 871 cout << "triangles per leaf: " << bvhStats.mTriangleRatio << endl; 872 cout << "===========================================" << endl << endl; 852 873 } 853 874 … … 1155 1176 int Bvh::SortTriangles(BvhLeaf *leaf, 1156 1177 int axis, 1157 float position ,1158 SceneEntityContainer &entities)1178 float position 1179 ) 1159 1180 { 1160 1181 int i = leaf->mFirst; 1161 1182 int j = leaf->mLast; 1162 1183 1163 while (1) 1164 { 1165 while (entities[i]->GetCenter()[axis] < position) 1184 while (1) 1185 { 1186 while (mGeometry[i]->GetWorldCenter()[axis] < position) 1187 { 1188 //cout<<" i " << i << " " << mGeometry[i]->GetWorldCenter()[axis]; 1166 1189 ++ i; 1167 1168 while (position < entities[j]->GetCenter()[axis]) 1190 } 1191 1192 while (position < mGeometry[j]->GetWorldCenter()[axis]) 1193 { 1194 //cout<< axis << " j " << j << " " << mGeometry[j]->GetWorldCenter()[axis] << " " << position<< " "; 1169 1195 -- j; 1196 } 1170 1197 1171 1198 // sorting finished … … 1173 1200 1174 1201 // swap entities 1175 swap( entities[i], entities[j]);1202 swap(mGeometry[i], mGeometry[j]); 1176 1203 1177 1204 ++ i; … … 1184 1211 1185 1212 int Bvh::SortTrianglesSpatialMedian(BvhLeaf *leaf, 1186 int axis ,1187 SceneEntityContainer &entities)1213 int axis 1214 ) 1188 1215 { 1189 1216 // spatial median 1190 1217 float m = leaf->mBox.Center()[axis]; 1191 return SortTriangles(leaf, axis, m, entities); 1218 //cout << "here3 " << leaf->mBox << " " << leaf->mFirst << " " << leaf->mLast << endl; 1219 return SortTriangles(leaf, axis, m); 1192 1220 } 1193 1221 1194 1222 1195 1223 BvhNode *Bvh::SubdivideLeaf(BvhLeaf *leaf, 1196 int parentAxis ,1197 SceneEntityContainer &entities)1224 int parentAxis 1225 ) 1198 1226 { 1199 1227 if (TerminationCriteriaMet(leaf)) 1200 1228 { 1201 1229 leaf->mIsVirtualLeaf = true; 1230 leaf->mIsMaxDepthForVirtualLeaf = true; 1202 1231 return leaf; 1203 1232 } 1204 1233 1205 //int axis = leaf->mBox.MajorAxis(); 1206 int axis = (parentAxis + 1) % 3; 1234 //const int axis = (parentAxis + 1) % 3; 1235 const int axis = leaf->mBox.MajorAxis(); 1236 1237 1238 const int scale = 20; 1207 1239 1208 1240 // position of the split in the partailly sorted array of triangles 1209 1241 // corresponding to this leaf 1210 1242 int split = -1; 1211 const int scale = 20;1212 1213 1243 float pos = -1.0f; 1214 1244 1215 1245 // Spatial median subdivision 1216 split = SortTrianglesSpatialMedian(leaf, axis , entities);1246 split = SortTrianglesSpatialMedian(leaf, axis); 1217 1247 pos = leaf->mBox.Center()[axis]; 1218 1248 … … 1247 1277 1248 1278 // reset box 1249 leaf->mBox.Initialize(); 1279 //leaf->mBox.Initialize(); 1280 1281 front->mBox = ComputeBoundingBox(mGeometry + front->mFirst, front->CountPrimitives()); 1282 leaf->mBox = ComputeBoundingBox(mGeometry + leaf->mFirst, leaf->CountPrimitives()); 1250 1283 1251 1284 // recursively continue subdivision 1252 parent->mBack = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mBack), axis , entities);1253 parent->mFront = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mFront), axis , entities);1285 parent->mBack = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mBack), axis); 1286 parent->mFront = SubdivideLeaf(static_cast<BvhLeaf *>(parent->mFront), axis); 1254 1287 1255 1288 return parent; … … 1267 1300 1268 1301 1269 void Bvh::UpdateDynamicBranch() 1302 void Bvh::UpdateDynamicBranch(BvhNode *node) 1303 { 1304 if (node->IsLeaf()) 1305 { 1306 int numEntities; 1307 SceneEntity **entities = GetGeometry(node, numEntities); 1308 1309 node->mBox = ComputeBoundingBox(entities, numEntities); 1310 //cout << "box: " << node->mBox << endl; 1311 } 1312 else 1313 { 1314 BvhNode *f = static_cast<BvhInterior *>(node)->GetFront(); 1315 BvhNode *b = static_cast<BvhInterior *>(node)->GetBack(); 1316 1317 UpdateDynamicBranch(f); 1318 UpdateDynamicBranch(b); 1319 1320 node->mBox = f->mBox; 1321 node->mBox.Include(b->mBox); 1322 } 1323 } 1324 1325 1326 void Bvh::CreateDynamicBranch() 1270 1327 { 1271 1328 // the bvh has two main branches … … 1278 1335 // the movements of the objects within 1279 1336 1280 // delete old branch1281 cout << "deleting old branch" << endl;1282 1283 1337 DEL_PTR(mDynamicRoot); 1284 1338 1285 mDynamicRoot = new BvhLeaf(mRoot); 1286 mDynamicRoot->mBox = mRoot->mBox; 1287 1288 mDynamicRoot->mFirst = 0; 1289 mDynamicRoot->mLast = (int)mDynamicEntities.size() - 1; 1290 mDynamicRoot->mArea = mDynamicRoot->mBox.SurfaceArea(); 1291 1292 cout << "updating dynamic branch" << endl; 1293 1294 mDynamicRoot = SubdivideLeaf(static_cast<BvhLeaf *>(mDynamicRoot), 0, mDynamicEntities); 1295 1296 cout << "finished updating dynamic branch" << endl; 1297 } 1298 1299 1300 void Bvh::AddDynamicObject(SceneEntity *ent) 1301 { 1302 mDynamicEntities.push_back(ent); 1339 BvhLeaf *l = new BvhLeaf(mRoot); 1340 1341 l->mBox.Initialize(); 1342 1343 SceneEntityContainer::const_iterator sit, sit_end = mDynamicEntities.end(); 1344 1345 for (sit = mDynamicEntities.begin(); sit != sit_end; ++ sit) 1346 { 1347 l->mBox.Include((*sit)->GetWorldBoundingBox()); 1348 } 1349 1350 l->mFirst = (int)(mGeometrySize - mDynamicEntities.size()); 1351 l->mLast = (int)mGeometrySize - 1; 1352 l->mArea = l->mBox.SurfaceArea(); 1353 1354 cout << "updating dynamic branch " << l->mFirst << " " << l->mLast << endl; 1355 1356 mDynamicRoot = SubdivideLeaf(l, 0); 1357 1358 BvhStats bvhStats; 1359 ComputeBvhStats(mDynamicRoot, bvhStats); 1360 1361 cout << "\n=========== Dynamic BVH statistics: =========" << endl; 1362 cout << "leaves = " << bvhStats.mLeaves << endl; 1363 cout << "interiorNodesSA = " << bvhStats.mInteriorSA << endl; 1364 cout << "leafNodesSA = " << bvhStats.mLeafSA << endl; 1365 cout << "interiorNodesVolume = " << bvhStats.mInteriorVol << endl; 1366 cout << "leafNodesVolume = " << bvhStats.mLeafVol << endl; 1367 1368 cout << "geometry per leaf: " << bvhStats.mGeometryRatio << endl; 1369 cout << "triangles per leaf: " << bvhStats.mTriangleRatio << endl; 1370 cout << "=============================================" << endl << endl; 1371 } 1372 1373 1374 void Bvh::AddDynamicObjects(const SceneEntityContainer &entities) 1375 { 1376 // copy old entities 1377 SceneEntity **newGeom = new SceneEntity*[mGeometrySize + (int)entities.size()]; 1378 1379 memcpy(newGeom, mGeometry, mGeometrySize * sizeof(SceneEntity *)); 1380 1381 delete [] mGeometry; 1382 mGeometry = newGeom; 1383 1384 // now add new entities 1385 SceneEntityContainer::const_iterator it, it_end = entities.end(); 1386 1387 size_t i = mGeometrySize; 1388 for (it = entities.begin(); it != it_end; ++ it, ++ i) 1389 { 1390 mGeometry[i] = (*it); 1391 mDynamicEntities.push_back(*it); 1392 } 1393 1394 1395 mGeometrySize += entities.size(); 1303 1396 } 1304 1397 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r3065 r3070 478 478 struct BvhStats 479 479 { 480 BvhStats(): 481 mInteriorSA(0), 482 mLeafSA(0), 483 mInteriorVol(0), 484 mLeafVol(0), 485 mTriangles(0), 486 mTriangleRatio(0), 487 mGeometryRatio(0), 488 mMaxGeometry(0), 489 mMaxTriangles(0) 490 {} 491 480 BvhStats() { Reset(); } 481 482 void Reset() 483 { 484 mInteriorSA = .0f; 485 mLeafSA = .0f; 486 mInteriorVol = .0f; 487 mLeafVol = .0f; 488 mTriangleRatio = .0f; 489 mGeometryRatio = .0f; 490 491 mTriangles = 0; 492 mLeaves = 0; 493 } 494 495 /////////////////// 496 492 497 float mInteriorSA; 493 498 float mLeafSA; … … 495 500 float mLeafVol; 496 501 497 int mTriangles;498 499 502 float mTriangleRatio; 500 503 float mGeometryRatio; 501 504 502 int m MaxGeometry;503 int m MaxTriangles;505 int mTriangles; 506 int mLeaves; 504 507 }; 505 508 … … 525 528 */ 526 529 inline BvhNode *GetRoot(); 530 531 inline BvhNode *GetDynamicRoot(); 527 532 /** Returns the bounding box of this bvh. 528 533 */ … … 643 648 void RenderBoundsForViz(BvhNode *node, RenderState *state, bool useTightBounds); 644 649 645 void AddDynamicObject(SceneEntity *ent); 650 void AddDynamicObjects(const SceneEntityContainer &entities); 651 646 652 647 653 … … 661 667 662 668 ///////////// 663 664 void ComputeBvhStats(); 665 void PrintBvhStats() const; 669 /** Traverse hierarchy and compute stats. 670 */ 671 void ComputeBvhStats(BvhNode *root, BvhStats &bvhStats); 672 /** Output the bvh statistics. 673 */ 674 void PrintBvhStats(const BvhStats &bvhStats) const; 666 675 667 676 … … 712 721 int SortTriangles(BvhLeaf *leaf, 713 722 int axis, 714 float position, 715 SceneEntityContainer &entities); 723 float position); 716 724 717 725 int SortTrianglesSpatialMedian(BvhLeaf *leaf, 718 int axis, 719 SceneEntityContainer &entities); 726 int axis); 720 727 721 728 BvhNode *SubdivideLeaf(BvhLeaf *leaf, 722 int parentAxis, 723 SceneEntityContainer &entities); 729 int parentAxis); 724 730 /** Recompute the dynamic branch of the hierarchy. 725 731 */ 726 void UpdateDynamicBranch(); 732 void CreateDynamicBranch(); 733 734 void UpdateDynamicBranch(BvhNode *node); 727 735 728 736 inline bool TerminationCriteriaMet(BvhLeaf *leaf) const; … … 830 838 831 839 840 BvhNode *Bvh::GetDynamicRoot() 841 { 842 return mDynamicRoot; 843 } 844 845 832 846 const AxisAlignedBox3 &Bvh::GetBox() const 833 847 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
r3069 r3070 130 130 131 131 // compute and print stats 132 bvh->ComputeBvhStats( );133 bvh->PrintBvhStats( );132 bvh->ComputeBvhStats(bvh->mRoot, bvh->mBvhStats); 133 bvh->PrintBvhStats(bvh->mBvhStats); 134 134 135 135 return bvh; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/EntityMerger.cpp
r2980 r3070 30 30 Shape *shape = MergeShapes(shape1, shape2, ent); 31 31 32 LODLevel *lodLevel = new LODLevel(0);32 LODLevel lodLevel(0); 33 33 34 lodLevel ->AddShape(shape);34 lodLevel.AddShape(shape); 35 35 ent->AddLODLevel(lodLevel); 36 36 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r3066 r3070 157 157 // add root node to queue 158 158 EnqueueNode(mBvh->GetRoot()); 159 // add dynamic root 160 EnqueueNode(mBvh->GetDynamicRoot()); 159 161 160 162 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3058 r3070 51 51 CLEAR_CONTAINER(mTrafos); 52 52 CLEAR_CONTAINER(mShapes); 53 CLEAR_CONTAINER(mLODs);53 //CLEAR_CONTAINER(mLODs); 54 54 } 55 55 … … 103 103 str.read(reinterpret_cast<char *>(&numShapes), sizeof(int)); 104 104 105 LODLevel *lodLevel = new LODLevel(dist); 105 //LODLevel *lodLevel = new LODLevel(dist); 106 LODLevel lodLevel(dist); 106 107 107 108 for (int j = 0; j < numShapes; ++ j) … … 119 120 120 121 sceneGeom->AddShape(shape); 121 lodLevel ->AddShape(shape);122 lodLevel.AddShape(shape); 122 123 } 123 124 124 mLODs.push_back(lodLevel);125 //mLODs.push_back(lodLevel); 125 126 sceneGeom->AddLODLevel(lodLevel); 126 127 } … … 407 408 } 408 409 409 } 410 410 411 void ResourceManager::AddSceneEntity(SceneEntity *ent) 412 { 413 mSceneEntities.push_back(ent); 414 } 415 416 417 Transform3 *ResourceManager::CreateTransform(const Matrix4x4 &m) 418 { 419 Transform3 *t = new Transform3(m); 420 421 mTrafos.push_back(t); 422 return t; 423 } 424 425 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r3057 r3070 50 50 */ 51 51 static void DelSingleton(); 52 /** Adds a scene entity to be handled by the resource mananger. 53 */ 54 void AddSceneEntity(SceneEntity *ent); 55 /** Adds a scene entity to be handled by the resource mananger. 56 */ 57 Transform3 *CreateTransform(const Matrix4x4 &m); 58 52 59 53 60 protected: … … 83 90 TransformContainer mTrafos; 84 91 ShapeContainer mShapes; 85 LODContainer mLODs;92 //LODContainer mLODs; 86 93 /// the scene entities 87 94 SceneEntityContainer mSceneEntities; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r3034 r3070 39 39 if (!sUseLODs) return; 40 40 41 const Vector3 pos = Get Center();41 const Vector3 pos = GetWorldCenter(); 42 42 43 43 const float dist = SqrDistance(pos, viewPoint); … … 48 48 for (int i = 0; i < l; ++ i) 49 49 { 50 LODLevel *lod = mLODLevels[i]; 51 52 if (lod->GetSquaredDistance() > dist) 50 if (mLODLevels[i].GetSquaredDistance() > dist) 53 51 break; 54 52 … … 79 77 } 80 78 81 start = mLODLevels[mCurrentLODLevel] ->GetShapes().begin();82 end = mLODLevels[mCurrentLODLevel] ->GetShapes().end();79 start = mLODLevels[mCurrentLODLevel].GetShapes().begin(); 80 end = mLODLevels[mCurrentLODLevel].GetShapes().end(); 83 81 } 84 82 … … 88 86 ShapeContainer::iterator &end) 89 87 { 90 LODLevel *lod = mLODLevels[level]; 91 92 start = lod->GetShapes().begin(); 93 end = lod->GetShapes().end(); 88 start = mLODLevels[level].GetShapes().begin(); 89 end = mLODLevels[level].GetShapes().end(); 94 90 } 95 91 … … 99 95 ShapeContainer::iterator sit, sit_end; 100 96 101 GetCurrentLODLevel(sit, sit_end); 97 if (!mLODLevels.empty()) 98 GetCurrentLODLevel(sit, sit_end); 99 else 100 { 101 sit = mShapes.begin(); sit_end = mShapes.end(); 102 } 102 103 103 104 for (; sit != sit_end; ++ sit) … … 146 147 } 147 148 148 return mLODLevels[lodLevel] ->GetNumTriangles();149 return mLODLevels[lodLevel].GetNumTriangles(); 149 150 } 150 151 151 152 152 AxisAlignedBox3 SceneEntity::Get TransformedBoundingBox() const153 AxisAlignedBox3 SceneEntity::GetWorldBoundingBox() const 153 154 { 154 155 if (mTransform->IsIdentity()) return mBox; … … 166 167 167 168 168 Vector3 SceneEntity::Get Center() const169 Vector3 SceneEntity::GetWorldCenter() const 169 170 { 170 171 if (mTransform->IsIdentity()) 171 172 return mCenter; 172 173 173 Matrix4x4 mat = mTransform->GetMatrix(); 174 175 return mat * mCenter; 174 return mTransform->GetMatrix() * mCenter; 176 175 } 177 176 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r3042 r3070 34 34 */ 35 35 SceneEntity(Transform3 *trafo); 36 36 /** Copy constructur. 37 */ 38 //SceneEntity(const SceneEntity &trafo); 39 /** Destructor. 40 */ 37 41 virtual ~SceneEntity(); 38 42 /** Renders this node. … … 64 68 */ 65 69 int CountNumTriangles(int lodLevel = -1); 66 /** Returns the bounding box.70 /** Returns the local bounding box. 67 71 */ 68 72 AxisAlignedBox3 GetBoundingBox() const; 69 73 /** Returns the transformed bounding box. 70 74 */ 71 AxisAlignedBox3 Get TransformedBoundingBox() const;75 AxisAlignedBox3 GetWorldBoundingBox() const; 72 76 73 77 … … 84 88 /** Adds a new lod level. 85 89 */ 86 void AddLODLevel( LODLevel *lod) { mLODLevels.push_back(lod); }90 void AddLODLevel(const LODLevel &lod) { mLODLevels.push_back(lod); } 87 91 /** Returns numbers of lod levels. 88 92 */ … … 90 94 /** Returns transformed center point of this shape. 91 95 */ 92 Vector3 Get Center() const;96 Vector3 GetWorldCenter() const; 93 97 /** If false, the highest (most detailed) LOD level is used for all entities. 94 98 */ … … 111 115 Transform3 *mTransform; 112 116 /// Stores information about the LOD levels 113 LODLevel ContainermLODLevels;117 LODLevelArray mLODLevels; 114 118 /// the renderable shapes 115 119 ShapeContainer mShapes; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp
r3023 r3070 46 46 ent->AddShape(shape); 47 47 48 LODLevel *lodLevel = new LODLevel(0);48 LODLevel lodLevel(0); 49 49 50 lodLevel ->AddShape(shape);50 lodLevel.AddShape(shape); 51 51 ent->AddLODLevel(lodLevel); 52 52 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
r3054 r3070 53 53 54 54 55 AxisAlignedBox3 Shape::Get TransformedBoundingBox() const55 AxisAlignedBox3 Shape::GetWorldBoundingBox() const 56 56 { 57 57 if (mParent->GetTransform()->IsIdentity()) … … 64 64 65 65 66 Vector3 Shape::Get Center() const66 Vector3 Shape::GetWorldCenter() const 67 67 { 68 68 if (mParent->GetTransform()->IsIdentity()) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h
r3061 r3070 52 52 /** Returns bounding box transformed with the parent transform. 53 53 */ 54 AxisAlignedBox3 Get TransformedBoundingBox() const;54 AxisAlignedBox3 GetWorldBoundingBox() const; 55 55 /** Returns material of this shape. 56 56 */ … … 58 58 /** Returns transformed center point of this shape. 59 59 */ 60 Vector3 Get Center() const;60 Vector3 GetWorldCenter() const; 61 61 62 62 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r3057 r3070 157 157 void SkyPreetham::RenderSunDisk(const Vector3 &sunDir, Camera *camera) 158 158 { 159 #if TODO D159 #if TODO 160 160 // Move skybox with camera. 161 161 Vector3 position = camera->GetPosition(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r3034 r3070 7 7 { 8 8 9 CGparameter Transform3::sModelMatrixParam; 9 10 Transform3::Transform3() 11 { 12 Reset(); 13 } 10 14 11 15 … … 13 17 { 14 18 mIsIdentity = false; 15 }16 17 18 Transform3::Transform3()19 {20 Reset();21 19 } 22 20 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
r3061 r3070 3 3 4 4 #include "Matrix4x4.h" 5 #include "glInterface.h"6 5 #include "common.h" 7 #include <Cg/cg.h>8 #include <Cg/cgGL.h>9 6 10 7 … … 49 46 inline bool IsIdentity() const { return mIsIdentity; } 50 47 51 static CGparameter sModelMatrixParam;52 53 48 54 49 protected: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Triangle3.cpp
r2957 r3070 49 49 50 50 51 Vector3 Triangle3::Get Center() const51 Vector3 Triangle3::GetWorldCenter() const 52 52 { 53 53 return (mVertices[0] + mVertices[1] + mVertices[2]) / 3.0f; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Triangle3.h
r2957 r3070 21 21 Vector3 GetNormal() const; 22 22 23 Vector3 Get Center() const;23 Vector3 GetWorldCenter() const; 24 24 25 25 float GetSpatialAngle(const Vector3 &point) const; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3068 r3070 71 71 /// the renderable scene geometry 72 72 SceneEntityContainer sceneEntities; 73 SceneEntityContainer dynamicObjects; 73 74 // traverses and renders the hierarchy 74 75 RenderTraverser *traverser = NULL; … … 289 290 void PrepareRenderQueue(); 290 291 /// loads the specified model 291 void LoadModel(const string &model );292 void LoadModel(const string &model, SceneEntityContainer &entities); 292 293 293 294 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } … … 450 451 //-- load the static scene geometry 451 452 452 LoadModel("city.dem" );453 LoadModel("city.dem", sceneEntities); 453 454 454 455 … … 478 479 //-- setup the skydome model 479 480 480 LoadModel("sky.dem" );481 LoadModel("sky.dem", sceneEntities); 481 482 skyDome = sceneEntities.back(); 482 483 … … 494 495 visualization = new Visualization(bvh, camera, NULL, &state); 495 496 496 497 LoadModel("hbuddha.dem"); 498 buddha = sceneEntities.back(); 499 497 LoadModel("hbuddha.dem", dynamicObjects); 498 buddha = dynamicObjects.back(); 499 dynamicObjects.clear(); 500 500 Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 501 501 Matrix4x4 transl = TranslationMatrix(sceneCenter); 502 503 502 buddha->GetTransform()->SetMatrix(transl); 504 503 505 bvh->AddDynamicObject(buddha); 506 504 Vector3 offs = Vector3::ZERO(); 505 506 for (int i = 0; i < 10; ++ i) 507 { 508 SceneEntity *ent = new SceneEntity(*buddha); 509 resourceManager->AddSceneEntity(ent); 510 511 offs.x = RandomValue(.0f, 50.0f); 512 offs.y = RandomValue(.0f, 50.0f); 513 514 transl = TranslationMatrix(sceneCenter + offs); 515 Transform3 *transform = resourceManager->CreateTransform(transl); 516 517 ent->SetTransform(transform); 518 dynamicObjects.push_back(ent); 519 } 520 521 bvh->AddDynamicObjects(dynamicObjects); 507 522 508 523 // this function assign the render queue bucket ids of the materials in beforehand 509 524 // => probably a little less overhead for new parts of the scene that are not yet assigned 510 525 PrepareRenderQueue(); 511 512 526 /// forward rendering is the default 513 527 state.SetRenderTechnique(FORWARD); 514 515 528 // frame time is restarted every frame 516 529 frameTimer.Start(); … … 2004 2017 2005 2018 2006 void LoadModel(const string &model )2019 void LoadModel(const string &model, SceneEntityContainer &entities) 2007 2020 { 2008 2021 const string filename = string(model_path + model); 2009 2022 2010 if (resourceManager->Load(filename, sceneEntities))2023 if (resourceManager->Load(filename, entities)) 2011 2024 cout << "model " << filename << " loaded" << endl; 2012 2025 else -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
r3042 r3070 505 505 typedef std::vector<ShaderProgram *> ShaderContainer; 506 506 typedef std::vector<Technique *> TechniqueContainer; 507 507 508 typedef std::vector<Vector3> VertexArray; 508 509 typedef std::vector<LODLevel> LODLevelArray; 509 510 510 511 typedef std::pair<float, float> Texcoord2;
Note: See TracChangeset
for help on using the changeset viewer.