Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 3:54:49 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/world_entities/projectile.cc

    r3605 r3746  
    1818
    1919#include "projectile.h"
    20 #include "stdincl.h"
     20
    2121#include "world_entity.h"
     22#include "weapon.h"
     23#include "null_parent.h"
     24#include "model.h"
    2225#include "vector.h"
    23 #include "objModel.h"
    2426
    2527using namespace std;
     
    2931   \brief standard constructor
    3032*/
    31 Projectile::Projectile () : WorldEntity()
     33Projectile::Projectile (Weapon* weapon) : WorldEntity()
    3234{
    33   this->model = new OBJModel("");
     35  this->model = (Model*)ResourceManager::getInstance()->load("sphere", PRIM, RP_LEVEL);
     36  this->weapon = weapon;
     37  this->flightDirection = NULL;
     38  this->currentLifeTime = 0.0f;
     39  this->ttl = 0.75f; /* sec */
     40  this->speed = 2.0f;
    3441}
    3542
     
    4047Projectile::~Projectile ()
    4148{
    42 
     49  /*
     50     do not delete the test projectModel, since it is pnode
     51     and will be cleaned out by world
     52  */
     53  //delete this->projectileModel;
    4354}
    4455
     56
     57/**
     58   \brief this sets the flight direction of the projectile
     59   \param directin in which to flight
     60
     61   this function will calculate a vector out of this to be used in the
     62   tick function
     63*/
     64void Projectile::setFlightDirection(Quaternion flightDirection)
     65{
     66  if( this->flightDirection == NULL)
     67    this->flightDirection = new Vector();
     68  Vector v(1, 0, 0);
     69  *this->flightDirection = flightDirection.apply(v);
     70  this->flightDirection->normalize();
     71}
     72
     73
     74/**
     75   \brief this sets the time to life of the projectile
     76   \param ttl in second
     77
     78   after this life time, the projectile will garbage collect itself
     79*/
     80void Projectile::setTTL(float ttl)
     81{
     82  this->ttl = ttl;
     83}
     84
     85
     86/**
     87   \brief sets the speed of the projectile
     88*/
     89void Projectile::setSpeed(float speed)
     90{
     91  this->speed = speed * 3; /* fix speed settings */
     92  PRINTF(4)("Projectile::setting speed to: %f\n", this->speed);
     93}
    4594
    4695/**
     
    4998*/
    5099void Projectile::tick (float time)
    51 {}
     100{
     101  Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.7);
     102  this->shiftCoor(v);
     103
     104  this->currentLifeTime += time;
     105  if( this->ttl < this->currentLifeTime)
     106    {
     107      PRINTF(5)("FINALIZE==========================\n");
     108      PRINTF(5)("current life time is: %f/%f\n", this->currentLifeTime, this->ttl);
     109      PRINTF(5)("FINALIZE===========================\n");
     110      this->finalize();
     111      this->currentLifeTime = 0.0f;
     112    }
     113}
    52114
    53115/**
Note: See TracChangeset for help on using the changeset viewer.