📄 teengine.cpp
字号:
//##################################################//# $Id: TeEngine.cpp 28 2005-08-28 10:37:47Z peciva $/*****************************************************************************\ * * TeEngine.cpp * * TeEngine - terrain engine class * * Authors: Martin Havl龛ek (xhavli15 AT stud.fit.vutbr.cz) * PCJohn (peciva AT fit.vutbr.cz) * Contributors: * * ---------------------------------------------------------------------------- * * THIS SOFTWARE IS NOT COPYRIGHTED * * This source code is offered for use in the public domain. * You may use, modify or distribute it freely. * * This source code is distributed in the hope that it will be useful but * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY * DISCLAIMED. This includes but is not limited to warranties of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * If you find the source code useful, authors will kindly welcome * if you give them credit and keep their names with their source code. *\*****************************************************************************/#include <Inventor/nodes/SoSeparator.h>#include <Inventor/errors/SoDebugError.h>#include <cstdlib> // NULL#include <ctime> // time#include "TeEngine.h"//----------------------------------------------------------------------------/** * Default constructor. * * Does some default choices, that can be modified later. * TeEngine::FAULT_FORMATION is selected as a generator and TeEngine::LINEAR * as a filter. * * \param hmapResolution Resolution of the patches' heightmaps. If left blank, * default value is used. * \param patch0Size Area occupied by the patch in the world-space. If left * blank, default value is used. */TeEngine::TeEngine(SbVec2s hmapResolution, SbVec2f patch0Size) : root(NULL), currGen(FAULT_FORMATION), currFilter(LINEAR), HUDCamera(NULL), HUDRoot(NULL), sceneCamera(NULL), sceneRoot(NULL), activeObject(NULL), fps(0.0f), tasksInQueue(0), patchesNum(0){ this->hmapResolution = hmapResolution; this->patch0Size = patch0Size; generator = &faultFormation;}//----------------------------------------------------------------------------/** * Destructor. */TeEngine::~TeEngine(){ delete root;}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Patch height map resolution. * * \sa hmapResolution */const SbVec2s& TeEngine::getHMapResolution() const{ return hmapResolution;}//-----------------------------------------------------------------------------/** * Computes patch build maps resolution. * * Build maps have to have double sized dimensions than the resulting height * map (minus 1). * * \return Patch build map resolution. */SbVec2s TeEngine::getBuildMapResolution() const{ return hmapResolution * 2 - SbVec2s(1,1);}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Patch height map resolution. * * \sa patch0Size */const SbVec2f& TeEngine::getPatch0Size() const{ return patch0Size;}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Currently selected generation method. * * \sa currGen, setCurrGen() */TeEngine::GenMethod TeEngine::getCurrGen(){ return currGen;}//-----------------------------------------------------------------------------/** * Sets currently selected generation method to \a m * * This method will be used when new task is scheduled or when generateHMap() * method is called. * * \param m Selected generation method. * * \sa currGen, getCurrGen(), schedule() */void TeEngine::setCurrGen(GenMethod m){ currGen = m;}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Currently selected filtration method. * * \sa currFilter, setCurrFilter() */TeEngine::FilterMethod TeEngine::getCurrFilter(){ return currFilter;}//-----------------------------------------------------------------------------/** * Sets currently selected filtration method to \a m * * This method will be used when new task is scheduled or when generateHMap() * method is called. * * \param m Selected filtration method. * * \sa currFilter, getCurrFilter(), schedule() */void TeEngine::setCurrFilter(FilterMethod m){ currFilter = m;}//-----------------------------------------------------------------------------/** * Adds object into the engine. * * \param obj Object to be added to the object list. * * \sa objectList, getObject(), removeObject() */void TeEngine::addObject(TeObject *obj){ obj->engine = this; objectList.append(obj); sceneRoot->addChild(obj->getSceneGraph());}//-----------------------------------------------------------------------------/** * Gets object from the object list. * * \param idx Index into the object list. * \return Object at index \a idx in the object list * * \sa objectList, addObject(), removeObject() */TeObject *TeEngine::getObject(int idx){ return objectList[idx];}//-----------------------------------------------------------------------------/** * Removes the \a object from engine. * * \param obj Object to be removed from the object list. * * \sa objectList, addObject(), getObject() */void TeEngine::removeObject(TeObject *obj){ objectList.removeItem(obj);}//-----------------------------------------------------------------------------/** * Sets active object. * * \param obj Object to be set as active. * * \sa activeObject, getActiveObject() */void TeEngine::setActiveObject(TeObject *obj){ activeObject = obj;}//-----------------------------------------------------------------------------/** * Gets active object. * * \return Currently active object. * * \sa activeObject, setActiveObject() */TeObject *TeEngine::getActiveObject(){ return activeObject;}//-----------------------------------------------------------------------------/** * Sets whole scene root. * * All objects managed by the engine will be added to the scene as children * of this node. * * \param sep Selected scene root. * * \sa sceneRoot, getSceneRoot() */void TeEngine::setSceneRoot(SoSeparator *sep){ sceneRoot = sep;}//-----------------------------------------------------------------------------/** * Private attribute accessor. * * \return Whole scene root. * * \sa sceneRoot, setSceneRoot() */SoSeparator* TeEngine::getSceneRoot(){ return sceneRoot;}//-----------------------------------------------------------------------------/** * Adds \a node to scene. * * This function checks, whether the \a node is already present. If it is, * nothing happens. This prevents from adding the same \a node into the * scene several times. Helpful when adding seams into the scene graph. * * Note, that modifications to the scene graph are not allowed during the * rendering traversal of the tree. Violation of this condition results * usually in application crash. * * \param node Node to be added to the scene. * * \sa sceneRoot, removeNode() */void TeEngine::addNode(SoNode *node){ if (sceneRoot->findChild(node) == -1) sceneRoot->addChild(node);}//-----------------------------------------------------------------------------/** * Removes \a node from scene. * * This function checks, whether the \a node is truly present. If it isn't, * nothing happens. * * Note, that modifications to the scene graph are not allowed during the * rendering traversal of the tree. Violation of this condition results * usually in application crash. * * \param node Node to be removed from the scene. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -