Changeset 4832 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons
- Timestamp:
- Jul 11, 2005, 5:45:27 PM (20 years ago)
- Location:
- orxonox/trunk/src/world_entities/weapons
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/crosshair.cc
r4831 r4832 19 19 #include "event_handler.h" 20 20 21 #include "load_param.h" 21 22 #include "graphics_engine.h" 22 23 #include "glincl.h" 23 #include "p_node.h"24 24 #include "state.h" 25 #include "m odel.h"25 #include "material.h" 26 26 27 27 #include <iostream> … … 31 31 32 32 /** 33 \brief standard constructor 33 * standart constructor 34 */ 35 Crosshair::Crosshair (const TiXmlElement* root) 36 { 37 this->init(); 38 39 if (root) 40 this->loadParams(root); 41 else 42 this->setTexture("maps/aim.png"); 43 } 44 45 46 /** 47 * destroys a Crosshair 34 48 */ 35 Crosshair::Crosshair () 49 Crosshair::~Crosshair () 50 { 51 if (this->material) 52 delete this->material; 53 54 // delete what has to be deleted here 55 EventHandler::getInstance()->unsubscribe(this); 56 57 GraphicsEngine::showMouse(true); 58 GraphicsEngine::stealWMEvents(false); 59 } 60 61 /** 62 * initializes the Crosshair 63 */ 64 void Crosshair::init() 36 65 { 37 66 this->setClassID(CL_CROSSHAIR, "Crosshair"); 38 67 this->setName("Crosshair"); 39 68 40 this->material = NULL;41 this->model = NULL;42 69 this->rotation = 0; 43 44 this->material = new Material("Crosshair Material"); 45 this->material->setDiffuseMap("maps/aim.png"); 46 47 float size = 50; 48 this->model = new Model(); 49 this->model->addVertex (-0.5*size, -0.5*size, 0); 50 this->model->addVertex (0.5*size, -0.5*size, 0); 51 this->model->addVertex (0.5*size, 0.5*size, 0); 52 this->model->addVertex (-0.5*size, 0.5*size, 0); 53 54 this->model->addVertexTexture(0,0); 55 this->model->addVertexTexture(1,0); 56 this->model->addVertexTexture(1,1); 57 this->model->addVertexTexture(0,1); 58 59 this->model->setMaterial(this->material); 60 this->model->addFace(4, VERTEX_TEXCOORD, 0,0, 1,1 ,2,2, 3,3); 61 this->model->finalize(); 70 this->rotationSpeed = 5; 71 this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0); 72 73 this->material = new Material; 62 74 63 75 EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION); … … 70 82 71 83 72 /** 73 \brief standard deconstructor 74 */ 75 Crosshair::~Crosshair () 76 { 77 // delete this->model; 78 79 // delete what has to be deleted here 80 EventHandler::getInstance()->unsubscribe(this); 81 82 GraphicsEngine::showMouse(true); 83 GraphicsEngine::stealWMEvents(false); 84 } 85 84 void Crosshair::loadParams(const TiXmlElement* root) 85 { 86 static_cast<PNode*>(this)->loadParams(root); 87 static_cast<EventListener*>(this)->loadParams(root); 88 89 LoadParam<Crosshair>(root, "texture", this, &Crosshair::setTexture) 90 .describe("the texture-file to load onto the Crosshair"); 91 92 LoadParam<Crosshair>(root, "size", this, &Crosshair::setSize) 93 .describe("the size of the Crosshair in Pixels"); 94 95 LoadParam<Crosshair>(root, "rotation-speed", this, &Crosshair::setRotationSpeed) 96 .describe("the Speed with which the Crosshair should rotate"); 97 } 98 99 100 /** 101 * sets the size of the Crosshair. 102 * @param size the size in pixels 103 */ 104 void Crosshair::setSize(float size) 105 { 106 this->size = size*.5; 107 }; 108 109 /** 110 * sets the material to load 111 * @param textureFile The texture-file to load onto the crosshair 112 */ 113 void Crosshair::setTexture(const char* textureFile) 114 { 115 this->material->setDiffuseMap(textureFile); 116 } 117 118 /** 119 * processes the input 120 * @param event the Event coming as input 121 */ 86 122 void Crosshair::process(const Event &event) 87 123 { … … 113 149 } 114 150 115 151 /** 152 * ticks the Crosshair 153 * @param dt the time to ticks 154 */ 155 void Crosshair::tick(float dt) 156 { 157 this->rotation += dt * rotationSpeed; 158 159 160 161 } 162 163 /** 164 * draws the crosshair 165 */ 116 166 void Crosshair::draw() 117 167 { … … 189 239 pos, pos+1, pos+2 ); 190 240 191 this->rotation += 1;192 241 193 242 glTranslatef(position2D[0], position2D[1], 0); 194 243 glRotatef(this->rotation, 0,0,1); 195 this->model->draw(); 244 this->material->select(); 245 glBegin(GL_TRIANGLE_STRIP); 246 glTexCoord2f(0, 0); 247 glVertex2f(-size, -size); 248 glTexCoord2f(1, 0); 249 glVertex2f(size, -size); 250 glTexCoord2f(0, 1); 251 glVertex2f(-size, size); 252 glTexCoord2f(1, 1); 253 glVertex2f(size, size); 254 glEnd(); 196 255 /* 197 256 glBegin(GL_QUADS); -
orxonox/trunk/src/world_entities/weapons/crosshair.h
r4830 r4832 15 15 class Model; 16 16 class Material; 17 class TiXmlElement; 17 18 18 19 //! A class that enables the … … 20 21 21 22 public: 22 Crosshair( );23 Crosshair(const TiXmlElement* root = NULL); 23 24 virtual ~Crosshair(); 24 25 26 void init(); 27 void loadParams(const TiXmlElement* root); 28 29 void setSize(float size); 30 void setTexture(const char* textureFile); 31 /** @param rotationSpeed the speed at what the crosshair should rotate */ 32 void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; }; 25 33 26 34 virtual void process(const Event &event); 27 28 35 void tick(float dt); 29 36 void draw(); … … 32 39 float position2D[2]; //!< The 2D-position on the screen 33 40 34 Model* model; //!< A model for the crosshair representing the Aim35 41 Material* material; //!< a material for the Aim. 36 42 float rotation; //!< a rotation of the aim. 43 float rotationSpeed; //!< Speed of the Rotation. 37 44 float size; //!< The Size of the Crosshair (in % of screen resolution 1 is fullscreen) 38 45 }; -
orxonox/trunk/src/world_entities/weapons/weapon.cc
r4830 r4832 12 12 ### File Specific 13 13 main-programmer: Patrick Boenzli 14 co-programmer: 14 co-programmer: Benjamin Grauer 15 15 */ 16 16 -
orxonox/trunk/src/world_entities/weapons/weapon.h
r4831 r4832 22 22 #include "world_entity.h" 23 23 24 #define W_MAX_SLOTS 825 #define W_MAX_CONFIGS 426 27 28 24 // FORWARD DECLARATION 29 25 class Projectile; … … 42 38 WA_SPECIAL1 = 6, //!< Special Action taken 43 39 44 WA_ACTION_COUNT = 6 //!< This must match the count of enumerations (without W_NONE)40 WA_ACTION_COUNT = 7 //!< This must match the count of enumerations-members. 45 41 } WeaponActions; 46 42 … … 55 51 WS_IDLE = 7, //!< The State where the weapon is idle 56 52 57 WS_STATE_COUNT = 7 //!< This must match the count of the enumerations (without W_NONE)53 WS_STATE_COUNT = 8 //!< This must match the count of the enumerations-members. 58 54 } WeaponState; 59 55 -
orxonox/trunk/src/world_entities/weapons/weapon_manager.cc
r4828 r4832 12 12 ### File Specific 13 13 main-programmer: Patrick Boenzli 14 co-programmer: 14 co-programmer: Benjamin Grauer 15 15 */ 16 16 … … 26 26 27 27 28 29 /** 30 * @brief this initializes the weaponManager for a given nnumber of weapon slots 28 /** 29 * this initializes the weaponManager for a given nnumber of weapon slots 31 30 * @param number of weapon slots of the model/ship <= 8 (limitied) 32 31 */ 33 32 WeaponManager::WeaponManager(int nrOfSlots) 34 33 { 35 34 this->setClassID(CL_WEAPON_MANAGER, "WeaponManager"); … … 63 62 64 63 /** 65 * @briefadds a weapon to the selected weaponconfiguration into the selected slot64 * adds a weapon to the selected weaponconfiguration into the selected slot 66 65 * @param the weapon to add 67 66 * @param an identifier for the slot: number between 0..7 if not specified: slotID=next free slot 68 67 * @param an identifier for the weapon configuration, number between 0..3 69 70 if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be71 72 73 74 */ 75 68 * 69 * if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be 70 * replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free 71 * slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be 72 * a error message. 73 */ 74 void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID) 76 75 { 77 76 if( slotID == W_FREE_SLOT) … … 101 100 102 101 /** 103 * @briefchanges to the next weapon configuration104 105 106 107 */ 108 102 * changes to the next weapon configuration 103 * 104 * if there are multiple weapon configurations defined by the manager, use this to switch between them 105 * this function will deactivate the weapons first, change the config and reactivate them later 106 */ 107 void WeaponManager::nextWeaponConf() 109 108 { 110 109 PRINTF(4)("Changing weapon configuration: from %i to next\n", this->currConfID); … … 146 145 147 146 /** 148 * @brieftriggers fire of all weapons in the current weaponconfig149 */ 150 147 * triggers fire of all weapons in the current weaponconfig 148 */ 149 void WeaponManager::fire() 151 150 { 152 151 Weapon* firingWeapon; … … 160 159 161 160 /** 162 * @brieftriggers tick of all weapons in the current weaponconfig163 164 */ 165 161 * triggers tick of all weapons in the current weaponconfig 162 * @param second passed since last tick 163 */ 164 void WeaponManager::tick(float sec) 166 165 { 167 166 Weapon* w; … … 175 174 176 175 /** 177 * @brieftriggers draw of all weapons in the current weaponconfig176 * triggers draw of all weapons in the current weaponconfig 178 177 */ 179 178 void WeaponManager::draw() … … 189 188 190 189 /** 191 * @briefprivate gets the next free slot in a certain weaponconfig192 193 */ 194 190 * private gets the next free slot in a certain weaponconfig 191 * @param the selected weaponconfig 192 */ 193 int WeaponManager::getNextFreeSlot(int configID) 195 194 { 196 195 for( int i = 0; i < W_MAX_SLOTS; ++i) -
orxonox/trunk/src/world_entities/weapons/weapon_manager.h
r4826 r4832 33 33 class Weapon; 34 34 35 35 #define W_MAX_SLOTS 8 36 #define W_MAX_CONFIGS 4 36 37 37 38 //! this is an identifier for the weapon config … … 56 57 //! this is a weapon Configuration: it has up to 8 slots 57 58 typedef struct weaponConfig { 58 bool bUsed; // <!is set to true, if this configuration is59 bool bUsed; //!< is set to true, if this configuration is 59 60 Weapon* slots[8]; 60 61 };
Note: See TracChangeset
for help on using the changeset viewer.