Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/weapons/test_gun.cc @ 6693

Last change on this file since 6693 was 6693, checked in by patrick, 18 years ago

branches: removed spaceshipcontrol branche

File size: 6.2 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*/
[5357]21#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3618]22
23#include "test_gun.h"
[6434]24#include "world_entities/projectiles/projectile.h"
[3618]25
26#include "world_entity.h"
[6022]27#include "static_model.h"
[4955]28#include "weapon_manager.h"
[5355]29#include "factory.h"
[3618]30
[3851]31#include "animation3d.h"
[3618]32
[4940]33#include "fast_factory.h"
[4287]34
[4931]35
[3618]36using namespace std;
37
[5750]38CREATE_FACTORY(TestGun, CL_TEST_GUN);
[3618]39
40/**
[4836]41 *  standard constructor
[3618]42
43   creates a new weapon
44*/
[5750]45TestGun::TestGun ( int leftRight)
46  : Weapon()
[3683]47{
[4974]48  this->init();
49
50
[3755]51  this->leftRight = leftRight;
[3752]52
[3886]53  this->objectComponent1 = new PNode();
[4895]54  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
55  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
56  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
[3986]57  //parent->addChild(this->objectComponent1, PNODE_ALL);
[5382]58  this->addChild(this->objectComponent1);
[3755]59
[4893]60  animation1->setInfinity(ANIM_INF_CONSTANT);
61  animation2->setInfinity(ANIM_INF_CONSTANT);
62  animation3->setInfinity(ANIM_INF_CONSTANT);
[4972]63
[3886]64  if( this->leftRight == W_LEFT)
[4972]65  {
[5459]66    this->setEmissionPoint(1.0, -0.6, -0.2);
[3888]67
[5062]68    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
69    animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
70    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
[3986]71
[5062]72    animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
73    animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
[3986]74
[5062]75    animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
76    animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
[4972]77  }
[3886]78  else if( this->leftRight == W_RIGHT)
[4972]79  {
[5459]80    this->setEmissionPoint(1.0, -0.6, 0.3);
[3888]81
[4972]82    this->objectComponent1->setRelCoor(Vector(0,0,0.35));
[5062]83    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
84    animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
85    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
[3986]86
[5062]87    animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
88    animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
[3993]89
[5062]90    animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
91    animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
[4972]92  }
93}
[4885]94
95
[4972]96TestGun::TestGun(const TiXmlElement* root)
97{
98  this->init();
99  this->loadParams(root);
100}
101
102/**
103 *  standard deconstructor
104*/
105TestGun::~TestGun ()
106{
107  // model will be deleted from WorldEntity-destructor
108}
109
110
111void TestGun::init()
112{
113  this->setClassID(CL_TEST_GUN, "TestGun");
114
[5053]115//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
[4972]116
[5053]117  this->loadModel("models/guns/test_gun.obj");
118
[5457]119  this->setStateDuration(WS_SHOOTING, .1);
120  this->setStateDuration(WS_RELOADING, .1);
[4910]121  this->setStateDuration(WS_ACTIVATING, .4);
122  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]123
[6693]124  this->setEnergyMax(1000);
[5048]125  this->increaseEnergy(1000);
[4927]126  //this->minCharge = 2;
[4885]127
[5819]128  this->setActionSound(WA_SHOOT, "sound/laser.wav");
129  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
[4934]130
[5819]131
[5441]132  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[5456]133  this->setProjectileType(CL_LASER);
[5356]134  this->prepareProjectiles(20);
[5457]135
[3683]136}
[3618]137
138
[4972]139void TestGun::loadParams(const TiXmlElement* root)
[3618]140{
[6512]141  Weapon::loadParams(root);
[4972]142
[3618]143}
144
145
146/**
[4836]147 *  this activates the weapon
[3618]148
[4592]149   This is needed, since there can be more than one weapon on a ship. the
150   activation can be connected with an animation. for example the weapon is
151   been armed out.
[3618]152*/
153void TestGun::activate()
[3980]154{
155}
[3618]156
157
158/**
[4836]159 *  this deactivates the weapon
[3618]160
[4592]161   This is needed, since there can be more than one weapon on a ship. the
162   activation can be connected with an animation. for example the weapon is
[3618]163   been armed out.
164*/
165void TestGun::deactivate()
[3980]166{
167}
[3618]168
169
170/**
[4836]171 *  fires the weapon
[4592]172
[3618]173   this is called from the player.cc, when fire-button is been pushed
[4836]174   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
[3618]175*/
176void TestGun::fire()
[3620]177{
[5356]178  Projectile* pj =  this->getProjectile();
179  if (pj == NULL)
180    return;
[3888]181
[6074]182  pj->setParent(PNode::getNullParent());
[5000]183
[6162]184  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
[4955]185
[4927]186  pj->setAbsCoor(this->getEmissionPoint());
[3708]187  pj->setAbsDir(this->getAbsDir());
[5443]188  pj->activate();
[3620]189}
[3618]190
191/**
[4836]192 *  is called, when the weapon is destroyed
[5498]193 *
194 * this is in conjunction with the hit function, so when a weapon is able to get
195 * hit, it can also be destoryed.
[3618]196*/
[4592]197void TestGun::destroy ()
[3618]198{}
199
200/**
[4836]201 *  this will draw the weapon
[3618]202*/
[5500]203void TestGun::draw () const
[3750]204{
[3886]205  /* draw gun body */
[3750]206  glMatrixMode(GL_MODELVIEW);
207  glPushMatrix();
[4592]208  glTranslatef (this->getAbsCoor ().x,
209                this->getAbsCoor ().y,
210                this->getAbsCoor ().z);
[5000]211
212  Vector tmpRot = this->getAbsDir().getSpacialAxis();
213  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
214
[3886]215  if( this->leftRight == W_RIGHT)
216    glScalef(1.0, 1.0, -1.0);
[6022]217  static_cast<StaticModel*>(this->getModel())->draw(1);
[3752]218  glPopMatrix();
219
[3886]220  /* draw objectComponent1: gun coil - animated stuff */
[3752]221  glMatrixMode(GL_MODELVIEW);
222  glPushMatrix();
[4592]223  glTranslatef (this->objectComponent1->getAbsCoor ().x,
224                this->objectComponent1->getAbsCoor ().y,
225                this->objectComponent1->getAbsCoor ().z);
[5000]226  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
227  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[6022]228  static_cast<StaticModel*>(this->getModel())->draw(0);
[3750]229  glPopMatrix();
230}
[3618]231
Note: See TracBrowser for help on using the repository browser.