Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/aiming_turret.cc @ 10767

Last change on this file since 10767 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 4.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific
12   main-programmer: Benjamin Grauer
13   co-programmer:
14*/
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "aiming_turret.h"
18
19#include "weapon_manager.h"
20#include "aim.h"
21#include "world_entities/projectiles/projectile.h"
22
23#include "model.h"
24
25#include "animation3d.h"
26
27#include "util/loading/factory.h"
28
29
30ObjectListDefinition(AimingTurret);
31CREATE_FACTORY(AimingTurret);
32
33
34
35/**
36 *  standard constructor
37
38   creates a new weapon
39*/
40AimingTurret::AimingTurret ()
41    : Weapon(), target(this)
42{
43  this->init();
44  this->loadModel("models/guns/turret2.obj");
45}
46
47
48AimingTurret::AimingTurret(const TiXmlElement* root)
49    : target(this)
50{
51  this->init();
52  if (root != NULL)
53    this->loadParams(root);
54}
55
56/**
57 *  standard deconstructor
58*/
59AimingTurret::~AimingTurret ()
60{
61  // model will be deleted from WorldEntity-destructor
62  //  delete this->target;
63}
64
65void AimingTurret::init()
66{
67  this->registerObject(this, AimingTurret::_objectList);
68
69  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
70  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
71
72  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
75  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
76
77  animation1->setInfinity(ANIM_INF_CONSTANT);
78  animation2->setInfinity(ANIM_INF_CONSTANT);
79
80  this->setStateDuration(WS_SHOOTING, .9);
81  this->setStateDuration(WS_RELOADING, .1);
82  this->setStateDuration(WS_ACTIVATING, .4);
83  this->setStateDuration(WS_DEACTIVATING, .4);
84
85  this->setEnergyMax(10000);
86  this->increaseEnergy(100000);
87
88  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
89  this->setProjectileTypeC("GuidedMissile");
90
91
92  this->setEmissionPoint(1.684, 0.472, 0);
93  //this->getProjectileFactory()->prepare(100);
94
95  this->target.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT | PNODE_PROHIBIT_CHILD_DELETE);
96  this->target.setVisibility(false);
97  this->target.setRange(400);
98  this->target.setAngle(M_PI_2);
99
100  this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_3.wav");
101  this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav");
102//   this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav");
103
104}
105
106void AimingTurret::loadParams(const TiXmlElement* root)
107{
108  Weapon::loadParams(root);
109
110}
111
112void AimingTurret::activate()
113{
114  this->target.setVisibility(true);
115}
116
117void AimingTurret::deactivate()
118{
119  this->target.setVisibility(false);
120}
121
122void AimingTurret::tick(float dt)
123{
124  if (!Weapon::tickW(dt))
125    return;
126  Quaternion quat;
127  Vector direction = this->target.getAbsCoor() - this->getAbsCoor();
128
129  direction.normalize();
130
131  if (likely (this->getParent() != NULL))
132    //quat = Quaternion(direction, this->getParent()->getAbsDirY()) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
133    quat = Quaternion ( M_PI_2, this->getParent()->getAbsDirY()) * Quaternion::lookAt(this->getAbsCoor(), this->target.getAbsCoor(), this->getParent()->getAbsDirY());
134  else
135    //quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
136    quat = Quaternion ( M_PI_2, Vector(0,1,0)) * Quaternion::lookAt(this->getAbsCoor(), this->target.getAbsCoor(), Vector(0,1,0));
137
138  this->setAbsDirSoft(quat, 5);
139
140  this->target.tick(dt);
141}
142
143void AimingTurret::fire()
144{
145  Projectile* pj = this->getProjectile();
146  if (pj == NULL)
147    return;
148
149  pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDirX()*250.0 + VECTOR_RAND(4)
150                                          /*target.getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
151
152  pj->setParent(PNode::getNullParent());
153  pj->setAbsCoor(this->getEmissionPoint());
154  pj->setAbsDir(this->getAbsDir());
155  pj->activate();
156}
157
158
159/**
160 * draws the AimingTurret
161*/
162void AimingTurret::draw () const
163{
164  /* draw gun body */
165  glMatrixMode(GL_MODELVIEW);
166  glPushMatrix();
167  glTranslatef (this->getAbsCoor ().x,
168                this->getAbsCoor ().y,
169                this->getAbsCoor ().z);
170  Vector tmpRot = this->getAbsDir().getSpacialAxis();
171  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
172
173  if (this->getModel())
174    this->getModel()->draw();
175  glPopMatrix();
176}
177
Note: See TracBrowser for help on using the repository browser.