// // Create the 3d scene: call vtlib to load the terrain and prepare for // user interaction. // bool App::CreateScene() { // Get a handle to the vtScene - one is already created for you vtScene *pScene = vtGetScene(); // Look up the camera m_pCamera = pScene->GetCamera(); m_pCamera->SetHither(10); m_pCamera->SetYon(100000); // The terrain scene will contain all the terrains that are created. m_ts = new vtTerrainScene; // Set the global data path vtStringArray paths; paths.push_back(vtString("../Data/")); paths.push_back(vtString("Data/")); vtSetDataPath(paths); // Begin creating the scene, including the sun and sky vtGroup *pTopGroup = m_ts->BeginTerrainScene(); // Tell the scene graph to point to this terrain scene pScene->SetRoot(pTopGroup); // Create a new vtTerrain, read its paramters from a file vtTerrain *pTerr = new vtTerrain; pTerr->SetParamFile("Data/Simple.xml"); pTerr->LoadParams(); // Add the terrain to the scene, and contruct it m_ts->AppendTerrain(pTerr); if (!m_ts->BuildTerrain(pTerr)) { printf("Terrain creation failed.\n"); return false; } m_ts->SetCurrentTerrain(pTerr); // Create a navigation engine to move around on the terrain // Get flight speed from terrain parameters float fSpeed = pTerr->GetParams().GetValueFloat(STR_NAVSPEED); vtTerrainFlyer *pFlyer = new vtTerrainFlyer(fSpeed); pFlyer->SetTarget(m_pCamera); pFlyer->SetHeightField(pTerr->GetHeightField()); pScene->AddEngine(pFlyer); // Minimum height over terrain is 100 m vtHeightConstrain *pConstrain = new vtHeightConstrain(100); pConstrain->SetTarget(m_pCamera); pConstrain->SetHeightField(pTerr->GetHeightField()); pScene->AddEngine(pConstrain); #if 0 #include "C:/Dev/vtlibTests.cpp" #endif return true; }
Vehicle *VehicleManager::CreateVehicle(const char *szType, const RGBf &cColor) { vtContentManager3d &con = vtGetContent(); osg::Node *node = con.CreateNodeFromItemname(szType); if (!node) return NULL; Vehicle *v = CreateVehicleFromNode(node, cColor); if (v) v->setName(vtString("Vehicle-") + szType); return v; }
// Methods static PyObject* vtpSimple_init(PyObject* self, PyObject* args) { // Would be usefule to include a parameter for the type of flyer const char *sourcefile, *datadir, *debugfile; if (!PyArg_ParseTuple(args, "sss", &sourcefile, &datadir, &debugfile)) return NULL; m_pTerrainScene = NULL; vtGetScene()->Init(); VTSTARTLOG(debugfile); // Get a handle to the vtScene - one is already created for you vtScene *pScene = vtGetScene(); // Look up the camera vtCamera *pCamera = pScene->GetCamera(); pCamera->SetHither(10); pCamera->SetYon(100000); // The terrain scene will contain all the terrains that are created. m_pTerrainScene = new vtTerrainScene; // Set the global data path vtStringArray paths; paths.push_back(vtString(datadir)); pScene->SetDataPath(paths); // Begin creating the scene, including the sun and sky vtGroup *pTopGroup = m_pTerrainScene->BeginTerrainScene(); // Tell the scene graph to point to this terrain scene pScene->SetRoot(pTopGroup); // Create a new vtTerrain, read its paramters from a file vtTerrain *pTerr = new vtTerrain; pTerr->SetParamFile(sourcefile); pTerr->LoadParams(); // Add the terrain to the scene, and contruct it m_pTerrainScene->AppendTerrain(pTerr); if (!m_pTerrainScene->BuildTerrain(pTerr)) { printf("Couldn't create the terrain. Perhaps the elevation data file isn't in the expected location?\n"); Py_INCREF(Py_False); return Py_False; } m_pTerrainScene->SetCurrentTerrain(pTerr); // Create a navigation engine to move around on the terrain // Get flight speed from terrain parameters float fSpeed = pTerr->GetParams().GetValueFloat(STR_NAVSPEED); vtTerrainFlyer *pFlyer = new vtTerrainFlyer(fSpeed); pFlyer->SetTarget(pCamera); pFlyer->SetHeightField(pTerr->GetHeightField()); pScene->AddEngine(pFlyer); // Minimum height over terrain is 100 m vtHeightConstrain *pConstrain = new vtHeightConstrain(100); pConstrain->SetTarget(pCamera); pConstrain->SetHeightField(pTerr->GetHeightField()); pScene->AddEngine(pConstrain); for (int i = 0; i < 512; i++) m_pbKeyState[i] = false; vtGetScene()->SetKeyStates(m_pbKeyState); printf("Done creating scene.\n"); Py_INCREF(Py_True); return Py_True; }
int vtUnzip::Extract(bool bFullPath, bool bOverwrite, const char *lpszDst, bool progress_callback(int)) { int iCount = 0; int iTotal = GetGlobalCount(); bool bOK = true; for (bool bContinue = GoToFirstFile(); bContinue; bContinue = GoToNextFile()) { char szFileName[MAX_PATH]; unz_file_info info; bOK = GetCurrentFileInfo(&info, szFileName, MAX_PATH); if (!bOK) break; vtString src_filename = szFileName; const char *short_fname = (const char *)src_filename; for (const char *p = short_fname; (*p) != '\0'; p++) { if (((*p)=='/') || ((*p)=='\\')) { short_fname = p+1; } } vtString short_filename = short_fname; if ((*short_filename)=='\0') { if (bFullPath) { VTLOG("creating directory: %s\n", (const char *)src_filename); vtCreateDir(src_filename); } } else { bOK = OpenCurrentFile(); if (bOK) { vtString write_filename; write_filename = vtString(lpszDst) + (bFullPath ? src_filename : short_filename); vtString strResult; VTLOG("Extracting %s ...", (const char *) write_filename); if (ExtractAccept(write_filename, bOverwrite)) { FILE* file = vtFileOpen(write_filename, "wb"); bool bWrite = (file != NULL); if (bWrite) { char buf[4096]; bWrite = ExtractCurrentFile(file, buf, 4096); fclose(file); } if (bWrite) { vtUnzip::change_file_date(write_filename,info.dosDate, info.tmu_date); iCount++; if (progress_callback != NULL) { progress_callback(iCount * 99 / iTotal); } } else { m_error_count++; OnError(write_filename); } strResult = bWrite ? "ok" : "failed"; } else { strResult = "skipped"; } VTLOG(" %s\n", (const char *) strResult); CloseCurrentFile(); } } } if (bOK) return iCount; else return -1; }