Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4832 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons


Ignore:
Timestamp:
Jul 11, 2005, 5:45:27 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: loadParams and timing

Location:
orxonox/trunk/src/world_entities/weapons
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/weapons/crosshair.cc

    r4831 r4832  
    1919#include "event_handler.h"
    2020
     21#include "load_param.h"
    2122#include "graphics_engine.h"
    2223#include "glincl.h"
    23 #include "p_node.h"
    2424#include "state.h"
    25 #include "model.h"
     25#include "material.h"
    2626
    2727#include <iostream>
     
    3131
    3232/**
    33    \brief standard constructor
     33 * standart constructor
     34 */
     35Crosshair::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
    3448*/
    35 Crosshair::Crosshair ()
     49Crosshair::~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 */
     64void Crosshair::init()
    3665{
    3766  this->setClassID(CL_CROSSHAIR, "Crosshair");
    3867  this->setName("Crosshair");
    3968
    40   this->material = NULL;
    41   this->model = NULL;
    4269  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;
    6274
    6375  EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
     
    7082
    7183
    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 
     84void 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 */
     104void 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 */
     113void 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 */
    86122void Crosshair::process(const Event &event)
    87123{
     
    113149}
    114150
    115 
     151/**
     152 * ticks the Crosshair
     153 * @param dt the time to ticks
     154 */
     155void Crosshair::tick(float dt)
     156{
     157  this->rotation += dt * rotationSpeed;
     158
     159
     160
     161}
     162
     163/**
     164 * draws the crosshair
     165 */
    116166void Crosshair::draw()
    117167{
     
    189239             pos, pos+1, pos+2 );
    190240
    191   this->rotation += 1;
    192241
    193242  glTranslatef(position2D[0], position2D[1], 0);
    194243  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();
    196255  /*
    197256  glBegin(GL_QUADS);
  • orxonox/trunk/src/world_entities/weapons/crosshair.h

    r4830 r4832  
    1515class Model;
    1616class Material;
     17class TiXmlElement;
    1718
    1819//! A class that enables the
     
    2021
    2122 public:
    22   Crosshair();
     23  Crosshair(const TiXmlElement* root = NULL);
    2324  virtual ~Crosshair();
    2425
     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; };
    2533
    2634  virtual void process(const Event &event);
    27 
    2835  void tick(float dt);
    2936  void draw();
     
    3239   float            position2D[2];        //!< The 2D-position on the screen
    3340
    34    Model*           model;                //!< A model for the crosshair representing the Aim
    3541   Material*        material;             //!< a material for the Aim.
    3642   float            rotation;             //!< a rotation of the aim.
     43   float            rotationSpeed;        //!< Speed of the Rotation.
    3744   float            size;                 //!< The Size of the Crosshair (in % of screen resolution 1 is fullscreen)
    3845};
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4830 r4832  
    1212### File Specific
    1313   main-programmer: Patrick Boenzli
    14    co-programmer:
     14   co-programmer: Benjamin Grauer
    1515*/
    1616
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4831 r4832  
    2222#include "world_entity.h"
    2323
    24 #define W_MAX_SLOTS 8
    25 #define W_MAX_CONFIGS 4
    26 
    27 
    2824// FORWARD DECLARATION
    2925class Projectile;
     
    4238  WA_SPECIAL1      =    6,    //!< Special Action taken
    4339
    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.
    4541} WeaponActions;
    4642
     
    5551  WS_IDLE          =    7,    //!< The State where the weapon is idle
    5652
    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.
    5854} WeaponState;
    5955
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4828 r4832  
    1212### File Specific
    1313   main-programmer: Patrick Boenzli
    14    co-programmer:
     14   co-programmer: Benjamin Grauer
    1515*/
    1616
     
    2626
    2727
    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
    3130 * @param number of weapon slots of the model/ship <= 8 (limitied)
    3231 */
    33               WeaponManager::WeaponManager(int nrOfSlots)
     32WeaponManager::WeaponManager(int nrOfSlots)
    3433{
    3534  this->setClassID(CL_WEAPON_MANAGER, "WeaponManager");
     
    6362
    6463/**
    65  * @brief adds a weapon to the selected weaponconfiguration into the selected slot
     64 * adds a weapon to the selected weaponconfiguration into the selected slot
    6665 * @param the weapon to add
    6766 * @param an identifier for the slot: number between 0..7 if not specified: slotID=next free slot
    6867 * @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 be
    71              replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free
    72              slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be
    73              a error message.
    74  */
    75               void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
     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 */
     74void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    7675{
    7776  if( slotID == W_FREE_SLOT)
     
    101100
    102101/**
    103    * @brief changes to the next weapon configuration
    104 
    105              if there are multiple weapon configurations defined by the manager, use this to switch between them
    106              this function will deactivate the weapons first, change the config and reactivate them later
    107  */
    108               void WeaponManager::nextWeaponConf()
     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 */
     107void WeaponManager::nextWeaponConf()
    109108{
    110109  PRINTF(4)("Changing weapon configuration: from %i to next\n", this->currConfID);
     
    146145
    147146/**
    148    * @brief triggers fire of all weapons in the current weaponconfig
    149  */
    150               void WeaponManager::fire()
     147 * triggers fire of all weapons in the current weaponconfig
     148 */
     149void WeaponManager::fire()
    151150{
    152151  Weapon* firingWeapon;
     
    160159
    161160/**
    162    * @brief triggers tick of all weapons in the current weaponconfig
    163               * @param second passed since last tick
    164  */
    165               void WeaponManager::tick(float sec)
     161 * triggers tick of all weapons in the current weaponconfig
     162 * @param second passed since last tick
     163 */
     164void WeaponManager::tick(float sec)
    166165{
    167166  Weapon* w;
     
    175174
    176175/**
    177    * @brief triggers draw of all weapons in the current weaponconfig
     176 * triggers draw of all weapons in the current weaponconfig
    178177 */
    179178void WeaponManager::draw()
     
    189188
    190189/**
    191    * @brief private gets the next free slot in a certain weaponconfig
    192               * @param the selected weaponconfig
    193  */
    194               int WeaponManager::getNextFreeSlot(int configID)
     190 * private gets the next free slot in a certain weaponconfig
     191 * @param the selected weaponconfig
     192 */
     193int WeaponManager::getNextFreeSlot(int configID)
    195194{
    196195  for( int i = 0; i < W_MAX_SLOTS; ++i)
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.h

    r4826 r4832  
    3333class Weapon;
    3434
    35 
     35#define    W_MAX_SLOTS       8
     36#define    W_MAX_CONFIGS     4
    3637
    3738//! this is an identifier for the weapon config
     
    5657//! this is a weapon Configuration: it has up to 8 slots
    5758typedef struct weaponConfig {
    58   bool           bUsed;                       //<! is set to true, if this configuration is
     59  bool           bUsed;                       //!< is set to true, if this configuration is
    5960  Weapon*        slots[8];
    6061};
Note: See TracChangeset for help on using the changeset viewer.