Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9617 was 9002, checked in by bensch, 18 years ago

orxonox/trunk: redirect everything to see into the dof of the _centerNode

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