Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/weapons/test_gun.cc @ 4938

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

orxonox/trunk: doxygen tags.

File size: 6.4 KB
RevLine 
[3618]1
2
[4592]3/*
[3618]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
[4592]15   co-programmer:
[3631]16
17
[4836]18   @todo: direction in which the projectile flights
19   @todo: a target to set/hit
[3618]20*/
21
22
23#include "test_gun.h"
24
25#include "world_entity.h"
[3677]26#include "model.h"
[3710]27#include "test_bullet.h"
[3618]28
[4829]29#include "state.h"
[3618]30#include "vector.h"
[3629]31#include "list.h"
[3851]32#include "animation3d.h"
[4504]33#include "sound_engine.h"
[3618]34
[4289]35#include "object_manager.h"
[4287]36
[4931]37
[3618]38using namespace std;
39
40
41/**
[4836]42 *  standard constructor
[3618]43
44   creates a new weapon
45*/
[4597]46TestGun::TestGun (PNode* parent, const Vector& coordinate,
47                  const Quaternion& direction, int leftRight)
[4592]48  :  Weapon (parent, coordinate, direction)
[3683]49{
[4320]50  this->setClassID(CL_TEST_GUN, "TestGun");
[4597]51
[3752]52  this->model = (Model*)ResourceManager::getInstance()->load("models/test_gun.obj", OBJ, RP_CAMPAIGN);
[3755]53  this->leftRight = leftRight;
[3752]54
[3886]55  this->objectComponent1 = new PNode();
[4895]56  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
57  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
58  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
[3986]59  //parent->addChild(this->objectComponent1, PNODE_ALL);
60  this->addChild(this->objectComponent1, PNODE_ALL);
[3755]61
[4893]62  animation1->setInfinity(ANIM_INF_CONSTANT);
63  animation2->setInfinity(ANIM_INF_CONSTANT);
64  animation3->setInfinity(ANIM_INF_CONSTANT);
[3886]65  if( this->leftRight == W_LEFT)
[3755]66    {
[4927]67      this->setEmissionPoint(1.0, 0.0, -0.35);
[3888]68
[4893]69      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
70      animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
71      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
[3986]72
[4906]73      animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74      animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
[3986]75
[4906]76      animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
77      animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
[3755]78    }
[3886]79  else if( this->leftRight == W_RIGHT)
[3755]80    {
[4927]81      this->setEmissionPoint(1.0, 0.0, 0.5);
[3888]82
[3987]83      this->objectComponent1->setRelCoor(Vector(0,0,0.35));
[4893]84      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
85      animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
86      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
[3986]87
[4895]88      animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
89      animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
[3993]90
[4895]91      animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
92      animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
[3755]93    }
[4885]94/*
[4504]95  this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV);
96  this->weaponSource = new SoundSource(this->fireSound, this);
[4885]97  this->weaponSource->setRolloffFactor(.1);*/
[4932]98  Projectile* p = new TestBullet();
[4885]99
100  //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
[4389]101  //ObjectManager::getInstance()->debug();
[4885]102
[4906]103  this->setStateDuration(WS_SHOOTING, .4);
104  this->setStateDuration(WS_RELOADING, 1);
[4910]105  this->setStateDuration(WS_ACTIVATING, .4);
106  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]107
[4930]108  this->setMaximumEnergy(1000, 10);
[4927]109  this->increaseEnergy(100);
110  //this->minCharge = 2;
[4885]111
112  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
[4934]113
114  this->bulletFactory = tFastFactory<TestBullet>::getFastFactory(CL_TEST_BULLET, "TestBullet");
115  this->bulletFactory->prepare(100);
[3683]116}
[3618]117
118
119/**
[4836]120 *  standard deconstructor
[3618]121*/
[4592]122TestGun::~TestGun ()
[3618]123{
124  // model will be deleted from WorldEntity-destructor
125}
126
127
128/**
[4836]129 *  this activates the weapon
[3618]130
[4592]131   This is needed, since there can be more than one weapon on a ship. the
132   activation can be connected with an animation. for example the weapon is
133   been armed out.
[3618]134*/
135void TestGun::activate()
[3980]136{
137}
[3618]138
139
140/**
[4836]141 *  this deactivates the weapon
[3618]142
[4592]143   This is needed, since there can be more than one weapon on a ship. the
144   activation can be connected with an animation. for example the weapon is
[3618]145   been armed out.
146*/
147void TestGun::deactivate()
[3980]148{
149}
[3618]150
151
152/**
[4836]153 *  fires the weapon
[4592]154
[3618]155   this is called from the player.cc, when fire-button is been pushed
[4836]156   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
[3618]157*/
158void TestGun::fire()
[3620]159{
[4938]160  Projectile* pj =  dynamic_cast<Projectile*>(this->bulletFactory->resurrect());
[3888]161
[4927]162  pj->setAbsCoor(this->getEmissionPoint());
[3708]163  pj->setAbsDir(this->getAbsDir());
[4464]164  pj->setVelocity(this->getVelocity());
[4829]165  State::getWorldEntityList()->add(pj);
[3620]166}
[3618]167
168
169/**
[4836]170 *  is called, when the weapon gets hit (=collide with something)
171 * @param from which entity it is been hit
172 * @param where it is been hit
[3618]173
174   this may not be used, since it would make the game relay complicated when one
175   can destroy the weapons of enemies or vice versa.
176*/
[4592]177void TestGun::hit (WorldEntity* entity, Vector* position)
[3618]178{}
179
180
181/**
[4836]182 *  is called, when the weapon is destroyed
[3618]183
184   this is in conjunction with the hit function, so when a weapon is able to get
185   hit, it can also be destoryed.
186*/
[4592]187void TestGun::destroy ()
[3618]188{}
189
190/**
[4836]191 *  this will draw the weapon
[3618]192*/
[4592]193void TestGun::draw ()
[3750]194{
[3886]195  /* draw gun body */
[3750]196  glMatrixMode(GL_MODELVIEW);
197  glPushMatrix();
198  float matrix[4][4];
[4592]199  glTranslatef (this->getAbsCoor ().x,
200                this->getAbsCoor ().y,
201                this->getAbsCoor ().z);
[3886]202  this->getAbsDir ().matrix (matrix);
203  glMultMatrixf((float*)matrix);
204  if( this->leftRight == W_RIGHT)
205    glScalef(1.0, 1.0, -1.0);
206  this->model->draw(1);
[3752]207  glPopMatrix();
208
[3886]209  /* draw objectComponent1: gun coil - animated stuff */
[3752]210  glMatrixMode(GL_MODELVIEW);
211  glPushMatrix();
[4592]212  glTranslatef (this->objectComponent1->getAbsCoor ().x,
213                this->objectComponent1->getAbsCoor ().y,
214                this->objectComponent1->getAbsCoor ().z);
[3886]215  this->objectComponent1->getAbsDir ().matrix (matrix);
[3752]216  glMultMatrixf((float*)matrix);
217  this->model->draw(0);
[3750]218  glPopMatrix();
219}
[3618]220
Note: See TracBrowser for help on using the repository browser.