Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

orxonox/trunk: crosshair in WeaponManager (instead of World) and implemented easy Cyling for LoadParam

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

Legend:

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

    r4832 r4834  
    4343}
    4444
    45 
    4645/**
    4746 * destroys a Crosshair
     
    6867
    6968  this->rotation = 0;
    70   this->rotationSpeed = 5;
     69  this->setRotationSpeed(5);
    7170  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
    7271
     
    155154void Crosshair::tick(float dt)
    156155{
     156  // let the crosshair rotate
    157157  this->rotation += dt * rotationSpeed;
    158158
    159159
    160 
    161 }
    162 
    163 /**
    164  * draws the crosshair
    165  */
    166 void Crosshair::draw()
    167 {
    168   /*
    169   const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
    170   Vector cameraPos = camera->getAbsCoor();
    171   Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
    172   Vector view = cameraTargetPos - cameraPos;
    173   Vector up = Vector(0, 1, 0);
    174   up = camera->getAbsDir().apply(up);
    175   Vector h = up.cross(view);
    176   Vector v = h.cross(view);
    177   h.normalize();
    178   v.normalize();
    179 
    180   float px = (position2D[0]-GraphicsEngine::getInstance()->getResolutionX()/2)*.05;
    181   float py = -(position2D[1]-GraphicsEngine::getInstance()->getResolutionY()/2)*.05;
    182 
    183   glBegin(GL_TRIANGLES);
    184   glVertex3f(cameraTargetPos.x - h.x*px - v.x*py,
    185   cameraTargetPos.y - h.y*px - v.y*py,
    186   cameraTargetPos.z - h.z*px - v.z*py);
    187 
    188   glVertex3f(cameraTargetPos.x - h.x*(px+1) - v.x*py,
    189   cameraTargetPos.y - h.y*(px+1) - v.y*py,
    190   cameraTargetPos.z - h.z*(px+1) - v.z*py);
    191 
    192   glVertex3f(cameraTargetPos.x - h.x*px - v.x*(py+1),
    193   cameraTargetPos.y - h.y*px - v.y*(py+1),
    194   cameraTargetPos.z - h.z*px - v.z*(py+1));
    195 
    196   glEnd();
    197 
    198   */
    199 
    200 
    201   GraphicsEngine::storeMatrices();
    202 
    203 ///  float z;
    204 //   glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
    205 
    206 
    207   //cout << z <<"  "<< scale << "  "  << bias<< endl;
    208 
     160  float z;
     161  glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
     162  //cout << z << endl;
    209163
    210164  GLdouble objX, objY, objZ;
     
    221175  this->setAbsCoor(objX, objY, objZ);
    222176
     177
     178}
     179
     180/**
     181 * draws the crosshair
     182 */
     183void Crosshair::draw()
     184{
     185  GraphicsEngine::storeMatrices();
     186
     187
     188
     189
    223190//   glBegin(GL_TRIANGLES);
    224191//   glColor3f(1,0,0);
     
    228195//   glEnd();
    229196
     197  this->debugDraw();
    230198
    231199  GraphicsEngine::enter2DMode();
     
    253221  glVertex2f(size, size);
    254222  glEnd();
    255   /*
    256   glBegin(GL_QUADS);
    257   {
    258     glColor4f(1,0,0,1);
    259     glVertex2f(position2D[0]-10, position2D[1]-10);
    260     glVertex2f(position2D[0]+10, position2D[1]-10);
    261     glVertex2f(position2D[0]+10, position2D[1]+10);
    262     glVertex2f(position2D[0]-10, position2D[1]+10);
    263 
    264     //     glVertex2f(pos[0]-10, pos[1]-10);
    265     //     glVertex2f(pos[0]-10, pos[1]+10);
    266     //     glVertex2f(pos[0]+10, pos[1]+10);
    267     //     glVertex2f(pos[0]+10, pos[1]-10);
    268   }
    269   glEnd();
    270   */
     223
    271224  GraphicsEngine::leave2DMode();
    272225}
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4832 r4834  
    1616
    1717#include "weapon.h"
    18 #include "weapon_manager.h"
    1918
     19#include "projectile.h"
     20
     21#include "load_param.h"
    2022#include "vector.h"
    21 #include "projectile.h"
    2223#include "list.h"
    2324#include "state.h"
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4833 r4834  
    1919#include "weapon_manager.h"
    2020#include "weapon.h"
    21 
     21#include "crosshair.h"
     22
     23#include "load_param.h"
     24#include "factory.h"
    2225#include "vector.h"
    2326#include "list.h"
     
    5356      this->configs[i].slots[j] = NULL;
    5457  }
    55 }
    56 
     58
     59  // crosshair being a PNode it must not be deleted (this is because PNodes delete themselves.)
     60  //delete this->crosshair;
     61}
     62
     63/**
     64 * initializes the WeaponManager
     65 */
    5766void WeaponManager::init()
    5867{
     
    6675  }
    6776  this->currConfID = W_CONFIG0;
    68 
     77  this->crosshair = new Crosshair();
     78}
     79
     80/**
     81 *
     82 * @param root the XML-element to load from
     83 */
     84void WeaponManager::loadParams(const TiXmlElement* root)
     85{
     86  static_cast<BaseObject*>(this)->loadParams(root);
     87
     88  LoadParam<WeaponManager>(root, "slot-count", this, &WeaponManager::setSlotCount)
     89      .describe("how many slots(cannons) the WeaponManager can handle");
     90
     91  LOAD_PARAM_START_CYCLE;
     92
     93  LoadParam<WeaponManager>(root, "Weapons", this, &WeaponManager::loadWeapons)
     94      .describe("loads Weapons");
     95      // LoadParam<WeaponManager>(root, "Weapon", this, &WeaponManager::addWeapon);
     96
     97  LOAD_PARAM_END_CYCLE;
     98}
     99
     100/**
     101 * loads a Weapon onto the WeaponManager
     102 * @param root the XML-element to load the Weapons from
     103 */
     104void WeaponManager::loadWeapons(const TiXmlElement* root)
     105{
     106  LOAD_PARAM_START_CYCLE;
     107
     108  Weapon* newWeapon = dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(element));
     109
     110
     111
     112  LOAD_PARAM_END_CYCLE;
     113}
     114
     115
     116/**
     117 * sets the number of Slots the WeaponManager has
     118 * @param nrOfSlots the number of slots
     119 */
     120void WeaponManager::setSlotCount(int nrOfSlots)
     121{
     122  this->nrOfSlots = nrOfSlots;
    69123}
    70124
     
    100154}
    101155
    102 
     156/**
     157 * removes a Weapon from the WeaponManager
     158 */
    103159void WeaponManager::removeWeapon(Weapon* weapon, int configID)
    104160{
     
    163219    if( firingWeapon != NULL) firingWeapon->fire();
    164220  }
     221  this->crosshair->setRotationSpeed(-500);
    165222}
    166223
     
    178235    if( w != NULL) w->tick(dt);
    179236  }
     237
     238  crosshair->tick(dt);
     239  crosshair->setRotationSpeed(5);
    180240}
    181241
     
    193253      w->draw();
    194254  }
     255  crosshair->draw();
    195256}
    196257
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.h

    r4833 r4834  
    3232// FORWARD DECLARATION
    3333class Weapon;
     34class Crosshair;
    3435
    3536#define    W_MAX_SLOTS       8
     
    7172    void init();
    7273    void loadParams(const TiXmlElement* root);
     74    void loadWeapons(const TiXmlElement* root);
     75
     76    void setSlotCount(int nrOfSlots);
    7377
    7478    void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
     
    8185
    8286  private:
     87    Crosshair*            crosshair;               //!< an aim.
     88
    8389    int                   nrOfSlots;               //<! number of weapon slots a ship has
    8490    int                   currConfID;              //<! the currently selected config
Note: See TracChangeset for help on using the changeset viewer.