Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

orxonox/trunk: implemented aim

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

Legend:

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

    r4826 r4830  
    2323#include "p_node.h"
    2424#include "state.h"
     25#include "model.h"
    2526
    2627#include <iostream>
     
    3738  this->setName("Crosshair");
    3839
     40  this->material = NULL;
     41  this->model = NULL;
     42  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();
     62
    3963  EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
    4064
     
    4771Crosshair::~Crosshair ()
    4872{
     73 // delete this->model;
     74
    4975  // delete what has to be deleted here
    5076  EventHandler::getInstance()->unsubscribe(this);
     
    81107
    82108
    83 void Crosshair::draw() const
     109void Crosshair::draw()
    84110{
    85111  /*
     
    118144  GraphicsEngine::storeMatrices();
    119145
    120   float z;
    121   glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
    122 
    123 
    124   printf("%f %f %f\n", (int)position2D[0], (int)position2D[1], z);
     146///  float z;
     147//   glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
     148
    125149
    126150  //cout << z <<"  "<< scale << "  "  << bias<< endl;
     151
    127152
    128153  GLdouble objX, objY, objZ;
    129154  gluUnProject(position2D[0],
    130155               GraphicsEngine::getInstance()->getResolutionY()-position2D[1]-1,
    131                .5,
     156               .99,
    132157               GraphicsEngine::modMat,
    133158               GraphicsEngine::projMat,
     
    137162               &objZ );
    138163
    139   glBegin(GL_TRIANGLES);
    140   glColor3f(1,0,0);
    141   glVertex3f(objX, objY, objZ);
    142   glVertex3f(objX, objY+1, objZ);
    143   glVertex3f(objX, objY, objZ+1);
     164  this->setAbsCoor(objX, objY, objZ);
     165
     166//   glBegin(GL_TRIANGLES);
     167//   glColor3f(1,0,0);
     168//   glVertex3f(objX, objY, objZ);
     169//   glVertex3f(objX, objY+1, objZ);
     170//   glVertex3f(objX, objY, objZ+1);
     171//   glEnd();
     172
     173
     174  GraphicsEngine::enter2DMode();
     175  GLdouble pos[3];
     176  gluProject(this->getAbsCoor().x,
     177             this->getAbsCoor().y,
     178             this->getAbsCoor().z,
     179             GraphicsEngine::modMat,
     180             GraphicsEngine::projMat,
     181             GraphicsEngine::viewPort,
     182             pos, pos+1, pos+2 );
     183
     184  printf("%d %d %d\n", (int)pos[0], (int)pos[1], (int)pos[2]);
     185  this->rotation += 5;
     186
     187  glTranslatef(position2D[0], position2D[1], 0);
     188  glRotatef(this->rotation, 0,0,1);
     189  this->model->draw();
     190  /*
     191  glBegin(GL_QUADS);
     192  {
     193    glColor4f(1,0,0,1);
     194    glVertex2f(position2D[0]-10, position2D[1]-10);
     195    glVertex2f(position2D[0]+10, position2D[1]-10);
     196    glVertex2f(position2D[0]+10, position2D[1]+10);
     197    glVertex2f(position2D[0]-10, position2D[1]+10);
     198
     199    //     glVertex2f(pos[0]-10, pos[1]-10);
     200    //     glVertex2f(pos[0]-10, pos[1]+10);
     201    //     glVertex2f(pos[0]+10, pos[1]+10);
     202    //     glVertex2f(pos[0]+10, pos[1]-10);
     203  }
    144204  glEnd();
    145 }
     205  */
     206  GraphicsEngine::leave2DMode();
     207}
  • orxonox/trunk/src/world_entities/weapons/crosshair.h

    r4781 r4830  
    99
    1010#include "event_listener.h"
    11 
     11#include "p_node.h"
    1212#include "vector.h"
    1313
    1414// FORWARD DEFINITION
    15 
     15class Model;
     16class Material;
    1617
    1718//! A class that enables the
    18 class Crosshair : public EventListener {
     19class Crosshair : public PNode, public EventListener {
    1920
    2021 public:
     
    2526  virtual void process(const Event &event);
    2627
    27   /** @returns the current 3D-position of the Crosshair */
    28   const Vector& getPosition() { return this->position; };
    29 
    3028  void tick(float dt);
    31   void draw() const;
     29  void draw();
    3230
    3331 private:
    34    Vector           position;             //!< The current position of the Crosshair
    3532   float            position2D[2];        //!< The 2D-position on the screen
    3633
     34   Model*           model;                //!< A model for the crosshair representing the Aim
     35   Material*        material;             //!< a material for the Aim.
     36   float            rotation;             //!< a rotation of the aim.
     37   float            size;                 //!< The Size of the Crosshair (in % of screen resolution 1 is fullscreen)
    3738};
    3839
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4828 r4830  
    3333  this->setRelCoor(coordinate);
    3434  this->setRelDir(direction);
    35   this->worldEntities = State::getWorldEntityList();
    3635}
    3736
     
    156155   can destroy the weapons of enemies or vice versa.
    157156*/
    158 void Weapon::hit (WorldEntity* entity, Vector* position)
     157void Weapon::hit (WorldEntity* entity, const Vector& position)
    159158{}
    160159
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4827 r4830  
    3232class TiXmlElement;
    3333
     34//! An enumerator defining actions a Weapon can take
     35typedef enum {
     36  WA_NONE          =    0,    //!< No Action taken
     37  WA_SHOOT         =    1,    //!< emitting Shot
     38  WA_CHARGE        =    2,    //!< charge action (one click before the shot)
     39  WA_RELOAD        =    3,    //!< reload right after shoot is finished
     40  WA_ACTIVATE      =    4,    //!< activate the GUN
     41  WA_DEACTIVATE    =    5,    //!< deactivate the GUN
     42  WA_SPECIAL1      =    6,    //!< Special Action taken
    3443
    35 // typedef enum {
    36 //   W_SHOOT,
    37 //   W_EMPTY,
    38 //   W_RELOAD,
    39 //   W_SPECIAL1,
    40 //   W_SPECIAL2,
    41 //   W_SPECIAL3
    42 // } WeaponSoundType;
    43 
     44  WA_ACTION_COUNT  =    6     //!< This must match the count of enumerations (without W_NONE)
     45} WeaponActions;
    4446
    4547//! An enumerator defining the States of a Weapon
    4648typedef enum {
    47   W_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
    48   W_SHOOT         =    1,    //!< The State of the Shooting
    49   W_RELOAD        =    2,    //!< The State of the Reloading
    50   W_ACTIVATING    =    3,    //!< The State in which the weapon gets activated
    51   W_DEACTIVATING  =    4,    //!< The State in which the weapon gets deactivated
    52   W_INACTIVE      =    5,    //!< The State where the weapon is inactive (unable to shoot)
    53   W_IDLE          =    6,    //!< The State where the weapon is idle
     49  WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
     50  WS_SHOOTING      =    1,    //!< The State of the Shooting
     51  WS_RELOADING     =    3,    //!< The State of the Reloading
     52  WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
     53  WS_DEACTIVATING  =    5,    //!< The State in which the weapon gets deactivated
     54  WS_INACTIVE      =    6,    //!< The State where the weapon is inactive (unable to shoot)
     55  WS_IDLE          =    7,    //!< The State where the weapon is idle
    5456
    55   W_STATES_COUNT  =    6     //!< This must match the count of the enumerations (without W_NONE)
     57  WS_STATE_COUNT  =    7     //!< This must match the count of the enumerations (without W_NONE)
    5658} WeaponState;
    5759
    5860
    5961//! a weapon can be left or right sided
     62/**
     63 * @todo this will be reset with mirror X/Y/Z
     64 */
    6065#define    W_LEFT        0
    6166#define    W_RIGHT       1
     
    99104  /** @brief fires the weapon */
    100105  virtual void fire() = 0;
    101   virtual void hit (WorldEntity* weapon, Vector* loc);
     106  virtual void hit (WorldEntity* weapon, const Vector& loc);
    102107  virtual void destroy();
    103108
     
    107112
    108113 protected:
    109   tList<WorldEntity>*  worldEntities;
    110114
    111   float                localTime;                 //<! this is the local time. important for shooting attributes like frequency
    112   float                idleTime;                  //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
    113   float                slowDownFactor;            //<! if the shooting frequency is a linear function of time...
     115  float                localTime;                        //<! this is the local time. important for shooting attributes like frequency
     116  float                idleTime;                         //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
     117  float                slowDownFactor;                   //<! if the shooting frequency is a linear function of time...
     118
     119  ////////////
     120  // PHASES //
     121  ////////////
     122  float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState
     123  SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction
     124
     125
    114126
    115127  SoundBuffer*         fireSound;
     
    118130
    119131 private:
    120   bool                 enabled;                    //<! states if the weapon is enabled or not
    121   Projectile*          projectile;          //<! the projectile used for this weapon
     132  bool                 enabled;                          //<! states if the weapon is enabled or not
     133  Projectile*          projectile;                       //<! the projectile used for this weapon
    122134  //WeaponSound sound;
    123135};
Note: See TracChangeset for help on using the changeset viewer.