Changeset 3746 in orxonox.OLD for orxonox/branches/levelloader/src/world_entities
- Timestamp:
- Apr 7, 2005, 3:54:49 PM (20 years ago)
- Location:
- orxonox/branches/levelloader/src/world_entities
- Files:
-
- 2 deleted
- 12 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/world_entities/environment.cc
r3605 r3746 30 30 Environment::Environment () : WorldEntity() 31 31 { 32 this->model = new OBJModel("../data/models/fighter.obj"); 32 this->model = (Model*) ResourceManager::getInstance()->load("cube", RP_LEVEL); 33 // this->model = new OBJModel("../data/models/fighter.obj"); 33 34 } 34 35 … … 54 55 string = grabParameter( root, "model"); 55 56 if( string != NULL) 56 this->model = new OBJModel( string);57 this->model = (Model*) ResourceManager::getInstance()->load( string, RP_LEVEL); 57 58 else 58 59 { 59 60 PRINTF0("Environment is missing a proper 'model'\n"); 60 this->model = new OBJModel( "../data/models/reaplow.obj");61 this->model = (Model*) ResourceManager::getInstance()->load( "cube", RP_LEVEL); 61 62 } 62 63 if( this->model == NULL) -
orxonox/branches/levelloader/src/world_entities/player.cc
r3605 r3746 20 20 #include "player.h" 21 21 22 #include "track_manager.h" 23 #include "objModel.h" 24 #include "resource_manager.h" 25 #include "weapon.h" 26 #include "test_gun.h" 27 #include "world.h" 28 29 #include "list.h" 22 30 #include "stdincl.h" 23 //#include "collision.h"24 #include "objModel.h"25 #include "list.h"26 #include "weapon.h"27 #include "track_manager.h"28 31 29 32 using namespace std; … … 35 38 \param isFree if the player is free 36 39 */ 37 Player::Player(bool isFree) : WorldEntity(isFree) 38 { 39 this->model = new OBJModel("../data/models/reaplow.obj"); 40 Player::Player() : WorldEntity() 41 { 40 42 this->weapons = new tList<Weapon>(); 41 43 this->activeWeapon = NULL; 42 44 /* 45 this is the debug player - actualy we would have to make a new 46 class derivated from Player for each player. for now, we just use 47 the player.cc for debug also 48 */ 49 this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN); 43 50 travelSpeed = 15.0; 44 velocity = Vector();51 velocity = new Vector(); 45 52 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; 46 53 bFire = false; 47 54 acceleration = 10.0; 55 //weapons: 56 Weapon* wp = new TestGun(this, new Vector(-1.1, 0.0, 2.6), new Quaternion()); 57 this->weapons->add(wp); 58 this->activeWeapon = wp; 48 59 } 49 60 … … 53 64 Player::~Player () 54 65 { 55 Weapon* w = this->weapons->enumerate(); 56 while( w != NULL) 57 { 58 delete w; 59 w = this->weapons->nextElement(); 60 } 66 /* do not delete the weapons, they are contained in the pnode tree 67 and will be deleted there. 68 this only frees the memory allocated to save the list. 69 */ 61 70 delete this->weapons; 62 63 //delete this->velocity;64 71 } 65 72 … … 94 101 string = grabParameter( root, "model"); 95 102 if( string != NULL) 96 this->model = new OBJModel( string);103 this->model = (Model*)ResourceManager::getInstance()->load(string, OBJ, RP_CAMPAIGN); 97 104 else 98 105 { 99 106 PRINTF0("Player is missing a proper 'model'\n"); 100 this->model = new OBJModel( "../data/models/reaplow.obj");107 this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN); 101 108 } 102 109 if( this->model == NULL) … … 104 111 PRINTF0("Player model '%s' could not be loaded\n", string); 105 112 } 113 114 this->weapons = new tList<Weapon>(); 115 this->activeWeapon = NULL; 116 /* 117 this is the debug player - actualy we would have to make a new 118 class derivated from Player for each player. for now, we just use 119 the player.cc for debug also 120 */ 121 travelSpeed = 15.0; 122 velocity = new Vector(); 123 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; 124 bFire = false; 125 acceleration = 10.0; 126 //weapons: 127 Weapon* wp = new TestGun(this, new Vector(-1.1, 0.0, 2.6), new Quaternion()); 128 this->weapons->add(wp); 129 this->activeWeapon = wp; 106 130 } 107 131 … … 192 216 void Player::tick (float time) 193 217 { 218 /* link tick to weapon */ 219 this->activeWeapon->tick(time); 194 220 // player controlled movement 195 this->move 221 this->move(time); 196 222 // weapon system manipulation 197 this-> fire();223 this->weapon(); 198 224 } 199 225 … … 214 240 //orthDirection = orthDirection.cross (direction); 215 241 216 if( this->bUp && this->getRelCoor() .x < 20)242 if( this->bUp && this->getRelCoor()->x < 20) 217 243 accel = accel+(direction*acceleration); 218 if( this->bDown && this->getRelCoor() .x > -5)244 if( this->bDown && this->getRelCoor()->x > -5) 219 245 accel = accel-(direction*acceleration); 220 if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor() .z*2)246 if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor()->z*2) 221 247 accel = accel - (orthDirection*acceleration); 222 if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor() .z*2)248 if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor()->z*2) 223 249 accel = accel + (orthDirection*acceleration); 224 250 if( this->bAscend ) … … 233 259 \brief weapon manipulation by the player 234 260 */ 235 void Player:: fire()236 { 237 if( this->bFire)261 void Player::weapon() 262 { 263 if( this->bFire) 238 264 { 239 265 if(this->activeWeapon != NULL) 240 266 this->activeWeapon->fire(); 241 267 } 242 if( this->bWeaponChange)268 if( this->bWeaponChange && this->weapons->getSize() > 1) 243 269 { 244 Weapon* w = this->weapons->enumerate(); 270 PRINTF(1)("changing the weapon of the player: deactivate old, activate new\n"); 271 this->activeWeapon->deactivate(); 272 //this->weapons->enumerate(); FIX: strang weapon change... 245 273 this->activeWeapon = this->weapons->nextElement(this->activeWeapon); 274 this->activeWeapon->activate(); 246 275 } 247 276 } -
orxonox/branches/levelloader/src/world_entities/player.h
r3605 r3746 10 10 11 11 template<class T> class tList; 12 class OBJModel;13 12 class Weapon; 13 class Vector; 14 class World; 14 15 15 16 //! Basic controllable WorldEntity … … 19 20 20 21 public: 21 Player( bool isFree = false);22 Player(); 22 23 Player(TiXmlElement* root); 23 24 virtual ~Player(); … … 48 49 tList<Weapon>* weapons;//!< a list of weapon 49 50 Weapon* activeWeapon; //!< the weapon that is currenty activated 51 World* myWorld; //!< reference to the world object 50 52 51 Vector velocity; //!< the velocity of the player.53 Vector* velocity; //!< the velocity of the player. 52 54 float travelSpeed; //!< the current speed of the player (to make soft movement) 53 55 float acceleration; //!< the acceleration of the player. 54 56 55 57 void move(float time); 56 void fire(void);58 void weapon(void); 57 59 58 60 }; -
orxonox/branches/levelloader/src/world_entities/projectile.cc
r3605 r3746 18 18 19 19 #include "projectile.h" 20 #include "stdincl.h" 20 21 21 #include "world_entity.h" 22 #include "weapon.h" 23 #include "null_parent.h" 24 #include "model.h" 22 25 #include "vector.h" 23 #include "objModel.h"24 26 25 27 using namespace std; … … 29 31 \brief standard constructor 30 32 */ 31 Projectile::Projectile ( ) : WorldEntity()33 Projectile::Projectile (Weapon* weapon) : WorldEntity() 32 34 { 33 this->model = new OBJModel(""); 35 this->model = (Model*)ResourceManager::getInstance()->load("sphere", PRIM, RP_LEVEL); 36 this->weapon = weapon; 37 this->flightDirection = NULL; 38 this->currentLifeTime = 0.0f; 39 this->ttl = 0.75f; /* sec */ 40 this->speed = 2.0f; 34 41 } 35 42 … … 40 47 Projectile::~Projectile () 41 48 { 42 49 /* 50 do not delete the test projectModel, since it is pnode 51 and will be cleaned out by world 52 */ 53 //delete this->projectileModel; 43 54 } 44 55 56 57 /** 58 \brief this sets the flight direction of the projectile 59 \param directin in which to flight 60 61 this function will calculate a vector out of this to be used in the 62 tick function 63 */ 64 void Projectile::setFlightDirection(Quaternion flightDirection) 65 { 66 if( this->flightDirection == NULL) 67 this->flightDirection = new Vector(); 68 Vector v(1, 0, 0); 69 *this->flightDirection = flightDirection.apply(v); 70 this->flightDirection->normalize(); 71 } 72 73 74 /** 75 \brief this sets the time to life of the projectile 76 \param ttl in second 77 78 after this life time, the projectile will garbage collect itself 79 */ 80 void Projectile::setTTL(float ttl) 81 { 82 this->ttl = ttl; 83 } 84 85 86 /** 87 \brief sets the speed of the projectile 88 */ 89 void Projectile::setSpeed(float speed) 90 { 91 this->speed = speed * 3; /* fix speed settings */ 92 PRINTF(4)("Projectile::setting speed to: %f\n", this->speed); 93 } 45 94 46 95 /** … … 49 98 */ 50 99 void Projectile::tick (float time) 51 {} 100 { 101 Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.7); 102 this->shiftCoor(v); 103 104 this->currentLifeTime += time; 105 if( this->ttl < this->currentLifeTime) 106 { 107 PRINTF(5)("FINALIZE==========================\n"); 108 PRINTF(5)("current life time is: %f/%f\n", this->currentLifeTime, this->ttl); 109 PRINTF(5)("FINALIZE===========================\n"); 110 this->finalize(); 111 this->currentLifeTime = 0.0f; 112 } 113 } 52 114 53 115 /** -
orxonox/branches/levelloader/src/world_entities/projectile.h
r3605 r3746 2 2 \projectile.h 3 3 \brief a projectile, that is been shooted by a weapon 4 5 You can use this class to make some shoots, but this isn't the real idea. If you want to just test, if the 6 shooting funcions work, use the Projectile class. But if you want to implement your own shoots its 7 different:<br> 8 Make a new class and derive it from Projectile. To have a weapon work well, reimplement the functions 9 - void tick() 10 - void draw() 11 - void hit() (only if you have working collision detection) 12 When you have implemented these functions you have just to add the projectiles to your weapon. You ll want 13 to make this by looking into the function 14 - Weapon::fire() 15 there you just change the line: 16 Projectile* pj = new Projectile(); TO Projectile* pj = new MyOwnProjectileClass(); 17 and schwups it works... :) 4 18 */ 5 19 … … 9 23 #include "world_entity.h" 10 24 25 class Vector; 26 class Weapon; 11 27 12 28 class Projectile : public WorldEntity … … 15 31 16 32 public: 17 Projectile ( );33 Projectile (Weapon* weapon); 18 34 virtual ~Projectile (); 35 36 void setFlightDirection(Quaternion flightDirection); 37 void setSpeed(float speed); 38 void setTTL(float ttl); 19 39 20 40 virtual void hit (WorldEntity* weapon, Vector* loc); … … 24 44 virtual void draw (); 25 45 26 pr ivate:46 protected: 27 47 //physical attriutes like: force, speed, acceleration etc. 28 48 float speed; //!< this is the speed of the projectile 49 float currentLifeTime; //!< this is the time, the projectile exists in this world (incremented by tick) 50 float ttl; //!< time to life, after this time, the projectile will garbage collect itself 51 Vector* flightDirection; //!< direction in which the shoot flights 52 Weapon* weapon; //!< weapon the shoot belongs to 53 29 54 }; 30 55 -
orxonox/branches/levelloader/src/world_entities/skysphere.cc
r3605 r3746 26 26 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 27 27 28 #include "material.h" 28 29 29 #include "skysphere.h" 30 30 #include "stdincl.h" 31 32 #include "material.h" 31 33 #include "vector.h" 32 #include "world_entity.h" 34 //#include "world_entity.h" 35 33 36 34 37 using namespace std; … … 100 103 glPushMatrix(); 101 104 glMatrixMode(GL_MODELVIEW); 102 glTranslatef(this->absCoordinate.x, 103 this->absCoordinate.y, 104 this->absCoordinate.z); 105 Vector r = this->getAbsCoor(); 106 glTranslatef(r.x, r.y, r.z); 105 107 106 108 //glRotatef(-30, 1, 0, 0); -
orxonox/branches/levelloader/src/world_entities/skysphere.h
r3605 r3746 14 14 15 15 /* INCLUDES */ 16 #include "p_node.h"17 16 #include "world_entity.h" 18 17 -
orxonox/branches/levelloader/src/world_entities/terrain.cc
r3605 r3746 16 16 17 17 #include "terrain.h" 18 18 #include "stdincl.h" 19 #include "model.h" 20 #include "vector.h" 19 21 #include "glincl.h" 20 22 … … 43 45 if (strstr(fileName, ".obj") || strstr(fileName, ".OBJ")) 44 46 { 45 this->model = ( OBJModel*)new OBJModel(fileName);47 this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_LEVEL); 46 48 } 47 49 else -
orxonox/branches/levelloader/src/world_entities/weapon.cc
r3605 r3746 21 21 #include "world_entity.h" 22 22 #include "vector.h" 23 #include " objModel.h"23 #include "model.h" 24 24 #include "projectile.h" 25 #include "list.h" 26 #include "world.h" 25 27 26 28 using namespace std; … … 32 34 creates a new weapon 33 35 */ 34 Weapon::Weapon () : WorldEntity() 35 {} 36 Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion* direction) 37 : WorldEntity() 38 { 39 parent->addChild(this, PNODE_ROTATE_AND_MOVE); 40 this->setRelCoor(coordinate); 41 this->setRelDir(direction); 42 WorldInterface* wi = WorldInterface::getInstance(); 43 this->worldEntities = wi->getEntityList(); 44 } 36 45 37 46 … … 145 154 */ 146 155 void Weapon::setWeaponIdleTime(float time) 147 {} 156 { 157 this->idleTime = time; 158 } 148 159 149 160 /** … … 155 166 */ 156 167 float Weapon::getWeaponIdleTime(void) 157 {} 168 { 169 return this->idleTime; 170 } 158 171 159 172 /** … … 165 178 */ 166 179 bool Weapon::hasWeaponIdleTimeElapsed(void) 167 {} 180 { 181 return (this->localTime>this->idleTime)?true:false; 182 } 168 183 169 184 -
orxonox/branches/levelloader/src/world_entities/weapon.h
r3605 r3746 43 43 44 44 public: 45 Weapon ( );45 Weapon (PNode* parent, Vector* coordinate, Quaternion* direction); 46 46 virtual ~Weapon (); 47 47 … … 57 57 bool isActive(void); 58 58 59 v irtual void setWeaponIdleTime(float time);60 virtualfloat getWeaponIdleTime(void);61 virtualbool hasWeaponIdleTimeElapsed(void);59 void setWeaponIdleTime(float time); 60 float getWeaponIdleTime(void); 61 bool hasWeaponIdleTimeElapsed(void); 62 62 63 virtual void fire(void) ;63 virtual void fire(void) = 0; 64 64 virtual void hit (WorldEntity* weapon, Vector* loc); 65 65 virtual void destroy(void); … … 69 69 virtual void draw(void); 70 70 71 protected: 72 tList<WorldEntity>* worldEntities; 73 float localTime; 74 float idleTime; 75 float slowDownFactor; 71 76 72 77 private: 73 78 bool enabled; 74 float localTime;75 float slowDownFactor;76 79 Projectile* projectile; 77 80 //WeaponSound sound; 78 79 81 }; 80 82 -
orxonox/branches/levelloader/src/world_entities/world_entity.cc
r3605 r3746 19 19 20 20 #include "world_entity.h" 21 #include "stdincl.h" 21 #include "objModel.h" 22 #include "list.h" 23 24 //#include "stdincl.h" 22 25 //#include "collision.h" 23 26 … … 48 51 { 49 52 // if( collisioncluster != NULL) delete collisioncluster; 50 delete this->model; 53 if (this->model) 54 ResourceManager::getInstance()->unload(this->model); 51 55 } 52 56 … … 167 171 Handle all stuff that should update with time inside this method (movement, animation, etc.) 168 172 */ 169 void WorldEntity::tick(float time)173 inline void WorldEntity::tick(float time) 170 174 { 171 175 } … … 177 181 This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn. 178 182 */ 179 void WorldEntity::draw()183 inline void WorldEntity::draw() 180 184 {} 181 185 -
orxonox/branches/levelloader/src/world_entities/world_entity.h
r3605 r3746 7 7 #define _WORLD_ENTITY_H 8 8 9 #include "stdincl.h"10 9 #include "p_node.h" 11 #include "objModel.h" 10 #include "comincl.h" 11 #include "resource_manager.h" 12 12 13 13 14 //class CollisionCluster; 14 15 class CharacterAttributes; 16 class Model; 15 17 16 18 … … 48 50 49 51 protected: 50 OBJModel* model; //!< The model that should be loaded for this entity.52 Model* model; //!< The model that should be loaded for this entity. 51 53 CharacterAttributes* charAttr; //!< the character attributes of a world_entity 52 54
Note: See TracChangeset
for help on using the changeset viewer.