[Gcblue-commits] gcb_wx/src/sim Game.cpp,1.93,1.94 tc3DViewer.cpp,1.34,1.35 tcGameObject.cpp,1.20,1.
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-09-06 01:08:16
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11943/src/sim Modified Files: Game.cpp tc3DViewer.cpp tcGameObject.cpp tcGoalTracker.cpp tcMapView.cpp tcPlatformObject.cpp tcSimState.cpp Log Message: Index: tcSimState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSimState.cpp,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** tcSimState.cpp 5 Sep 2004 02:38:45 -0000 1.52 --- tcSimState.cpp 6 Sep 2004 01:08:04 -0000 1.53 *************** *** 1894,1904 **** } /********************************************************************/ ! unsigned tcSimState::GetAlliancePlatforms(tnPoolIndex *aaKeyList, unsigned anMaxLength, int anAlliance) { tcGameObject *pGameObj; ! tnPoolIndex cmappos = maPlatformState.GetStartPosition(); ! tnPoolIndex nSize = maPlatformState.GetCount(); ! tnPoolIndex nKey; ! tnPoolIndex nListIndex=0; for (int i=0;(i<nSize)&&(nListIndex<(int)anMaxLength);i++) --- 1894,1904 ---- } /********************************************************************/ ! unsigned tcSimState::GetAlliancePlatforms(long *aaKeyList, unsigned anMaxLength, int anAlliance) { tcGameObject *pGameObj; ! long cmappos = maPlatformState.GetStartPosition(); ! long nSize = maPlatformState.GetCount(); ! long nKey; ! long nListIndex=0; for (int i=0;(i<nSize)&&(nListIndex<(int)anMaxLength);i++) Index: tcGameObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcGameObject.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** tcGameObject.cpp 9 Aug 2004 02:35:16 -0000 1.20 --- tcGameObject.cpp 6 Sep 2004 01:08:04 -0000 1.21 *************** *** 151,154 **** --- 151,170 ---- } + /** + * Uses 3D model for size info (diameter of bounding sphere) + * @return largest dimension of object in meters or 0 if no model available + */ + float tcGameObject::GetSpan() + { + if (model) + { + return 2.0f*model->GetRadius(); + } + else + { + return 0; + } + } + tsGeoPoint tcGameObject::RelPosToLatLonAlt(const tsRelativePosition& rel_pos) const { Index: Game.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/Game.cpp,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** Game.cpp 5 Sep 2004 02:38:45 -0000 1.93 --- Game.cpp 6 Sep 2004 01:08:03 -0000 1.94 *************** *** 1,5 **** ! /** @file Game.cpp main application class ! ** ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. ** --- 1,6 ---- ! /** ! ** @file Game.cpp main application class ! */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. ** *************** *** 80,83 **** --- 81,85 ---- EVT_COMMAND(ID_SCENARIOSELECTVIEW, wxEVT_COMMAND_BUTTON_CLICKED , tcGame::SwitchToScenarioSelect) EVT_COMMAND(ID_MULTIPLAYERVIEW, wxEVT_COMMAND_BUTTON_CLICKED , tcGame::SwitchToNetwork) + EVT_COMMAND(ID_ENDGAME, wxEVT_COMMAND_BUTTON_CLICKED , tcGame::EndGame) EVT_COMMAND(ID_STARTGAME, wxEVT_COMMAND_BUTTON_CLICKED , tcGame::StartGame) EVT_COMMAND(ID_NEWHOOK, wxEVT_COMMAND_BUTTON_CLICKED, tcGame::NewHook) *************** *** 177,181 **** int nAlliances = 2; char buff[256]; ! for (int idx=0; idx < nAlliances; idx++) { --- 179,183 ---- int nAlliances = 2; char buff[256]; ! for (int idx=0; idx < nAlliances; idx++) { *************** *** 184,195 **** if (goalTracker->HasAllianceFailed(alliance)) { ! sprintf(buff, "Alliance %d LOST\n", alliance); ! infoConsole->Print(buff); } if (goalTracker->HasAllianceSucceeded(alliance)) { ! sprintf(buff, "Alliance %d WON\n", alliance); ! infoConsole->Print(buff); } } --- 186,207 ---- if (goalTracker->HasAllianceFailed(alliance)) { ! if (goalTracker->HasStatusChanged(alliance)) ! { ! sprintf(buff, "Alliance %d LOST\n", alliance); ! infoConsole->Print(buff); ! if (mcUserInfo.IsOwnAlliance(alliance)) DisplayOutcomeDialog(false); ! } } if (goalTracker->HasAllianceSucceeded(alliance)) { ! if (goalTracker->HasStatusChanged(alliance)) ! { ! sprintf(buff, "Alliance %d WON\n", alliance); ! infoConsole->Print(buff); ! DisplayOutcomeDialog(mcUserInfo.IsOwnAlliance(alliance)); ! } ! ! } } *************** *** 224,227 **** --- 236,272 ---- } + /** + * Displays a simple message box with won or lost message. + * Player is given the option to quit or continue. + */ + void tcGame::DisplayOutcomeDialog(bool playerWon) + { + std::stringstream outcomeMessage; + + if (playerWon) + { + outcomeMessage << "You have Won!\n"; + } + else + { + outcomeMessage << "You have Lost!\n"; + } + + goalTracker->WriteStatus(outcomeMessage, mcUserInfo.GetOwnAlliance()); + + wxMessageDialog confirmQuit(this, outcomeMessage.str().c_str(), + "Game over, quit game?", wxOK | wxCANCEL, wxDefaultPosition); + + if (confirmQuit.ShowModal() == wxID_OK) + { + wxCommandEvent command(wxEVT_COMMAND_BUTTON_CLICKED, ID_ENDGAME); + AddPendingEvent(command); + } + } + + void tcGame::EndGame(wxCommandEvent& event) + { + EndGame(); + } /** *************** *** 230,233 **** --- 275,280 ---- void tcGame::EndGame() { + if (meGameMode == GM_START) return; // ignore if game has not started + goalTracker->LogAllianceGoalStatus("log\\goal_results.txt", mcUserInfo.GetOwnAlliance()); *************** *** 251,254 **** --- 298,302 ---- simState->RandInit(); // generate new random scenario + HookRandomFriendly(); // reset time *************** *** 266,269 **** --- 314,324 ---- director->InitTest(); // load test event sequence (for random scen) + // set viewer back to object display mode + viewer->SetTerrainActive(false); + viewer->SetClearMode(1); // depth clearing + viewer->SetText(""); + + size3D = MODE3D_START; + Update3DSize(); // switch mode back to start *************** *** 294,297 **** --- 349,362 ---- scenarioSelectView->SetActive(false); + viewer->SetTerrainActive(true); + viewer->SetClearMode(2); // depth and color buffer clearing + viewer->ClearDefaultTextObjects(); + + tcString s; + s.Format("Starting scenario: %s",simState->msScenarioInfo.mzName); + ConsoleMessage(s.GetBuffer()); + + simState->PrintToFile("log\\simstate_text.txt"); + meGameMode = GM_PLAY; meScreenMode = TACTICAL; *************** *** 361,365 **** r.height = mnHeight-mnBottomMargin; } ! else // size3D = MODE3D_FULL { r.x = 0; --- 426,430 ---- r.height = mnHeight-mnBottomMargin; } ! else if (size3D == MODE3D_FULL) { r.x = 0; *************** *** 368,371 **** --- 433,441 ---- r.height = mnHeight; } + else // (size3D == MODE3D_START) + { + r = wxRect(startViewerPosition, startViewerSize); + } + viewer->Freeze(); viewer->SetSize(r); *************** *** 470,473 **** --- 540,545 ---- InitializeDirector(); pythonInterface->AttachDirector(director); + + InitSim(); } catch(std::string s) *************** *** 486,489 **** --- 558,562 ---- /* ** Miscellaneous startup * **/ simState->RandInit(); + HookRandomFriendly(); } catch(std::string s) *************** *** 533,543 **** smallViewerSize = wxSize(380, 200); ! viewer = new tc3DViewer(glCanvas, smallViewerPosition, smallViewerSize); viewer->SetActive(false); viewer->Show(FALSE); viewer->Freeze(); mb3DActive = false; ! size3D = MODE3D_SMALL; } --- 606,625 ---- smallViewerSize = wxSize(380, 200); ! startViewerSize = wxSize(mnWidth/2, mnWidth/4); ! startViewerPosition = wxPoint(mnWidth - startViewerSize.x, ! mnHeight - startViewerSize.y); ! ! ! viewer = new tc3DViewer(glCanvas, startViewerPosition, startViewerSize); viewer->SetActive(false); + viewer->SetTerrainActive(false); + viewer->SetClearMode(1); // depth clearing + viewer->SetText(""); + viewer->Show(FALSE); viewer->Freeze(); mb3DActive = false; ! size3D = MODE3D_START; } *************** *** 897,901 **** tcCustomControl::InitGdi(); ! return InitSim(); } --- 979,989 ---- tcCustomControl::InitGdi(); ! ! wxASSERT(infoConsole); ! pythonInterface->AttachConsole(infoConsole); ! mcGameView.AttachObjectControl(objectControl); ! ! ! return true; } *************** *** 928,933 **** bool tcGame::InitSim() { - tcString s; - simState->AttachMapData(&mcMapData); simState->AttachPythonInterface(pythonInterface); --- 1016,1019 ---- *************** *** 935,947 **** simState->AttachCommandInterface(&mcCommandQueue); ! s.Format("Starting scenario: %s",simState->msScenarioInfo.mzName); ! ! ConsoleMessage(s.GetBuffer()); ! ! simState->PrintToFile("log\\simstate_text.txt"); - wxASSERT(infoConsole); wxASSERT(director); - pythonInterface->AttachConsole(infoConsole); pythonInterface->AttachSensorMap(simState->mcSensorMap.GetMap(mcUserInfo.GetOwnAlliance())); pythonInterface->AttachCommandQueue(&mcCommandQueue); --- 1021,1027 ---- simState->AttachCommandInterface(&mcCommandQueue); ! wxASSERT(director); pythonInterface->AttachSensorMap(simState->mcSensorMap.GetMap(mcUserInfo.GetOwnAlliance())); pythonInterface->AttachCommandQueue(&mcCommandQueue); *************** *** 952,956 **** mcGameView.AttachUserInfo(&mcUserInfo); mcGameView.AttachOptions(tcOptions::Get()); - mcGameView.AttachObjectControl(objectControl); viewer->AttachSimState(simState); --- 1032,1035 ---- *************** *** 959,964 **** //tcSound::Get()->PlayEffect(SEFFECT_WELCOME); - HookSomethingFriendly(); - return true; } --- 1038,1041 ---- *************** *** 1007,1014 **** size3D = MODE3D_MEDIUM; } ! else // state == 3 { size3D = MODE3D_FULL; } Update3DSize(); } --- 1084,1095 ---- size3D = MODE3D_MEDIUM; } ! else if (state == 3) { size3D = MODE3D_FULL; } + else // state == 4 + { + size3D = MODE3D_START; + } Update3DSize(); } *************** *** 1246,1250 **** break; } ! viewer->SetActive(false); viewer->Update(gameDateZulu); mpGraphicsEngine->RenderAll(); --- 1327,1382 ---- break; } ! viewer->SetActive(true); ! ! viewer->SetCameraAz(viewer->GetCameraAz() + 0.02f); ! static float cameraTime = 0; ! cameraTime += 0.03f; ! viewer->SetCameraEl(0.5f * sinf(0.1f*cameraTime)); ! ! if (!viewer->TextObjectExists(0)) ! { ! viewer->AddDefaultTextObjects(); ! } ! ! long hookID = tacticalMap->GetHookID(); ! if (tcGameObject* obj = simState->GetObject(hookID)) ! { ! viewer->SetCameraRange(1.2f * obj->GetSpan()); ! wxString description; ! description = wxString::Format("%s\n%s", obj->mzClass.mz, obj->mzUnit.mz); ! ! wxString launcherDescription; ! wxString sensorDescription; ! if (tcPlatformObject* plat = dynamic_cast<tcPlatformObject*>(obj)) ! { ! launcherDescription = plat->GetLauncherDescription(); ! sensorDescription = plat->GetSensorDescription(); ! } ! else ! { ! launcherDescription = "No weapons\n"; ! sensorDescription = "No sensors\n"; ! } ! ! viewer->UpdateTextObject(2, description.c_str()); ! ! viewer->UpdateTextObject(0, launcherDescription.c_str()); ! viewer->UpdateTextObject(1, sensorDescription.c_str()); ! } ! else ! { ! HookRandomFriendly(); ! } ! ! ! ! if (cameraTime > 7) ! { ! cameraTime = 0; ! HookRandomFriendly(); ! } ! ! ! viewer->Update(gameDateZulu); mpGraphicsEngine->RenderAll(); *************** *** 1656,1667 **** * Used to avoid blank 3D screen in rand scenario */ ! void tcGame::HookSomethingFriendly() { ! long id; int ownAlliance = mcUserInfo.GetOwnAlliance(); ! simState->GetAlliancePlatforms(&id, 1, ownAlliance); ! NewHook(id); } --- 1788,1801 ---- * Used to avoid blank 3D screen in rand scenario */ ! void tcGame::HookRandomFriendly() { ! const unsigned maxPlats = 32; ! long id[maxPlats]; int ownAlliance = mcUserInfo.GetOwnAlliance(); ! unsigned count = simState->GetAlliancePlatforms(&id[0], maxPlats, ownAlliance); ! unsigned idx = rand() % count; ! NewHook(id[idx]); } *************** *** 1823,1833 **** * Updates member objects with new hook ID. * hookID = -1 is used to clear the hooked obj */ void tcGame::NewHook(long hookID) { tacticalMap->SetHookID(hookID); ! hookInfo->SetHookID(hookID); ! oobView->SetHookID(hookID); ! objectControl->SetHookID(hookID); viewer->SetHookID(hookID); --- 1957,1969 ---- * Updates member objects with new hook ID. * hookID = -1 is used to clear the hooked obj + * This was modified to check for null objects so that + * it works when called in start screen mode. */ void tcGame::NewHook(long hookID) { tacticalMap->SetHookID(hookID); ! if (hookInfo) hookInfo->SetHookID(hookID); ! if (oobView) oobView->SetHookID(hookID); ! if (objectControl) objectControl->SetHookID(hookID); viewer->SetHookID(hookID); *************** *** 2282,2300 **** } // synch button bar state to options, call when options are changed ! void tcGame::SyncButtonBars(void) { maButtonBar[1].mnCurrentButton = (mcOptions.mbUseNTDS) ? 0 : 1; } ! void tcGame::Update3DMode(void) { ! if (!mb3DActive) { tacticalMap->SetActive(true); mp3DSurface->mbActive = false; maButtonBar[2].mnCurrentButton = 2; } ! else { mp3DSurface->mbActive = true; ! if (mb3DSmall) { mrect3D = mrect3DSmall; mp3DSurface->mrectWindow = mrect3D; --- 2418,2441 ---- } // synch button bar state to options, call when options are changed ! void tcGame::SyncButtonBars() ! { maButtonBar[1].mnCurrentButton = (mcOptions.mbUseNTDS) ? 0 : 1; } ! void tcGame::Update3DMode() ! { ! if (!mb3DActive) ! { tacticalMap->SetActive(true); mp3DSurface->mbActive = false; maButtonBar[2].mnCurrentButton = 2; } ! else ! { mp3DSurface->mbActive = true; ! if (mb3DSmall) ! { mrect3D = mrect3DSmall; mp3DSurface->mrectWindow = mrect3D; *************** *** 2302,2306 **** maButtonBar[2].mnCurrentButton = 0; } ! else { mrect3D = mrectMap; mp3DSurface->mrectWindow = mrect3D; --- 2443,2448 ---- maButtonBar[2].mnCurrentButton = 0; } ! else ! { mrect3D = mrectMap; mp3DSurface->mrectWindow = mrect3D; *************** *** 2313,2318 **** ! // change virtual base class function in CommandInterface if this is changed ! void tcGame::ProcessCommand(teGameCommand aeCmd, float afData, long anData, int anData2) { static float sfData; static long snData; --- 2455,2463 ---- ! /** ! * change virtual base class function in CommandInterface if this is changed ! */ ! void tcGame::ProcessCommand(teGameCommand aeCmd, float afData, long anData, int anData2) ! { static float sfData; static long snData; Index: tcMapView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcMapView.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** tcMapView.cpp 16 Aug 2004 01:43:31 -0000 1.31 --- tcMapView.cpp 6 Sep 2004 01:08:04 -0000 1.32 *************** *** 1629,1633 **** // search for hook ! fHookDistance = mfScaleX_radppel*16.0f; // 16 pixels fMinDistance = 1e15f; nMinID = NULL_INDEX; --- 1629,1633 ---- // search for hook ! fHookDistance = mfScaleX_radppel*24.0f; // 24 pixels fMinDistance = 1e15f; nMinID = NULL_INDEX; *************** *** 1838,1842 **** bool isAltDown = event.AltDown(); ! bool noDrag = (buttonDownPoint == buttonUpPoint); if (noDrag) --- 1838,1845 ---- bool isAltDown = event.AltDown(); ! int absDistance = abs(buttonDownPoint.x - buttonUpPoint.x) + ! abs(buttonDownPoint.y - buttonUpPoint.y); ! ! bool noDrag = absDistance <= 6; if (noDrag) Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** tcPlatformObject.cpp 9 Aug 2004 02:35:16 -0000 1.28 --- tcPlatformObject.cpp 6 Sep 2004 01:08:04 -0000 1.29 *************** *** 284,287 **** --- 284,313 ---- /** + * @return description of launchers for display + */ + wxString tcPlatformObject::GetLauncherDescription() + { + wxString description; + + unsigned nLaunchers = mcLauncherState.GetLauncherCount(); + for (unsigned n=0; n < nLaunchers; n++) + { + tcLauncher* launcher = GetLauncher(n); + description += wxString::Format("%s, %d x %s\n", + launcher->mpLauncherDBObj->mzClass.mz, + launcher->mnCurrent, + launcher->mpChildDBObj->mzClass.mz); + } + + if (nLaunchers == 0) + { + description = "No weapons\n"; + } + + return description; + } + + + /** * */ *************** *** 300,303 **** --- 326,352 ---- /** + * @return description of sensors for display + */ + wxString tcPlatformObject::GetSensorDescription() + { + wxString description; + + unsigned nSensors = GetSensorCount(); + for (unsigned n=0; n < nSensors; n++) + { + const tcSensorState* sensor = GetSensor(n); + description += wxString::Format("%s\n", + sensor->mpDBObj->mzClass.mz); + } + + if (nSensors == 0) + { + description = "No sensors\n"; + } + + return description; + } + + /** * consider all active (mbActive) sensors */ Index: tcGoalTracker.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcGoalTracker.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tcGoalTracker.cpp 5 Sep 2004 02:38:45 -0000 1.5 --- tcGoalTracker.cpp 6 Sep 2004 01:08:04 -0000 1.6 *************** *** 47,50 **** --- 47,51 ---- delete allianceGoals[i]; allianceGoals[i] = new tcGoal(); // set default goal (always unresolved) (leaks memory) + previousGoalStatus[i] = tcGoal::UNRESOLVED; } } *************** *** 96,99 **** --- 97,110 ---- /** + * @return true if goalState for alliance changed during last update + */ + bool tcGoalTracker::HasStatusChanged(int alliance) + { + tcGoal* allianceGoal = allianceGoals[alliance]; + return (allianceGoal && + (allianceGoal->goalState != previousGoalStatus[alliance])); + } + + /** * Writes goal status out to file <fileName>. This should * be called at least once at the end of the game. *************** *** 133,137 **** { tcGoal* allianceGoal = allianceGoals[i]; ! if (allianceGoal) allianceGoal->Update(); } } --- 144,152 ---- { tcGoal* allianceGoal = allianceGoals[i]; ! if (allianceGoal) ! { ! previousGoalStatus[i] = allianceGoal->goalState; ! allianceGoal->Update(); ! } } } *************** *** 162,165 **** tcGoalTracker::~tcGoalTracker() { ! Clear(); } \ No newline at end of file --- 177,188 ---- tcGoalTracker::~tcGoalTracker() { ! // should use map iterator here ! for(int i=0;i<MAX_ALLIANCES;i++) ! { ! if (allianceGoals[i]) ! { ! delete allianceGoals[i]; ! } ! } ! } \ No newline at end of file Index: tc3DViewer.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tc3DViewer.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** tc3DViewer.cpp 9 Aug 2004 02:35:16 -0000 1.34 --- tc3DViewer.cpp 6 Sep 2004 01:08:04 -0000 1.35 *************** *** 1,6 **** ! /* ! ** tc3DViewer.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- ! /** ! ** @file tc3DViewer.cpp ! */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 39,52 **** #include <osg/MatrixTransform> #include <osg/PolygonMode> #include <osgDB/Registry> #include <osgDB/ReadFile> ! #include <osg/PositionAttitudeTransform> #include <osgUtil/CullVisitor> #include <osgUtil/SceneView> #include <osgUtil/UpdateVisitor> ! #include <osgText/Font> ! #include <osgText/Text> ! #include <osgParticle/ParticleSystem> ! #include <osgParticle/ParticleSystemUpdater> #include "ObjectUpdater.h" --- 39,54 ---- #include <osg/MatrixTransform> #include <osg/PolygonMode> + #include <osg/PositionAttitudeTransform> #include <osgDB/Registry> #include <osgDB/ReadFile> ! #include <osgParticle/ParticleSystem> ! #include <osgParticle/ParticleSystemUpdater> ! #include <osgText/Font> ! #include <osgText/Text> #include <osgUtil/CullVisitor> #include <osgUtil/SceneView> #include <osgUtil/UpdateVisitor> ! ! #include "ObjectUpdater.h" *************** *** 285,288 **** --- 287,311 ---- } + /** + * @param modeCode 0 - no clearing, 1 - depth only, 2 - depth and color buffers + */ + void tc3DViewer::SetClearMode(int modeCode) + { + osgUtil::RenderStage* stage = sceneView->getRenderStage(); + + if (modeCode == 1) + { + stage->setClearMask(GL_DEPTH_BUFFER_BIT); + } + else if (modeCode == 2) + { + stage->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + } + else + { + stage->setClearMask(0); + } + } + void tc3DViewer::SetGameTime(double t) { *************** *** 313,316 **** --- 336,340 ---- } + void tc3DViewer::SetPolarOffset(float az, float el, float range) { *************** *** 322,325 **** --- 346,373 ---- /** + * @param az camera az in radians for lookat modes + */ + void tc3DViewer::SetCameraAz(float az) + { + cameraAz = az; + } + + /** + * @param el camera el in radians for lookat modes + */ + void tc3DViewer::SetCameraEl(float el) + { + cameraEl = el; + } + + /** + * @param range_m camera range in meters for lookat modes + */ + void tc3DViewer::SetCameraRange(float range_m) + { + cameraRange = range_m; + } + + /** * Set the origin (0,0) of 3D world coordinates and * update lonToGridX and gridXToLon scale factors which *************** *** 335,339 **** gridXToLon = 1/lonToGridX; ! terrainManager->SetOrigin(lon, lat); } --- 383,390 ---- gridXToLon = 1/lonToGridX; ! if (isTerrainActive) ! { ! terrainManager->SetOrigin(lon, lat); ! } } *************** *** 561,583 **** rootnode->addChild(orthoProjection.get()); ! // tcParticleEffect* ps1 = new tcParticleEffect(); ! // ps1->AddToSceneGraph(rootnode.get()); ! ! //osgParticle::ParticleSystem *ps1 = create_simple_particle_system(rootnode.get()); ! ! // Now that the particle systems and all other related objects have been ! // created, we have to add an "updater" node to the scene graph. This node ! // will react to cull traversal by updating the specified particles system. ! ! //osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater; ! //psu->addParticleSystem(ps1); ! ! // add the updater node to the scene graph ! //rootnode->addChild(psu); ! ! ! //particleSystemUpdater = new osgParticle::ParticleSystemUpdater; ! //tcParticleEffect::SetParticleSystemUpdater(particleSystemUpdater.get()); ! } --- 612,616 ---- rootnode->addChild(orthoProjection.get()); ! isTerrainActive = true; } *************** *** 911,930 **** //sceneView->setComputeNearFarMode(osgUtil::CullVisitor::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES); ! /* ! NO_CULLING = 0x0, ! VIEW_FRUSTUM_CULLING = 0x1, ! NEAR_PLANE_CULLING = 0x2, ! FAR_PLANE_CULLING = 0x4, ! SMALL_FEATURE_CULLING = 0x8, ! SHADOW_OCCLUSION_CULLING = 0x10, ! ENABLE_ALL_CULLING ! */ ! sceneView->setCullingMode( ! osg::CullStack::NO_CULLING ! //osg::CullStack::FAR_PLANE_CULLING ! // osg::CullStack::NEAR_PLANE_CULLING ! // osg::CullStack::VIEW_FRUSTUM_CULLING ! // osg::CullStack::SMALL_FEATURE_CULLING ! ); // set up the clear mask. --- 944,963 ---- //sceneView->setComputeNearFarMode(osgUtil::CullVisitor::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES); ! /* ! NO_CULLING = 0x0, ! VIEW_FRUSTUM_CULLING = 0x1, ! NEAR_PLANE_CULLING = 0x2, ! FAR_PLANE_CULLING = 0x4, ! SMALL_FEATURE_CULLING = 0x8, ! SHADOW_OCCLUSION_CULLING = 0x10, ! ENABLE_ALL_CULLING ! */ ! sceneView->setCullingMode( ! osg::CullStack::NO_CULLING ! // osg::CullStack::FAR_PLANE_CULLING ! // osg::CullStack::NEAR_PLANE_CULLING ! // osg::CullStack::VIEW_FRUSTUM_CULLING ! // osg::CullStack::SMALL_FEATURE_CULLING ! ); // set up the clear mask. *************** *** 1004,1007 **** --- 1037,1041 ---- viewerText->setFontResolution(32,32); viewerText->setText("TEST TEXT"); + osg::StateSet *textState = textGeode->getOrCreateStateSet(); *************** *** 1023,1026 **** --- 1057,1091 ---- } + /** + * Used to enable or disable terrain and sky + */ + void tc3DViewer::SetTerrainActive(bool state) + { + if (isTerrainActive == state) return; // ignore if state already set + + wxASSERT(terrainManager); + + osg::ref_ptr<osg::Node> terrainNode = terrainManager->GetTerrainNode().get(); + if (state) + { + rootnode->addChild(skyTransform.get()); + foggedObjects->addChild(terrainNode.get()); + foggedObjects->addChild(skyLights.get()); + // update terrain here with current origin since it isn't updated while inactive + terrainManager->SetOrigin(lonOrigin_rad, latOrigin_rad); + } + else + { + if (!rootnode->removeChild(skyTransform.get()) || + !foggedObjects->removeChild(terrainNode.get()) || + !foggedObjects->removeChild(skyLights.get())) + { + fprintf(stderr, "tc3DViewer::SetTerrainActive - " + "tried to remove non-existent child\n"); + } + } + isTerrainActive = state; + } + void tc3DViewer::SetText(const char *s) { *************** *** 1028,1031 **** --- 1093,1230 ---- } + /** + * @param positionCode: 0 - upper left, 1 - top center, 2 - bottom center + */ + void tc3DViewer::SetTextPosition(int positionCode) + { + if (!viewerText.valid()) return; + + + if (positionCode == 0) + { + viewerText->setPosition(osg::Vec3(20.0f,(float)mnHeight - 40.0f,0.0f)); + viewerText->setAlignment(osgText::Text::AlignmentType::LEFT_BASE_LINE); + } + else if (positionCode == 1) + { + viewerText->setPosition(osg::Vec3(0.5f * (float)mnWidth, + (float)mnHeight - 40.0f, 0.0f)); + viewerText->setAlignment(osgText::Text::AlignmentType::CENTER_CENTER); + } + else + { + viewerText->setPosition(osg::Vec3(0.5f * (float)mnWidth, + (float)40.0f, 0.0f)); + viewerText->setAlignment(osgText::Text::AlignmentType::CENTER_CENTER); + } + } + + void tc3DViewer::AddDefaultTextObjects() + { + osg::Vec3 upperLeft(20.0f, (float)mnHeight - 40.0f, 0.0f); + osg::Vec3 upperRight((float)mnWidth - 150.0f, (float)mnHeight - 40.0f, 0.0f); + osg::Vec3 bottomCenter(0.5 * (float)mnWidth, 40.0f, 0.0f); + osg::Vec4 color(0.4f, 0.4f, 0.8f, 0.8f); + + AddTextObject(0, upperLeft, 12.0, color, + osgText::Text::AlignmentType::LEFT_BASE_LINE); + + AddTextObject(1, upperRight, 12.0, color, + osgText::Text::AlignmentType::LEFT_BASE_LINE); + + AddTextObject(2, bottomCenter, 16.0, osg::Vec4(0.9f, 0.9f, 0.7f, 0.9f), + osgText::Text::AlignmentType::CENTER_CENTER); + } + + void tc3DViewer::ClearDefaultTextObjects() + { + ClearTextObject(0); + ClearTextObject(1); + ClearTextObject(2); + } + + void tc3DViewer::AddTextObject(int key, const osg::Vec3& pos, float fontSize, + const osg::Vec4& color, + osgText::Text::AlignmentType alignment) + { + osgText::Text* text = new osgText::Text; + osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); + + text->setFont(font); + text->setColor(color); + text->setCharacterSize(fontSize, 1.2f); // font height, aspect ratio + text->setPosition(pos); + text->setLayout(osgText::Text::LEFT_TO_RIGHT); + text->setFontResolution(32,32); + text->setText(""); + text->setAlignment(alignment); + + textGeode->addDrawable(text); + + if (TextObjectExists(key)) + { + ClearTextObject(key); + fprintf(stderr, "tc3DViewer::AddTextObject - Replacing existing text obj\n"); + } + textMap[key] = text; + } + + void tc3DViewer::ClearTextObject(int key) + { + std::map<int,osgText::Text*>::iterator iter; + + iter = textMap.find(key); + if (iter == textMap.end()) + { + fprintf(stderr, "tc3DViewer::ClearTextObject - " + "Tried to clear non-existent text obj\n"); + return; + } + textGeode->removeDrawable(iter->second); + textMap.erase(iter); + } + + /** + * Not sure if destruction is done correctly here + */ + void tc3DViewer::ClearTextObjects() + { + std::map<int,osgText::Text*>::iterator iter; + + + for (iter = textMap.begin(); iter != textMap.end(); ++iter) + { + textGeode->removeDrawable(iter->second); + } + + textMap.clear(); + } + + /** + * @return true if text object matching key exists in map + */ + bool tc3DViewer::TextObjectExists(int key) + { + std::map<int,osgText::Text*>::const_iterator iter; + + iter = textMap.find(key); + return !(iter == textMap.end()); + } + + void tc3DViewer::UpdateTextObject(int key, const std::string& text) + { + std::map<int,osgText::Text*>::iterator iter; + + iter = textMap.find(key); + if (iter == textMap.end()) + { + fprintf(stderr, "tc3DViewer::UpdateTextObject - " + "Tried to update non-existent text obj\n"); + return; + } + iter->second->setText(text.c_str()); + } + + void tc3DViewer::Swap() { *************** *** 1073,1077 **** void tc3DViewer::Update(DateZulu& dateZulu) { ! static long lastHook = hookID; if (!simState) return; --- 1272,1276 ---- void tc3DViewer::Update(DateZulu& dateZulu) { ! static long lastHook = -1; if (!simState) return; *************** *** 1150,1153 **** --- 1349,1353 ---- isMouseDown = false; isActive = true; + isTerrainActive = false; isFrozen = false; viewWireframe = false; |