Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6002 in orxonox.OLD for trunk


Ignore:
Timestamp:
Dec 9, 2005, 5:30:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented the helicopter

Location:
trunk/src
Files:
4 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r5996 r6002  
    8282                  world_entities/power_ups/laser_power_up.cc \
    8383                  world_entities/space_ships/space_ship.cc \
     84                  world_entities/space_ships/helicopter.cc \
    8485                  subprojects/benchmark.cc
    8586
     
    122123                 world_entities/power_ups/turret_power_up.h \
    123124                 world_entities/power_ups/laser_power_up.h \
     125                 world_entities/space_ships/space_ship.h \
     126                 world_entities/space_ships/helicopter.h \
    124127                 defs/stdincl.h \
    125128                 defs/stdlibincl.h \
  • trunk/src/defs/class_id.h

    r5996 r6002  
    145145  CL_TEST_ENTITY                =    0x00000209,
    146146  CL_SPACE_SHIP                 =    0x0000020a,
     147  CL_HELICOPTER                 =    0x0000020b,
    147148
    148149  CL_TURRET_POWER_UP            =    0x00000211,
  • trunk/src/world_entities/space_ships/helicopter.cc

    r5999 r6002  
    1010
    1111### File Specific:
    12    main-programmer: Benjamin Knecht
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414
     
    1717#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    1818
    19 #include "executor/executor.h"
    20 #include "space_ship.h"
     19#include "helicopter.h"
    2120
    2221#include "objModel.h"
     
    3635using namespace std;
    3736
    38 CREATE_FACTORY(SpaceShip, CL_SPACE_SHIP);
     37CREATE_FACTORY(Helicopter, CL_HELICOPTER);
    3938
    4039/**
    4140 *  creates the controlable Spaceship
    4241 */
    43 SpaceShip::SpaceShip()
     42Helicopter::Helicopter()
    4443{
    4544  this->init();
     
    4948 *  destructs the spaceship, deletes alocated memory
    5049 */
    51 SpaceShip::~SpaceShip ()
     50Helicopter::~Helicopter ()
    5251{
    5352}
     
    5756 * @param fileName the name of the File to load the spaceship from (absolute path)
    5857 */
    59 SpaceShip::SpaceShip(const char* fileName)
     58Helicopter::Helicopter(const char* fileName)
    6059{
    6160  this->init();
     
    6463  if(!doc.LoadFile())
    6564  {
    66     PRINTF(2)("Loading file %s failed for spaceship.\n", fileName);
     65    PRINTF(2)("Loading file %s failed for Helicopter.\n", fileName);
    6766    return;
    6867  }
     
    7776   @todo add more parameters to load
    7877*/
    79 SpaceShip::SpaceShip(const TiXmlElement* root)
     78Helicopter::Helicopter(const TiXmlElement* root)
    8079{
    8180  this->init();
     
    105104 * initializes a Spaceship
    106105 */
    107 void SpaceShip::init()
     106void Helicopter::init()
    108107{
    109108//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
    110   this->setClassID(CL_SPACE_SHIP, "SpaceShip");
     109  this->setClassID(CL_HELICOPTER, "Helicopter");
    111110
    112111  PRINTF(4)("SPACESHIP INIT\n");
     112
     113  this->loadModel("models/ships/helicopter_high.obj", 1.0, 0);
     114  this->loadModel("models/ships/helicopter_medium.obj", 1.0, 1);
     115  this->loadModel("models/ships/helicopter_low.obj", 1.0, 2);
    113116
    114117  EventHandler::getInstance()->grabEvents(true);
     
    177180
    178181/**
    179  * loads the Settings of a SpaceShip from an XML-element.
     182 * loads the Settings of a Helicopter from an XML-element.
    180183 * @param root the XML-element to load the Spaceship's properties from
    181184 */
    182 void SpaceShip::loadParams(const TiXmlElement* root)
     185void Helicopter::loadParams(const TiXmlElement* root)
    183186{
    184187  static_cast<WorldEntity*>(this)->loadParams(root);
     
    190193 * @param weapon to add
    191194*/
    192 void SpaceShip::addWeapon(Weapon* weapon)
     195void Helicopter::addWeapon(Weapon* weapon)
    193196{
    194197  this->getWeaponManager()->addWeapon(weapon);
     
    200203 * @param weapon to remove
    201204*/
    202 void SpaceShip::removeWeapon(Weapon* weapon)
     205void Helicopter::removeWeapon(Weapon* weapon)
    203206{
    204207  this->getWeaponManager()->removeWeapon(weapon);
     
    206209
    207210/**
    208  *  effect that occurs after the SpaceShip is spawned
    209 */
    210 void SpaceShip::postSpawn ()
     211 *  effect that occurs after the Helicopter is spawned
     212*/
     213void Helicopter::postSpawn ()
    211214{
    212215  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
     
    216219 *  the action occuring if the spaceship left the game
    217220*/
    218 void SpaceShip::leftWorld ()
     221void Helicopter::leftWorld ()
    219222{}
    220223
    221 WorldEntity* ref = NULL;
    222224/**
    223225 *  this function is called, when two entities collide
     
    226228 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
    227229 */
    228 void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location)
    229 {
    230   if (entity->isA(CL_TURRET_POWER_UP) && entity != ref)
     230void Helicopter::collidesWith(WorldEntity* entity, const Vector& location)
     231{
     232  if (entity->isA(CL_TURRET_POWER_UP))
    231233  {
    232234    this->ADDWEAPON();
    233     ref = entity;
    234235    }
    235236//  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
    236237}
    237238
    238 /**
    239  *  draws the spaceship after transforming it.
    240 */
    241 void SpaceShip::draw () const
    242 {
    243   glMatrixMode(GL_MODELVIEW);
    244   glPushMatrix();
    245   /* translate */
    246   glTranslatef (this->getAbsCoor ().x,
    247                 this->getAbsCoor ().y,
    248                 this->getAbsCoor ().z);
    249   /* rotate */
    250   Vector tmpRot = this->getAbsDir().getSpacialAxis();
    251   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    252   this->getModel()->draw();
    253   glPopMatrix();
    254 
    255   this->getWeaponManager()->draw();
    256 
    257   //this->debug(0);
    258 }
     239
    259240
    260241/**
     
    262243 * @param time The timespan passed since last update
    263244*/
    264 void SpaceShip::tick (float time)
     245void Helicopter::tick (float time)
    265246{
    266247     cycle += time;
     
    290271 * @param time the timeslice since the last frame
    291272*/
    292 void SpaceShip::calculateVelocity (float time)
     273void Helicopter::calculateVelocity (float time)
    293274{
    294275  Vector accel(0.0, 0.0, 0.0);
     
    372353 * weapon manipulation by the player
    373354*/
    374 void SpaceShip::weaponAction()
     355void Helicopter::weaponAction()
    375356{
    376357  if( this->bFire)
     
    383364 * @todo switch statement ??
    384365 */
    385 void SpaceShip::process(const Event &event)
     366void Helicopter::process(const Event &event)
    386367{
    387368
     
    412393#include "weapons/aiming_turret.h"
    413394// FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG
    414 void SpaceShip::ADDWEAPON()
     395void Helicopter::ADDWEAPON()
    415396{
    416397  Weapon* turret = NULL;
  • trunk/src/world_entities/space_ships/helicopter.h

    r5999 r6002  
    11
    22/*!
    3  * @file space_ship.h
    4  * Implements the Control of a Spaceship
     3 * @file helicopter.h
     4 * Implements the Control of a Helicopter
    55 */
    66
    7 #ifndef _SPACE_SHIP_H
    8 #define _SPACE_SHIP_H
     7#ifndef _HELICOPTER_H
     8#define _HELICOPTER_H
    99
    1010#include "playable.h"
    1111
    12 template<class T> class tList;
    13 class Vector;
    14 class Event;
    1512
    16 class SpaceShip : public Playable
     13class Helicopter : public Playable
    1714{
    1815
    1916  public:
    2017
    21     SpaceShip();
    22     SpaceShip(const char* fileName);
    23     SpaceShip(const TiXmlElement* root);
    24     virtual ~SpaceShip();
     18    Helicopter();
     19    Helicopter(const char* fileName);
     20    Helicopter(const TiXmlElement* root);
     21    virtual ~Helicopter();
    2522
    2623    void init();
     
    3532    virtual void collidesWith(WorldEntity* entity, const Vector& location);
    3633    virtual void tick(float time);
    37     virtual void draw() const;
    3834
    3935    virtual void process(const Event &event);
     
    7167};
    7268
    73 #endif /* _SPACE_SHIPS_H */
     69#endif /* _HELICOPTERS_H */
  • trunk/src/world_entities/space_ships/space_ship.cc

    r5994 r6002  
    2020#include "space_ship.h"
    2121
    22 #include "objModel.h"
    2322#include "resource_manager.h"
    2423
  • trunk/src/world_entities/world_entity.cc

    r5996 r6002  
    2727#include "obb_tree.h"
    2828
     29#include "state.h"
     30
    2931using namespace std;
    3032
     
    9597    PRINTF(4)("fetching %s\n", fileName);
    9698    if (scaling == 1.0)
    97       this->setModel((Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN));
     99      this->setModel((Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN), modelNumber);
    98100    else
    99       this->setModel((Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, &scaling));
    100 
     101      this->setModel((Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, &scaling), modelNumber);
     102    if (modelNumber == 0)
    101103    this->buildObbTree(4);
    102104  }
     
    227229void WorldEntity::draw() const
    228230{
    229   glMatrixMode(GL_MODELVIEW);
    230   glPushMatrix();
    231   float matrix[4][4];
    232 
    233   /* translate */
    234   glTranslatef (this->getAbsCoor ().x,
    235                 this->getAbsCoor ().y,
    236                 this->getAbsCoor ().z);
    237   /* rotate */ // FIXME: devise a new Way to rotate this
    238   this->getAbsDir ().matrix (matrix);
    239   glMultMatrixf((float*)matrix);
    240 
    241   if (this->models[0])
    242     this->models[0]->draw();
    243   glPopMatrix();
     231  if (!this->models.empty())
     232  {
     233    glMatrixMode(GL_MODELVIEW);
     234    glPushMatrix();
     235    float matrix[4][4];
     236
     237    /* translate */
     238    glTranslatef (this->getAbsCoor ().x,
     239                  this->getAbsCoor ().y,
     240                  this->getAbsCoor ().z);
     241   /* rotate */ // FIXME: devise a new Way to rotate this
     242    this->getAbsDir ().matrix (matrix);
     243    glMultMatrixf((float*)matrix);
     244
     245    float cameraDistance = (State::getCamera()->getAbsCoor() - this->getAbsCoor()).len();
     246    if (this->isA(CL_HELICOPTER))
     247        printf("Test %f %d\n", cameraDistance, this->models.size());
     248    if (cameraDistance > 100 && this->models.size() >= 3 && this->models[2] != NULL)
     249    {
     250      if (this->isA(CL_HELICOPTER))printf("====== 2 ===\n");
     251       this->models[2]->draw();
     252    }
     253    else if (cameraDistance > 50 && this->models.size() >= 2 && this->models[1] != NULL)
     254    {
     255      if (this->isA(CL_HELICOPTER))printf("====== 1 ===\n");
     256      this->models[1]->draw();
     257    }
     258    else if (this->models.size() >= 1 && this->models[0] != NULL)
     259    {
     260      if (this->isA(CL_HELICOPTER))printf("====== 0 ===\n");
     261      this->models[0]->draw();
     262    }
     263    glPopMatrix();
     264  }
    244265}
    245266
Note: See TracChangeset for help on using the changeset viewer.