Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Objects now get cleanly ereased.
This is a fix in the Weapon-class, that kills the Resurected Projectiles created for information-gathering

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