Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/weapons/projectile.cc @ 4890

Last change on this file since 4890 was 4890, checked in by bensch, 19 years ago

orxonox/trunk: remake of the Projectile and TestBullet

File size: 2.4 KB
RevLine 
[3573]1
2
[4597]3/*
[3573]4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific
14   main-programmer: Patrick Boenzli
[4597]15   co-programmer:
[3573]16*/
17
18
19#include "projectile.h"
[3618]20
[3573]21#include "world_entity.h"
[3683]22#include "weapon.h"
[3646]23#include "null_parent.h"
[3678]24#include "model.h"
[3573]25#include "vector.h"
26
27using namespace std;
28
29
[3578]30/**
[4836]31 *  standard constructor
[3578]32*/
[3683]33Projectile::Projectile (Weapon* weapon) : WorldEntity()
[3573]34{
[4322]35  this->setClassID(CL_PROJECTILE, "Projectile");
[4597]36
[3683]37  this->weapon = weapon;
[4890]38  this->lifeCycle = 0.0;
39  this->lifeSpan = 0.75f; /* sec */
[3573]40}
41
42
[3578]43/**
[4836]44 *  standard deconstructor
[3578]45*/
[4597]46Projectile::~Projectile ()
[3573]47{
[4597]48  /*
49     do not delete the test projectModel, since it is pnode
50     and will be cleaned out by world
[3629]51  */
52  //delete this->projectileModel;
[3573]53}
54
[3578]55
56/**
[4836]57 *  this sets the flight direction of the projectile
58 * @param directin in which to flight
[3632]59
60   this function will calculate a vector out of this to be used in the
61   tick function
62*/
[3708]63void Projectile::setFlightDirection(Quaternion flightDirection)
[3632]64{
65  Vector v(1, 0, 0);
[4890]66  this->flightDirection = flightDirection.apply(v);
67  this->flightDirection.normalize();
[3632]68}
69
70/**
[4836]71 *  sets the velocity vector to a spec speed
72 * @param velocity: vector of the velocity
[4464]73*/
74void Projectile::setVelocity(const Vector &velocity)
75{
[4890]76  Vector offsetVel = this->velocity = velocity;
77  offsetVel.normalize();
78  this->velocity += (offsetVel * 50.0);
[4464]79}
80
81
82/**
[4836]83 *  signal tick, time dependent things will be handled here
84 * @param time since last tick
[3578]85*/
[4597]86void Projectile::tick (float time)
[3632]87{
[4464]88  Vector v = this->velocity * (time);
[3686]89  this->shiftCoor(v);
[3683]90
[4890]91  this->lifeCycle += time/this->lifeSpan;
92  if( this->lifeCycle >= 1)
93  {
94    PRINTF(5)("FINALIZE==========================\n");
95    PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
96    PRINTF(5)("FINALIZE===========================\n");
97    this->finalize();
98  }
[3632]99}
[3573]100
101
[3578]102/**
[4836]103 *  the function gets called, when the projectile is destroyed
[3578]104*/
[4597]105void Projectile::destroy ()
[3574]106{}
[3573]107
108
[4597]109void Projectile::draw ()
[3573]110{
111  glMatrixMode(GL_MODELVIEW);
112  glPushMatrix();
[3574]113
[4597]114  float matrix[4][4];
[3573]115  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
116  this->getAbsDir().matrix (matrix);
[4597]117  glMultMatrixf((float*)matrix);
[3672]118  this->model->draw();
[3573]119
120  glPopMatrix();
121}
122
Note: See TracBrowser for help on using the repository browser.