📄 teengine.cpp
字号:
* \sa sceneRoot, addNode(), removePatch() */void TeEngine::removeNode(SoNode *node){ if (sceneRoot->findChild(node) != -1) sceneRoot->removeChild(node);}//-----------------------------------------------------------------------------/** * Removes patch \a p and its seams from the scene. * * \param p Pointer to the patch; its graph is going to be removed from the * scene. * * \sa removeNode() */void TeEngine::removePatch(TePatch *p){ if (p) { // this should happen if camera is moving too fast and we want // to remove patch, that is not generated yet (it is scheduled) if (p->graph) removeNode(p->graph); for (int i=0; i<8; i++) { if (p->seamGraph[i]) removeNode(p->seamGraph[i]); } }}//-----------------------------------------------------------------------------/** * Sets HUD scene root. * * \param sep Selected HUD scene root. * * \sa HUDRoot, getHUDRoot() */void TeEngine::setHUDRoot(SoSeparator *sep){ HUDRoot = sep;}/** * Private attribute accessor. * * \return HUD scene root. * * \sa HUDRoot, setHUDRoot() */SoSeparator *TeEngine::getHUDRoot(){ return HUDRoot;}//-----------------------------------------------------------------------------/** * Sets camera to be used to observe the scene. * * \param c Camera. * * \sa sceneCamera, getSceneCamera() */void TeEngine::setSceneCamera(SoPerspectiveCamera *c){ sceneCamera = c;}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Camera used to observe the scene. * * \sa sceneCamera, setSceneCamera() */SoPerspectiveCamera *TeEngine::getSceneCamera(){ return sceneCamera;}//-----------------------------------------------------------------------------/** * Sets camera to be used to display the HUD. * * \param c Camera. * * \sa HUDCamera, getHUDCamera() */void TeEngine::setHUDCamera(SoPerspectiveCamera *c){ HUDCamera = c;}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Camera used to display the HUD. * * \sa HUDCamera, setHUDCamera() */SoPerspectiveCamera *TeEngine::getHUDCamera(){ return HUDCamera;}//-----------------------------------------------------------------------------/** * Documentation not available. * * \todo More detailed documentation. */TePatch* TeEngine::getPatch(const SbVec2f &pos, const int level, TePatch::PatchMissedPolicy policy){ // handle root == NULL if (!root) { if (policy == TePatch::DONT_CREATE) return NULL; root = new TePatch(this); SbVec2f size2(patch0Size/2.f); int i; if (level > 0) for (i=0; i<level; i++) size2 *= 2.f; else for (i=0; i>level; i--) size2 *= 0.5f; root->makeRoot(SbBox2f(pos-size2, pos+size2), this); rootLevel = level; return root; } return root->getPatch(pos, level, policy);}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Patch hierarchy root. * * \sa root */TePatch* TeEngine::getRootPatch(){ return root;}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Level of the patch hierarchy root. * * \sa rootLevel, getRootPatch() */int TeEngine::getRootLevel() const{ return rootLevel;}//-----------------------------------------------------------------------------/** * Documentation not available. * * \todo More detailed documentation. */void TeEngine::advanceRootToPos(const SbVec2f &pos){ if (!root) { root = new TePatch(this); SbVec2f size2(patch0Size/2.f); root->makeRoot(SbBox2f(pos-size2, pos+size2), this); rootLevel = 0; return; } while (!root->getArea().intersect(pos)) { const SbBox2f &rootArea = root->getArea(); SbVec2f min = rootArea.getMin(); SbVec2f max = rootArea.getMax(); float sizex,sizey; rootArea.getSize(sizex,sizey); if (pos[0] < rootArea.getMin()[0]) min[0] -= sizex; else max[0] += sizex; if (pos[1] < rootArea.getMin()[1]) min[1] -= sizey; else max[1] += sizey; TePatch *newRoot = new TePatch(this); newRoot->makeRoot(SbBox2f(min,max), this); TePatch::Direction d = TePatch::getDirectionXFromVec(rootArea.getCenter() - newRoot->getArea().getCenter()); assert(d != -1 && "This should never happen."); newRoot->setDetail(d,root); root = newRoot; rootLevel++; }}//----------------------------------------------------------------------------/** * Generates new height map of the given resolution. * * The appearance of the result can be influenced by choosing the generation * and filtering method before calling this function. Note, that all * generator parameters (including the random seed) can be set in order * to customize the process of generating the result. * * \param res Desired resolution of the map. * \return Pointer to the new height map object. * * \sa setCurrGen(), setCurrFilter(), TeGenerator */TeHeightMap* TeEngine::generateHMap(const SbVec2s &res){ TeHeightMap *tmp = new TeHeightMap(res); TeGenerator *g = NULL; switch (currGen) { case FAULT_FORMATION: g = &faultFormation; break; } g->setHMap(tmp); g->generate(); if (currFilter != NONE) { switch (currFilter) { case LINEAR: g = &linearFilter; break; } g->setHMap(tmp); g->generate(); } return tmp;}//-----------------------------------------------------------------------------/** * Generates new height map using fault-formation algorithm. * * This method is obsolete and should be removed. Use generateHMap() instead. * * \return Pointer to the new height map object. * * \todo This method is obsolete and should be removed. */TeHeightMap* TeEngine::generateHMapFF(){ return this->generateHMapFF(this->getHMapResolution());}//-----------------------------------------------------------------------------/** * Generates new height map using fault-formation algorithm. * * This method is obsolete and should be removed. Use generateHMap() instead. * * \param res Desired resolution of the map. * \return Pointer to the new height map object. * * \todo This method is obsolete and should be removed. */TeHeightMap* TeEngine::generateHMapFF(const SbVec2s &res){ return this->generateHMapFF(res, (unsigned int)time(NULL)+(rand()%100), 150, 0.05f, 2.0f);}//-----------------------------------------------------------------------------/** * Generates new height map using fault-formation algorithm. * * This method is obsolete and should be removed. Use generateHMap() instead. * * \param res Desired resolution of the map. * \param seed Random seed that defines terrain shape. * \param num_faults Number of faults to be generated (number of iterations). * \param min_delta Minimal fault height. * \param max_delta Maximal fault height. * \return Pointer to the new height map object. * * \todo This method is obsolete and should be removed. */TeHeightMap* TeEngine::generateHMapFF(const SbVec2s &res, const unsigned int seed, const int num_faults, const float min_delta, const float max_delta){ TeHeightMap *hmap = new TeHeightMap(res); hmap->generate_FaultFormation(seed, num_faults, min_delta, max_delta); return hmap;}//-----------------------------------------------------------------------------/** * Initializes the engine. * * Checks if all necessary attributes are set, generates initial patches and * creates HUD. * * If something is wrong terminates the execution and echoes the error. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -