⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teobject.h

📁 海量地形数据漫游系统,对于OPENGL开发人员具有一定的参考
💻 H
字号:
#ifndef TE_OBJECT_H#define TE_OBJECT_H/*****************************************************************************\ * * TeObject.h * * TeObject abstract class * * Author: Martin Havl龛ek (xhavli15 AT stud.fit.vutbr.cz) * Contributors: * * Some code taken from SpaceGame objects written by Petr Mastera and PCJohn. * * ---------------------------------------------------------------------------- * * 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. *\*****************************************************************************//** * TeObject class header file. * * \file TeObject.h * \author Martin Havl龛ek (martyn AT seznam.cz) */#include <Inventor/SbLinear.h>#include "TePatch.h"class SoSeparator;class SoTranslation;class SoRotation;class SoEvent;class TeEngine;/** * Class meant to be a parent to all engine objects. * TeObject itself is suitable for simple AI-controlled or static (it has * empty handleEvent() method and provides static HUD [=Heads-Up Display]) * objects. This class defines interface for derived classes. They are meant * to be used as a representation of differently behaving objects that can * move over our landscape and engine has to have access to them. * * Creating variety of classes that share the interface is comfort way how * to let engine take care of all kinds of objects and also to let objects * define completely different behaviour, controls, HUDs, etc. in other hand. * * For ensuring the functionality of the engine it is important to correctly * define timeTick() and handleEvent() methods in each derived class. In case * we want our object to provide HUD, functions called createHUD() and * updateHUD() should do that work. The functions should do the things as * follows: * \li timeTick() function is responsible for performing movement according *     to the speed vector and the time elapsed since last function call. *     This method is called continuously by the engine. * \li handleEvent() method is responsible for handling user inputs and *     defines behaviour (the physics) of the given vehicle (plane, car, *     walker,...). Engine catches the event and passes it to the active *     object. When control returns back to the engine, it sets the event *     "handled". * \li createHUD() function should is called by the engine's *     TeEngine::initialize() method. It should create the scene graph *     that provides all HUD-related nodes. The root of this graph *     will be stored by the engine class. * \li updateHUD() method should be called by the timeTick() function *     of the object. All code that changes the HUD look to represent *     current object state should be placed here. It is recommended to *     store all related nodes in private attributes of derived class. *     Note also, that setting of all class attributes, that are new in the *     derived class should be done in the correctly defined constructor. */class TeObject {  friend class TeEngine;public:  /** Enumeration of model types. */  enum MODEL_SET {    RENDER = 0x01, /**< Model for rendering. */                   COLLISION = 0x02, /**< Model for collision detection. */                         ALL = 0x03  /**< Both purposes. */  };protected:  // these attributes are managed by TeEngine friend class and should be never  // hacked some other way  /** Connection to the engine class. Connection is established by the engine when adding the object into it. \sa TeEngine::addObject() */  TeEngine *engine;  /** Set to TRUE when touched by the engine for the first time. */  SbBool initialized;  /** Coordinates of the patch right under the object. */  SbVec2f patchPosUnder;  /** Position relative to the patch borders. */  TePatch::Direction posInsidePatch;  /** Root of the internal scene. \sa getSceneGraph() */  SoSeparator *root;  /** Translation of the render-model. */  SoTranslation *translation;  /** Rotation of the render-model. */  SoRotation *rotation;  /** Positon of the camera relatively to the object's position. */  SbVec3f camDistance;  // models stuff  /** Internal scene that represents object model for rendering. \sa getModel(), setModel() */  SoNode *model;  /** Internal scene that represents object model for collision detection. \sa getModel(), setModel() */  SoNode *collisionModel;  void createHiddenScene();  void releaseHiddenScene();  virtual void createHUD();  // these functions are called internally in each timeTick()  virtual void updateHUD();  virtual void updateCamera();public:  virtual void timeTick(const SbTime delta);  /** Current object position in 3D space. */  //SbVec3f position;  /** Current object orientation in 3D space. */  //SbRotation orientation;  /** Current object speed vector. */  SbVec3f speed;  const SbVec3f& getPosition() const;  void setPosition(const SbVec3f &pos);  void setPosition(const float x, const float y, const float z);  const SbRotation& getOrientation() const;  void setOrientation(const SbRotation &orient);  void setOrientation(const float q0, const float q1, const float q2, const float q3);  TeObject();  virtual ~TeObject();  SoSeparator *getSceneGraph();  SoTranslation* getTranslation();  SoNode* getModel();  SoNode* getCollisionModel();  void setModel(SoNode *model, MODEL_SET which = ALL);  SbBool setModel(const char *filename, MODEL_SET which = ALL);  virtual void handleEvent(const SoEvent *event);};#endif /* TE_OBJECT_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -