Changeset 1285 for GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Timestamp:
- 08/25/06 17:44:02 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTree.h
r1274 r1285 46 46 } 47 47 48 // save entities to ascii file 49 bool saveSceneASCII(const String& filename, SceneNode *entityroot); 48 50 protected: 49 51 KdTreeAppListener *mFrameListener; … … 84 86 bool loadScene(const String& filename); 85 87 bool loadSceneIV(const String &filename, SceneNode *root, const int index); 88 // loadding world geometry from cfg file - for terrain 89 bool loadSceneCfg(const String &filename, SceneNode *root, const int index); 90 // load entities from ascii file 91 bool loadSceneASCII(const String &filename, SceneNode *root, const int index); 92 93 typedef std::list<SceneNode *> NodeList; 94 void addNodesToList(SceneNode* node, NodeList& list); 86 95 87 96 void createMaterials(void); -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1274 r1285 66 66 typedef std::list<FrameInfo> FrameList; 67 67 68 class KdTreeApp; 69 68 70 class KdTreeAppListener: public FrameListener, public KeyListener 69 71 { … … 120 122 mDemoMode(false), 121 123 mEnhancedVisibility(false), 122 mDemoInterval(1.0f) 124 mDemoInterval(1.0f), 125 myApp(0) 123 126 { 124 127 … … 126 129 127 130 String mSceneFiles; 131 String mSceneOutfileName; 128 132 String mDemoInfileName; 129 133 String mDemoOutfileName; … … 142 146 bool mEnhancedVisibility; 143 147 Real mDemoInterval; 148 KdTreeApp *myApp; 144 149 }; 145 150 -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1274 r1285 6 6 #include "TestKdTree.h" 7 7 #include "WinCmdLineParser.h" 8 #include <cstring> 8 9 9 10 #ifdef __cplusplus … … 37 38 .addOpt("s","scenemgr", ARGUMENT_REQUIRED) 38 39 .addOpt("","comment", ARGUMENT_REQUIRED) 39 .addOpt("e","enhancevis", ARGUMENT_NONE); 40 .addOpt("e","enhancevis", ARGUMENT_NONE) 41 .addOpt("","savesceneto", ARGUMENT_REQUIRED); 40 42 41 43 … … 46 48 options.mDemoMode = cmdparser.getOpt("d"); 47 49 options.mEnhancedVisibility = cmdparser.getOpt("e"); 50 cmdparser.getOpt("savesceneto", options.mSceneOutfileName); 48 51 49 52 std::string tmp; … … 302 305 mCamNode->setPosition(707,2500,528); 303 306 mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 304 //mCamNode->setPosition( 0,0,0);305 //mCamNode->setOrientation(Quaternion( Radian(Math::PI),Vector3::UNIT_Y));307 //mCamNode->setPosition(1056.59, 467.412, 783.502); 308 //mCamNode->setOrientation(Quaternion(-0.281354, 0.0204027, 0.956747, 0.0695345)); 306 309 } 307 310 // load scene from file … … 310 313 // don't load the other stuff 311 314 loadScene(mOptions.mSceneFiles); 315 312 316 // top view 313 317 mTopCam->setPosition(Vector3(1232, 3990, -1477)); … … 531 535 void KdTreeApp::createFrameListener(void) 532 536 { 537 // set pointer to self in options 538 mOptions.myApp = this; 539 533 540 mFrameListener = new KdTreeAppListener(mWindow, mSceneMgr, mOptions); 534 541 //mFrameListener->showDebugOverlay( true ); … … 760 767 LogManager::getSingleton().logMessage(d.str()); 761 768 762 bool result = false; 769 bool loadres = false; 770 bool result = filenames.empty() ? false : true; 771 763 772 std::vector<std::string>::const_iterator fit, fit_end = filenames.end(); 764 773 int i = 0; … … 770 779 if (strstr(fn.c_str(), ".iv") || strstr(fn.c_str(), ".wrl")) 771 780 { 772 // hack: set postion manually for vienna773 //mCamNode->setPosition(Vector3(830, 300, -540));774 //mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));775 776 781 // load iv files 777 loadSceneIV(fn, mSceneMgr->getRootSceneNode(), i); 778 } 779 780 result = true; 781 } 782 783 784 /* 785 if (result) 786 { 787 int intersectables, faces; 788 789 std::stringstream d; 790 d << filename << " parsed successfully.\n" 791 << "#NUM_OBJECTS (Total numner of objects)\n" << intersectables << "\n" 792 << "#NUM_FACES (Total numner of faces)\n" << faces << "\n"; 793 } 794 */ 782 loadres = loadSceneIV(fn, mSceneMgr->getRootSceneNode(), i); 783 } 784 else if (strstr(fn.c_str(), ".cfg")) 785 { 786 // load terrain from cfg 787 loadres = loadSceneCfg(fn, mSceneMgr->getRootSceneNode(), i); 788 } 789 else if (strstr(fn.c_str(), ".txt")) 790 { 791 // load entities form text file 792 loadres = loadSceneASCII(fn, mSceneMgr->getRootSceneNode(), i); 793 } 794 else 795 { 796 loadres = false; 797 } 798 799 // result is true only if all files have been succesfully loaded 800 result = result ? loadres : false; 801 } 795 802 796 803 return result; … … 802 809 IVReader * mIVReader = new IVReader(); 803 810 804 if ( 1)811 if (0) 805 812 { 806 813 String logFilename = "IVLog" + Ogre::StringConverter().toString(index) + ".log"; … … 823 830 return true; 824 831 } 825 826 return false; 827 } 832 else 833 { 834 OGRE_DELETE(mIVReader); 835 836 return false; 837 } 838 } 839 840 //----------------------------------------------------------------------- 841 bool KdTreeApp::loadSceneCfg(const String &filename, SceneNode *root, const int index) 842 { 843 // Set ambient light 844 mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); 845 // Create a light 846 Light* l = mSceneMgr->createLight("MainLight"); 847 l->setPosition(20,80,50); 848 849 // try to load world geometry defined in the cfg file 850 mSceneMgr -> setWorldGeometry( filename ); 851 852 // return true since we have no feedback from setWorldGeometry 853 return true; 854 } 855 856 #define MAX_BUF_SIZE 1024 857 858 //----------------------------------------------------------------------- 859 bool KdTreeApp::loadSceneASCII(const String &filename, SceneNode *root, const int index) 860 { 861 typedef std::map<std::string, std::string> EntMeshMap; 862 typedef std::vector<std::string> Line; 863 864 std::ifstream read; 865 read.open(filename.c_str()); 866 if (read.is_open()) 867 { 868 char buf[MAX_BUF_SIZE]; 869 Line line; 870 std::stringstream s; 871 std::string node, ent, mesh; 872 Vector3 pos; 873 Quaternion or; 874 Vector3 scale; 875 int count; 876 EntMeshMap emm; 877 878 // the node which is parent to all entities 879 SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); 880 881 while (!read.eof()) 882 { 883 line.clear(); 884 memset(buf, 0, MAX_BUF_SIZE); 885 read.getline(buf, MAX_BUF_SIZE); 886 splitFilenames(std::string(buf), line); 887 if (line.size() < 5) 888 continue; 889 // see if node not empty 890 s << line[4]; 891 s >> count; 892 s.clear(); 893 if (count > 0) 894 { 895 // read info 896 node = line[0]; 897 s << line[1]; 898 s >> pos.x >> pos.y >> pos.z; 899 s.clear(); 900 s << line[2]; 901 s >> or.x >> or.y >> or.z >> or.w; 902 s.clear(); 903 s << line[3]; 904 s >> scale.x >> scale.y >> scale.z; 905 s.clear(); 906 for (int i = 5; i < 5 + count; i ++) 907 { 908 s << line[i]; 909 s >> ent >> mesh; 910 s.clear(); 911 emm[ent] = mesh; 912 } 913 // build node 914 SceneNode *newnode = anchor->createChildSceneNode(node, pos, or); 915 newnode->setScale(scale); 916 for (EntMeshMap::iterator emmit = emm.begin(); emmit != emm.end(); emmit ++) 917 { 918 Entity * entity = mSceneMgr->createEntity(emmit->first, emmit->second); 919 newnode->attachObject(entity); 920 } 921 emm.clear(); 922 } 923 924 925 } 926 927 return true; 928 } 929 else 930 { 931 return false; 932 } 933 } 934 935 //----------------------------------------------------------------------- 936 bool KdTreeApp::saveSceneASCII(const String& filename, SceneNode *entityroot) 937 { 938 // find all entities under node entityroot and store their name, position 939 //and orientation to a test file 940 std::ofstream write; 941 write.open(filename.c_str()); 942 if (write.is_open()) 943 { 944 NodeList list; 945 addNodesToList(entityroot, list); 946 947 std::string fs = ";", rs = "\n"; 948 std::string entnames; 949 int entcount; 950 951 for (NodeList::iterator it = list.begin(); it != list.end(); it ++) 952 { 953 // fist dump info about node (name, position, orientation, scale) 954 SceneNode * node = *it; 955 write << node->getName() << fs << 956 StringConverter::toString(node->getPosition()) << fs << 957 StringConverter::toString(node->getOrientation()) << fs << 958 StringConverter::toString(node->getScale()) << fs; 959 960 entcount = 0; 961 entnames = ""; 962 963 SceneNode::ObjectIterator objIt = node->getAttachedObjectIterator(); 964 965 while (objIt.hasMoreElements()) 966 { 967 MovableObject *movable = objIt.getNext(); 968 if (movable->getMovableType() == "Entity") 969 { 970 Entity *ent = static_cast<Entity *>(movable); 971 entcount++; 972 entnames += fs + ent->getName() + " " + ent->getMesh()->getName(); 973 974 } 975 } 976 977 // now dump entity count and names 978 write << entcount << entnames << rs; 979 } 980 981 write.close(); 982 return true; 983 } 984 else 985 { 986 return false; 987 } 988 989 } 990 991 void KdTreeApp::addNodesToList(SceneNode* node, NodeList& list) 992 { 993 //// check if node has entities 994 //bool entfound = false; 995 996 //SceneNode::ObjectIterator objIt = node->getAttachedObjectIterator(); 997 //while (objIt.hasMoreElements()) 998 //{ 999 // MovableObject *movable = objIt.getNext(); 1000 // if (movable->getMovableType() == "Entity") 1001 // entfound = true; 1002 //} 1003 1004 //// if yes, add to list 1005 //if (entfound) 1006 list.push_back(node); 1007 1008 // check if node has children and add them to list 1009 SceneNode::ChildNodeIterator childIt = node->getChildIterator(); 1010 while (childIt.hasMoreElements()) 1011 { 1012 SceneNode *child = static_cast<SceneNode *>(childIt.getNext()); 1013 addNodesToList(child, list); 1014 } 1015 } 1016 828 1017 829 1018 /**********************************************************************/ -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1274 r1285 4 4 #include <OgrePanelOverlayElement.h> 5 5 #include "TestKdTreeAppListener.h" 6 #include "TestKdTree.h" 6 7 #include <windows.h> 7 8 … … 543 544 } 544 545 546 if (mInputDevice->isKeyDown(KC_F7) && mTimeUntilNextToggle <= 0) 547 { 548 SceneNode *entnode = mSceneMgr->getSceneNode("AnchorNode"); 549 if (!mOptions.myApp->saveSceneASCII(mOptions.mSceneOutfileName, entnode)) 550 LogManager::getSingleton().logMessage( 551 "##Error##: Failed to save scene to " + mOptions.mSceneOutfileName); 552 mTimeUntilNextToggle = 0.5; 553 } 554 545 555 if (mInputDevice->isKeyDown(KC_F9) && mTimeUntilNextToggle <= 0) 546 556 {
Note: See TracChangeset
for help on using the changeset viewer.