www.pudn.com > RCApp-src.zip > Entity.h
/* RedEye Project (http://members.ozemail.com.au/~ndmcevoy/) Copyright (C) 2003 Nick McEvoy This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------- Commented for use with Doxygen (http://www.doxygen.org) ----------------------------------------------------------------- */ /*! \file Entity.h * \brief Game entity. * * This file contains the game entity. */ #ifndef _RE_GAME_ENTITY_H_ #define _RE_GAME_ENTITY_H_ // PLIB includes #include#include #include // ODE includes #include "ode/common.h" #include "ode/contact.h" #include "ode/objects.h" // RedEye includes #include "RCDefs.h" #include "RCXML.h" #include "List.h" class reShadow : public ssgBranch { public: reShadow(float x1, float x2, float y1, float y2); //! Update the shadow void Update(float x, float y); private: ssgTransform* mpTransform; }; class reGameEntity : public ssgBranch { public: static reGameEntity* Create(const char* psFile); static reGameEntity* Create(TiXmlNode* pNode); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity virtual void Update(float fDeltaSec); //! Check collisions of ODE body against PLIB world virtual void SpaceCollide(){}; //! Keyboard callbacks virtual void Keyboard(unsigned char key, int x, int y, bool bKeyDown){}; virtual void KeyboardSpecial(int key, int x, int y, bool bKeyDown){}; //! Set position virtual void SetPosition(sgCoord* p); void SetVelocity(float x, float y, float z) {dBodySetLinearVel(mODEBody, x, y, z);} void AddForce(float fx, float fy, float fz) {dBodyAddForce(mODEBody, fx, fy, fz);} void AddTorque(float fx, float fy, float fz) {dBodyAddTorque(mODEBody, fx, fy, fz);} //! Get position void GetPosition(sgCoord* p); //! Get transform void GetTransform(sgMat4 Xform); //! Get velocity void GetVelocity(sgVec3& Velocity); //! Destructor virtual ~reGameEntity(); protected: //! Constructor is protected as this class is an abstract class reGameEntity(); //! Get 'possible' collision hits of entity (bounding sphere) against PLIB world int GetHits(ssgHit** pHitList); //! Base transform ssgTransform* mpTransform; //! Velocity damping factor sgVec3 mVDampFactor; //! Angular velocity damping factor sgVec3 mAVDampFactor; //! Shadow reShadow* mpShadow; //! ODE body dBodyID mODEBody; //! ODE geometry dGeomID mODEGeom; }; class rePlatformEntity : public reGameEntity { public: rePlatformEntity(); virtual ~rePlatformEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Get attributes float GetPower() {return mfPower;} protected: //! Control entity void SetForward(bool bOn) {mbForward = bOn;} void SetReverse(bool bOn) {mbReverse = bOn;} void SetBreaking(bool bOn) {mbBreaking = bOn;} void SetHeadingLeft(bool bOn) {mbHeadingLeft = bOn;} void SetHeadingRight(bool bOn) {mbHeadingRight = bOn;} void SetPitchUp(bool bOn) {mbPitchUp = bOn;} void SetPitchDown(bool bOn) {mbPitchDown = bOn;} void SetRollLeft(bool bOn) {mbRollLeft = bOn;} void SetRollRight(bool bOn) {mbRollRight = bOn;} float mfPower; // Engine power (decimal %) sgVec3 mDirChange; // Direction change - hpr (decimal %) float mfMaxFuel; // Max fuel capacity (l) float mfBurnRate; // Fuel burn rate (l/s) sgVec2 mMaxThrust; // Max forward & reverse thrust (N) sgVec3 mMaxAngularThrust; // Max heading, pitch & roll thrust (N) sgVec3 mPowerFactor; // Power forward, reverse & break factor (decimal %/sec) sgVec3 mPowerDampFactor; // Power forward, reverse & break damping factor (decimal %/sec) sgVec3 mAngularPowerFactor; // Heading, pitch & roll factor (decimal %/sec) sgVec3 mAngularDampFactor; // Heading, pitch & roll damping factor (decimal %/sec) bool mbForward; // Forward flag bool mbReverse; // Reverse flag bool mbBreaking; // Breaking flag bool mbHeadingLeft; // Heading left flag bool mbHeadingRight; // Heading right flag bool mbPitchUp; // Pitching up flag bool mbPitchDown; // Pitching down flag bool mbRollLeft; // Roll left flag bool mbRollRight; // Roll right flag }; class reLandCraftEntity : public rePlatformEntity { public: //! Initialise bool Init(TiXmlNode* pConfig); }; class reWaterCraftEntity : public rePlatformEntity { public: //! Initialise bool Init(TiXmlNode* pConfig); }; class reAirCraftEntity : public rePlatformEntity { public: //! Initialise bool Init(TiXmlNode* pConfig); }; class reSpaceCraftEntity : public rePlatformEntity { public: //! Initialise bool Init(TiXmlNode* pConfig); }; class reWeaponEntity : public rePlatformEntity { public: //! Initialise bool Init(TiXmlNode* pConfig); }; class reBuildingEntity : public reGameEntity { }; class reEquipmentEntity : public reGameEntity { }; class reSceneryEntity : public reGameEntity { public: //! Initialise bool Init(TiXmlNode* pConfig); }; class reParticleSystem : public ssgaParticleSystem { public: reParticleSystem(TiXmlNode* pConfig); sgVec3 mColMin; sgVec3 mColMax; sgVec3 mPosMin; sgVec3 mPosMax; sgVec3 mVelMin; sgVec3 mVelMax; sgVec3 mAccelMin; sgVec3 mAccelMax; float mfLiveTimeMin; float mfLiveTimeMax; }; class reParticleEntity : public reGameEntity { public: reParticleEntity(); ~reParticleEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); void SetCreationRate(float fRate); private: reParticleSystem* mpParticle; }; class reTreeEntity : public reSceneryEntity { public: reTreeEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); }; class reTerrainEntity : public reSceneryEntity { public: reTerrainEntity(); ~reTerrainEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); private: //! Entity list - todo: maybe move to reGameEntity !!?? reList mEntityList; }; class reOceanEntity : public reSceneryEntity { public: reOceanEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); private: float mfTime; ssgaWaveSystem* mpOcean; reList mWaveTrainList; }; class reSkyEntity : public reSceneryEntity { public: reSkyEntity(); ~reSkyEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); void PreDraw(); void PostDraw(); private: ssgaSky* mpSky; ssgaCelestialBody* mpSunRef; }; class reBillyCartEntity : public reLandCraftEntity { public: reBillyCartEntity(); ~reBillyCartEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); //! Check collisions of ODE body against PLIB world void SpaceCollide(); //! Keyboard callbacks void Keyboard(unsigned char key, int x, int y, bool bKeyDown); void KeyboardSpecial(int key, int x, int y, bool bKeyDown); //! Set position void SetPosition(sgCoord* p); private: ssgTransform* mpWheelTransform[4]; // 0=FR,1=FL,2=BR,3=BL sgVec3 mWOffset; // FR wheel offset sgVec3 mTOffset; // Tux offset // ODE physics engine // todo: maybe move body extensions into reGameEntity?? dBodyID mODEBodyEx[5]; // 0-3=wheels, 4=tux dJointID mODEJointEx[5]; // 0-3=wheels, 4=tux dGeomID mODEGeomEx[5]; // 0-3=wheels, 4=tux dGeomID mODEGeomGroupEx; }; class reBoatEntity : public reWaterCraftEntity { public: reBoatEntity(); ~reBoatEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); //! Check collisions of ODE body against PLIB world void SpaceCollide(); //! Keyboard callbacks void Keyboard(unsigned char key, int x, int y, bool bKeyDown); void KeyboardSpecial(int key, int x, int y, bool bKeyDown); //! Set position void SetPosition(sgCoord* p); private: reParticleEntity* mpSpray; // ODE physics engine // todo: maybe move body extensions into reGameEntity?? dBodyID mODEBodyEx[2]; // 0-1=front/back end sphere dJointID mODEJointEx[2]; // 0-1=front/back end sphere dGeomID mODEGeomEx[2]; // 0-1=front/back end sphere dGeomID mODEGeomGroupEx; }; class reSpaceShipEntity : public reSpaceCraftEntity { public: reSpaceShipEntity(); ~reSpaceShipEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); //! Check collisions of ODE body against PLIB world void SpaceCollide(); //! Keyboard callbacks void Keyboard(unsigned char key, int x, int y, bool bKeyDown); void KeyboardSpecial(int key, int x, int y, bool bKeyDown); }; class rePlasmaBoltEntity : public reWeaponEntity { public: rePlasmaBoltEntity(); ~rePlasmaBoltEntity(); //! Initialise virtual bool Init(TiXmlNode* pConfig); //! Update the entity void Update(float fDeltaSec); //! Check collisions of ODE body against PLIB world void SpaceCollide(); }; #endif // _RE_GAME_ENTITY_H_