Changeset 1200 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 08/11/06 17:34:12 (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
r1195 r1200 74 74 bool loadSceneIV(const String &filename, SceneNode *root, const int index); 75 75 private: 76 void createMaterials(void); 76 77 std::string cat(std::string name, int x, int z) 77 78 { -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1195 r1200 131 131 132 132 FrameList mFrameList; 133 FrameList::iterator mCurrFrame; 134 Real mTimeRemaining; 133 135 134 136 AppState mAppState; 137 138 Overlay * mDemoOverlay; 139 OverlayElement * mDemoStatus; 135 140 136 141 void toggleRecord(); 137 142 void togglePlayback(); 143 // void resetPlayback(); 144 138 145 void saveFrameInfo(Real elapsedTime); 139 146 147 void setDemoOverlay(); 148 149 void saveFramesBinary(const String& filename); 150 void loadFramesBinary(const String& filename); 140 151 public: 141 152 void loadFrames(const String& filename); -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1195 r1200 101 101 void KdTreeApp::createScene(void) 102 102 { 103 createMaterials(); 104 103 105 Entity *deaths; 104 106 SceneNode *nodes; … … 370 372 } 371 373 374 void KdTreeApp::createMaterials() 375 { 376 MaterialPtr mat; 377 Technique * tech; 378 Pass * pass; 379 TextureUnitState * tex; 380 381 // create play button 382 mat = MaterialManager::getSingleton().create("KdTree/DemoPlayButton", "General"); 383 mat->setLightingEnabled(false); 384 tech = mat->getTechnique(0); 385 tech->setSceneBlending(SBT_TRANSPARENT_ALPHA); 386 tech->setDepthCheckEnabled(false); 387 pass = tech->getPass(0); 388 tex = pass->createTextureUnitState(); 389 tex->setTextureName("DemoPlayButton.png"); 390 391 // create record button 392 mat = MaterialManager::getSingleton().create("KdTree/DemoRecordButton", "General"); 393 mat->setLightingEnabled(false); 394 tech = mat->getTechnique(0); 395 tech->setSceneBlending(SBT_TRANSPARENT_ALPHA); 396 tech->setDepthCheckEnabled(false); 397 pass = tech->getPass(0); 398 tex = pass->createTextureUnitState(); 399 tex->setTextureName("DemoRecordButton.png"); 400 } 401 372 402 373 403 //----------------------------------------------------------------------- -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1195 r1200 2 2 #include <cstdlib> 3 3 4 #include <OgrePanelOverlayElement.h> 4 5 #include "TestKdTreeAppListener.h" 5 6 … … 129 130 MaterialManager::getSingleton().setDefaultAnisotropy(mAniso); 130 131 132 mDemoOverlay = 0; 133 mDemoStatus = 0; 134 131 135 initKdTreeOverlay(); 132 136 initStatsOverlay(); … … 134 138 showDebugOverlay(true); 135 139 136 loadFrames("demo-in.txt"); 140 setDemoOverlay(); 141 142 //loadFrames("demo-in.txt"); 143 loadFramesBinary("demo-in.bin"); 137 144 } 138 145 //----------------------------------------------------------------------- … … 150 157 // save demo 151 158 if (!mFrameList.empty()) 152 saveFrames("demo-out.txt"); 159 { 160 //saveFrames("demo-out.txt"); 161 saveFramesBinary("demo-out.bin"); 162 } 153 163 } 154 164 //----------------------------------------------------------------------- … … 942 952 } 943 953 944 if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys) 945 { 946 // one of the input modes is immediate, so update the movement vector 947 948 moveCamera(); 949 950 } 951 954 // demo playback - replace position with stored one 955 if (mAppState == AS_PLAYBACK) 956 { 957 // update time 958 mTimeRemaining -= evt.timeSinceLastFrame; 959 960 static FrameList::iterator lastFrame; 961 if (mCurrFrame == mFrameList.begin()) 962 lastFrame = mCurrFrame; 963 964 // advance to next stored frame 965 while (mTimeRemaining <= 0.0 && mCurrFrame != mFrameList.end()) 966 { 967 lastFrame = mCurrFrame; 968 ++ mCurrFrame; 969 mTimeRemaining += mCurrFrame->mElapsedTime; 970 } 971 972 // when reached last frame, reset and stop playback 973 if (mCurrFrame == mFrameList.end()) 974 { 975 togglePlayback(); 976 } 977 // interpolate position & orientation and modify move vectors 978 else 979 { 980 981 // interpolation factor 982 Real factor = 1.0 - mTimeRemaining / mCurrFrame->mElapsedTime; 983 984 // interpolate position and orientation 985 Vector3 pos = lastFrame->mPosition + 986 factor * (mCurrFrame->mPosition - lastFrame->mPosition); 987 988 Quaternion or = Quaternion::Slerp(factor, lastFrame->mOrientation, 989 mCurrFrame->mOrientation); 990 991 // update camera 992 mCamNode->setPosition(pos); 993 mCamNode->setOrientation(or); 994 995 // update viz camera 996 mTopCam->moveRelative(mVizCamTransVect); 997 if (mTopCamFollow) 998 { 999 Vector3 toppos = mTopCam->getPosition(); 1000 Vector3 campos = mCamNode->getPosition(); 1001 mTopCam->setPosition(Vector3::ZERO); 1002 mTopCam->setOrientation(Quaternion::IDENTITY); 1003 mTopCam->setPosition(campos.x, toppos.y, campos.z); 1004 mTopCam->pitch(Radian(-Math::HALF_PI)); 1005 } 1006 1007 } 1008 } 1009 else 1010 { 1011 if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys) 1012 { 1013 // one of the input modes is immediate, so update the movement vector 1014 1015 moveCamera(); 1016 1017 } 1018 } 952 1019 953 1020 //saveFrameInfo(evt.timeSinceLastFrame); … … 1024 1091 void KdTreeAppListener::toggleRecord() 1025 1092 { 1026 // TODO: overlay1093 // start recording 1027 1094 if (mAppState == AS_NORMAL) 1028 1095 { 1096 // change state 1029 1097 mAppState = AS_RECORD; 1030 } 1098 1099 // clear old recording 1100 mFrameList.clear(); 1101 } 1102 // stop recording 1031 1103 else if (mAppState == AS_RECORD) 1032 1104 { 1105 // change state 1033 1106 mAppState = AS_NORMAL; 1034 } 1107 1108 } 1109 // update display 1110 setDemoOverlay(); 1035 1111 } 1036 1112 … … 1038 1114 void KdTreeAppListener::togglePlayback() 1039 1115 { 1040 // TODO: overlay 1041 if (mAppState == AS_NORMAL) 1042 { 1116 static Vector3 pos; 1117 static Quaternion or; 1118 1119 // start playback 1120 if (mAppState == AS_NORMAL && !mFrameList.empty()) 1121 { 1122 // change state 1043 1123 mAppState = AS_PLAYBACK; 1044 } 1124 1125 // save old position 1126 pos = mCamNode->getPosition(); 1127 or = mCamNode->getOrientation(); 1128 1129 // reset demo 1130 mCurrFrame = mFrameList.begin(); 1131 mTimeRemaining = mCurrFrame->mElapsedTime; 1132 } 1133 // stop playback 1045 1134 else if (mAppState == AS_PLAYBACK) 1046 1135 { 1136 // change state 1047 1137 mAppState = AS_NORMAL; 1048 } 1049 } 1138 1139 // restore old position 1140 mCamNode->setPosition(pos); 1141 mCamNode->setOrientation(or); 1142 } 1143 1144 // update display 1145 setDemoOverlay(); 1146 } 1147 1148 //----------------------------------------------------------------------------- 1149 //void KdTreeAppListener::resetPlayback() 1150 //{ 1151 // if (!mFrameList.empty()) 1152 // { 1153 // mCurrFrame = mFrameList.begin(); 1154 // mTimeRemaining = mCurrFrame->mElapsedTime; 1155 // } 1156 //} 1050 1157 1051 1158 //----------------------------------------------------------------------------- … … 1083 1190 1084 1191 //----------------------------------------------------------------------------- 1192 void KdTreeAppListener::saveFramesBinary(const String& filename) 1193 { 1194 std::ofstream dest(filename.c_str(), std::ios_base::out | std::ios_base::binary); 1195 1196 if (!dest) 1197 { 1198 LogManager::getSingleton().logMessage("Failed to open file for saving demo: " + filename); 1199 return; 1200 } 1201 1202 FrameList::iterator it = mFrameList.begin(); 1203 FrameList::iterator end = mFrameList.end(); 1204 1205 size_t size = sizeof(Real); 1206 1207 // dump values 1208 while (it != end) 1209 { 1210 dest.write((char *)&it->mPosition.x, size); 1211 dest.write((char *)&it->mPosition.y, size); 1212 dest.write((char *)&it->mPosition.z, size); 1213 dest.write((char *)&it->mOrientation.w, size); 1214 dest.write((char *)&it->mOrientation.x, size); 1215 dest.write((char *)&it->mOrientation.y, size); 1216 dest.write((char *)&it->mOrientation.z, size); 1217 dest.write((char *)&it->mElapsedTime, size); 1218 ++ it; 1219 } 1220 1221 dest.close(); 1222 } 1223 1224 //----------------------------------------------------------------------------- 1085 1225 void KdTreeAppListener::loadFrames(const String& filename) 1086 1226 { … … 1121 1261 src.close(); 1122 1262 } 1263 1264 //----------------------------------------------------------------------------- 1265 void KdTreeAppListener::loadFramesBinary(const String& filename) 1266 { 1267 // open file 1268 std::ifstream src(filename.c_str(), std::ios_base::out | std::ios_base::binary); 1269 if (!src) 1270 { 1271 LogManager::getSingleton().logMessage("Failed to open file for reading demo: " + filename); 1272 return; 1273 } 1274 1275 // clear the list 1276 mFrameList.clear(); 1277 1278 size_t size = sizeof(Real); 1279 1280 Vector3 pos; 1281 Quaternion or; 1282 Real time; 1283 1284 while (!src.eof()) 1285 { 1286 src.read((char *)&pos.x, size); 1287 src.read((char *)&pos.y, size); 1288 src.read((char *)&pos.z, size); 1289 src.read((char *)&or.w, size); 1290 src.read((char *)&or.x, size); 1291 src.read((char *)&or.y, size); 1292 src.read((char *)&or.z, size); 1293 src.read((char *)&time, size); 1294 1295 mFrameList.push_back(FrameInfo(pos, or, time)); 1296 } 1297 1298 // HACK pop last frame, was doubled while reading 1299 mFrameList.pop_back(); 1300 1301 src.close(); 1302 } 1303 //----------------------------------------------------------------------------- 1304 void KdTreeAppListener::setDemoOverlay() 1305 { 1306 // init overlay if not present 1307 if (!mDemoOverlay || !mDemoStatus) 1308 { 1309 OGRE_DELETE(mDemoOverlay); 1310 OGRE_DELETE(mDemoStatus); 1311 1312 mDemoStatus = OverlayManager::getSingleton().createOverlayElement("Panel", "KdTree/DemoStatus"); 1313 mDemoStatus->setMetricsMode(GMM_PIXELS); 1314 mDemoStatus->setHorizontalAlignment(GHA_CENTER); 1315 mDemoStatus->setVerticalAlignment(GVA_TOP); 1316 mDemoStatus->setTop(5); 1317 mDemoStatus->setLeft(-16); 1318 mDemoStatus->setDimensions(32, 32); 1319 1320 mDemoOverlay = OverlayManager::getSingleton().create("KdTree/DemoOverlay"); 1321 mDemoOverlay->setZOrder(500); 1322 mDemoOverlay->add2D(static_cast<PanelOverlayElement *>(mDemoStatus)); 1323 } 1324 1325 switch(mAppState) 1326 { 1327 case AS_NORMAL: 1328 mDemoOverlay->hide(); 1329 break; 1330 case AS_PLAYBACK: 1331 mDemoStatus->setMaterialName("KdTree/DemoPlayButton"); 1332 mDemoOverlay->show(); 1333 break; 1334 case AS_RECORD: 1335 mDemoStatus->setMaterialName("KdTree/DemoRecordButton"); 1336 mDemoOverlay->show(); 1337 break; 1338 default: 1339 break; 1340 } 1341 1342 }
Note: See TracChangeset
for help on using the changeset viewer.