Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6055 was 6022, checked in by bensch, 18 years ago

orxonox/trunk: merged the NewModel branche back to the trunk.
merged with command
svn merge branches/newModel/ trunk/ -r 6016:HEAD
no conflicts

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