Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/space_ships/turbine_hover.cc @ 7125

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

try fix

File size: 13.1 KB
RevLine 
[6443]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*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
[7000]19#include "turbine_hover.h"
[6443]20
21#include "weapons/weapon_manager.h"
22#include "weapons/test_gun.h"
23#include "weapons/turret.h"
24#include "weapons/cannon.h"
25
26#include "factory.h"
27#include "key_mapper.h"
28#include "event_handler.h"
29#include "state.h"
30
31#include "graphics_engine.h"
[7001]32#include "dot_emitter.h"
33#include "sprite_particles.h"
[6443]34
35using namespace std;
36
[7000]37CREATE_FACTORY(TurbineHover, CL_TURBINE_HOVER);
[6443]38
39/**
[7000]40 *  destructs the turbine_hover, deletes alocated memory
[6443]41 */
[7000]42TurbineHover::~TurbineHover ()
[6986]43{
44  this->setPlayer(NULL);
45}
[6443]46
47/**
[7000]48 * loads a TurbineHover information from a specified file.
49 * @param fileName the name of the File to load the turbine_hover from (absolute path)
[6443]50 */
[7000]51TurbineHover::TurbineHover(const char* fileName)
[6443]52{
53  this->init();
54  TiXmlDocument doc(fileName);
55
56  if(!doc.LoadFile())
57  {
[7000]58    PRINTF(2)("Loading file %s failed for TurbineHover.\n", fileName);
[6443]59    return;
60  }
61
62  this->loadParams(doc.RootElement());
63}
64
65/**
66 *  creates a new Spaceship from Xml Data
67 * @param root the xml element containing spaceship data
68
69   @todo add more parameters to load
70*/
[7000]71TurbineHover::TurbineHover(const TiXmlElement* root)
[6443]72{
73  this->init();
74  if (root != NULL)
75    this->loadParams(root);
76
77  //weapons:
78  Weapon* wpRight = new TestGun(0);
79  wpRight->setName("testGun Right");
80  Weapon* wpLeft = new TestGun(1);
81  wpLeft->setName("testGun Left");
[6811]82  Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_HYPERBLASTER));
[6443]83
84  cannon->setName("BFG");
85
86  this->addWeapon(wpLeft, 1, 0);
87  this->addWeapon(wpRight,1 ,1);
[6803]88  this->addWeapon(cannon, 0, 2);
[6443]89
90  this->getWeaponManager()->changeWeaponConfig(1);
91  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
[6800]92
93  this->loadModel("models/ships/hoverglider_mainbody.obj");
[6443]94}
95
96
97/**
[7000]98 * initializes a TurbineHover
[6443]99 */
[7000]100void TurbineHover::init()
[6443]101{
[6805]102  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
[7000]103  this->setClassID(CL_TURBINE_HOVER, "TurbineHover");
[6443]104
[6807]105  this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3);
[7000]106  this->loadModel("models/ships/hoverglider_turbine.obj", 1.0f, 4);
107  this->loadModel("models/ships/hoverglider_turbine_rotors.obj", 1.0f, 5);
[6443]108
[6805]109  bForward = bBackward = bLeft = bRight = bAscend = bDescend = false;
[6807]110  mouseSensitivity = 0.005;
[6443]111
[6806]112  this->rotorSpeed = 1000.0f;
113  this->rotorCycle = 0.0f;
[6807]114  this->cameraLook = 0.0f;
115  this->rotation = 0.0f;
[7001]116  this->acceleration = 10.0f;
117  this->airFriction = 2.0f;
[6799]118
[7072]119  this->setHealthMax(100);
120  this->setHealth(100);
121
122
[6806]123  // camera - issue
[6800]124  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[6806]125  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
[6880]126  //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT);
[7003]127  //this->cameraNode.setParent(this);
[6799]128
[6724]129  // rotors
[6803]130  this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT );
131  this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
[6801]132  this->wingNodeLeft.setParent(this);
133  this->wingNodeLeft.setRelCoor(-1.5, -.3, -1.0);
[6800]134  this->rotorNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[6801]135  this->rotorNodeLeft.setParent(&this->wingNodeLeft);
136  this->rotorNodeLeft.setRelCoor(0, 1.0, -2.3);
[6799]137
[6801]138  this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[6803]139  this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
[6800]140  this->wingNodeRight.setParent(this);
[6801]141  this->wingNodeRight.setRelCoor(-1.5, -0.3, 1.0);
142  this->rotorNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[6800]143  this->rotorNodeRight.setParent(&this->wingNodeRight);
[6801]144  this->rotorNodeRight.setRelCoor(0, 1.0, 2.3);
[6443]145
[7001]146  // PARTICLES
147  this->burstEmitter[0] = new DotEmitter(200, 5.0, .01);
148  this->burstEmitter[0]->setParent(&this->rotorNodeLeft);
149  this->burstEmitter[0]->setRelCoor(0, -0.7, 0);
150  this->burstEmitter[0]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1)));
151  this->burstEmitter[0]->setName("TurbineHover_Burst_emitter_Left");
[6803]152
[7001]153  this->burstEmitter[1] = new DotEmitter(200, 5.0, .01);
154  this->burstEmitter[1]->setParent(&this->rotorNodeRight);
155  this->burstEmitter[1]->setRelCoor(0, -0.7, 0);
156  this->burstEmitter[1]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1)));
157  this->burstEmitter[1]->setName("TurbineHover_Burst_emitter_Right");
[6800]158
[7001]159
160  this->burstSystem = new SpriteParticles(1000);
161  this->burstSystem->addEmitter(this->burstEmitter[0]);
162  this->burstSystem->addEmitter(this->burstEmitter[1]);
163  this->burstSystem->setName("SpaceShip_Burst_System");
164  ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png");
165  this->burstSystem->setLifeSpan(1.0, .3);
166  this->burstSystem->setRadius(0.0, 1.5);
167  this->burstSystem->setRadius(0.05, 1.8);
168  this->burstSystem->setRadius(.5, .8);
169  this->burstSystem->setRadius(1.0, 0);
170  this->burstSystem->setColor(0.0, .7,.7,1,.5);
171  this->burstSystem->setColor(0.2, 0,0,0.8,.5);
172  this->burstSystem->setColor(0.5, .5,.5,.8,.3);
173  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
174
175
[6443]176  //add events to the eventlist
[6997]177  registerEvent(KeyMapper::PEV_FORWARD);
178  registerEvent(KeyMapper::PEV_BACKWARD);
[6637]179  registerEvent(KeyMapper::PEV_LEFT);
180  registerEvent(KeyMapper::PEV_RIGHT);
[6998]181  registerEvent(KeyMapper::PEV_UP);
182  registerEvent(KeyMapper::PEV_DOWN);
[6443]183  registerEvent(KeyMapper::PEV_FIRE1);
184  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
185  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
186  registerEvent(EV_MOUSE_MOTION);
187
[7001]188  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
[6443]189
[6803]190  // WEAPON_MANAGER configuration
191  this->getWeaponManager()->setSlotCount(5);
192
193  this->getWeaponManager()->setSlotPosition(0, Vector(-0.28, 1.186, -2.750), &this->wingNodeLeft);
[6443]194  this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
195
[6803]196  this->getWeaponManager()->setSlotPosition(1, Vector(-0.28, 1.186, 2.750), &this->wingNodeRight);
[6443]197  this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
198
[6803]199  this->getWeaponManager()->setSlotPosition(2, Vector(-1.63, .809, -.003));
200  this->getWeaponManager()->setSlotCapability(2, WTYPE_HEAVY);
[6443]201
[6803]202  /// TODO: THESE ARE TOO MUCH
203  this->getWeaponManager()->setSlotPosition(3, Vector(-1.63, .678, -.652));
204  this->getWeaponManager()->setSlotDirection(3, Quaternion(-24/180 * M_PI, Vector(1,0,0)));
[6443]205
[6803]206  this->getWeaponManager()->setSlotPosition(4, Vector(-1.63, .678, .652));
207  this->getWeaponManager()->setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0)));
[6443]208
[6807]209  this->cameraNode.setRelCoor(1,5,0);
210  this->getWeaponManager()->getFixedTarget()->setParent(&this->cameraNode);
211  this->getWeaponManager()->getFixedTarget()->setRelCoor(1000,0,0);
[6443]212}
213
214/**
[7000]215 * loads the Settings of a TurbineHover from an XML-element.
[6443]216 * @param root the XML-element to load the Spaceship's properties from
217 */
[7000]218void TurbineHover::loadParams(const TiXmlElement* root)
[6443]219{
[6512]220  WorldEntity::loadParams(root);
[6443]221}
222
223
[7000]224void TurbineHover::enter()
[6443]225{
226  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true);
227
[7125]228  if (State::getCameraNode != NULL)
229  {
230    State::getCameraNode()->setParentSoft(&this->cameraNode);
231    State::getCameraNode()->setRelCoorSoft(-10, 0,0);
232    State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
233  }
[6443]234}
235
[7000]236void TurbineHover::leave()
[6443]237{
238  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
239  this->detachCamera();
240
241}
242
243
244/**
[7000]245 *  effect that occurs after the TurbineHover is spawned
[6443]246*/
[7000]247void TurbineHover::postSpawn ()
[6443]248{
249  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
250}
251
252/**
[7000]253 *  the action occuring if the turbine_hover left the game
[6443]254*/
[7000]255void TurbineHover::leftWorld ()
[6443]256{}
257
258/**
259 *  this function is called, when two entities collide
260 * @param entity: the world entity with whom it collides
261 *
262 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
263 */
[7000]264void TurbineHover::collidesWith(WorldEntity* entity, const Vector& location)
[7072]265{
266  Playable::collidesWith(entity, location);
267}
[6443]268
269
270
271/**
272 *  the function called for each passing timeSnap
273 * @param time The timespan passed since last update
274*/
[7000]275void TurbineHover::tick (float dt)
[6443]276{
[7105]277//  this->debugNode(1);
[6804]278  Playable::tick(dt);
279
[6443]280  // spaceship controlled movement
[6805]281  this->movement(dt);
[6806]282  this->rotorCycle += this->rotorSpeed * dt;
[7001]283
284  // TRYING TO FIX PNode.
[7003]285  this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
286  this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
[6443]287}
288
289/**
290 *  calculate the velocity
291 * @param time the timeslice since the last frame
292*/
[7000]293void TurbineHover::movement (float dt)
[6443]294{
295  Vector accel(0.0, 0.0, 0.0);
[6879]296  float rotSpeed = .3;
[6443]297
[6814]298  if( this->bForward )
299  {
[6879]300    accel += Vector(this->acceleration, 0, 0);
[6443]301  }
302
[6814]303  if( this->bBackward )
304  {
[6879]305    accel -= Vector(this->acceleration, 0, 0);
[6443]306  }
[6814]307  if( this->bLeft)
308  {
[6879]309    accel -= Vector(0, 0, this->acceleration);
[6443]310  }
[6807]311
[6814]312  if( this->bRight)
313  {
[6879]314    accel += Vector(0, 0, this->acceleration);
[6443]315  }
316
[6814]317  if (this->bAscend )
318  {
[6879]319    accel += Vector(0, this->acceleration, 0);
[6443]320  }
[6814]321  if (this->bDescend )
322  {
[6879]323    accel -= Vector(0, this->acceleration, 0);
[6807]324  }
[6443]325
[6999]326  Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);
[6814]327
[6879]328  // this is the air friction (necessary for a smooth control)
[6999]329  Vector damping = (this->velocity * this->airFriction);
330
331
332  this->velocity += (accelerationDir - damping)* dt;
333
334  this->shiftCoor (this->velocity * dt);
[6879]335  this->rotation = 0.0f;
336
[6880]337  this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
[6805]338
[7001]339  this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
340  this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5);
[6805]341
[7001]342  this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
343  this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5);
[6443]344}
345
346
[7000]347void TurbineHover::draw() const
[6443]348{
[6801]349  Vector tmpRot;
[6443]350  WorldEntity::draw();
[6799]351
[6801]352  glPushMatrix();
353  /// LEFT SIDE
354  glTranslatef (this->wingNodeLeft.getAbsCoor ().x,
355                this->wingNodeLeft.getAbsCoor ().y,
356                this->wingNodeLeft.getAbsCoor ().z);
357  tmpRot = this->wingNodeLeft.getAbsDir().getSpacialAxis();
358  glRotatef (this->wingNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
359  this->getModel(3)->draw();
360  glPopMatrix ();
[6443]361
[6801]362  glPushMatrix();
363  glTranslatef (this->rotorNodeLeft.getAbsCoor ().x,
364                this->rotorNodeLeft.getAbsCoor ().y,
365                this->rotorNodeLeft.getAbsCoor ().z);
366  tmpRot = this->rotorNodeLeft.getAbsDir().getSpacialAxis();
367  glRotatef (this->rotorNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
368  this->getModel(4)->draw();
[6806]369  glRotatef(this->rotorCycle, 0,1,0);
370  this->getModel(5)->draw();
[6801]371  glPopMatrix ();
[6724]372
[6801]373  /// RIGHT SIDE
374  glPushMatrix();
375  glTranslatef (this->wingNodeRight.getAbsCoor ().x,
376                this->wingNodeRight.getAbsCoor ().y,
377                this->wingNodeRight.getAbsCoor ().z);
378  tmpRot = this->wingNodeRight.getAbsDir().getSpacialAxis();
379  glRotatef (this->wingNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
380  glScalef(1,1,-1);
381  this->getModel(3)->draw();
382  glPopMatrix ();
[6724]383
[6801]384  glPushMatrix();
385  glTranslatef (this->rotorNodeRight.getAbsCoor ().x,
386                this->rotorNodeRight.getAbsCoor ().y,
387                this->rotorNodeRight.getAbsCoor ().z);
388  tmpRot = this->rotorNodeRight.getAbsDir().getSpacialAxis();
389  glRotatef (this->rotorNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
390  glScalef(1,1,-1);
391  this->getModel(4)->draw();
[6806]392  glRotatef(this->rotorCycle, 0,1,0);
393  this->getModel(5)->draw();
[6801]394  glPopMatrix ();
[6443]395}
396
397/**
398 * @todo switch statement ??
399 */
[7000]400void TurbineHover::process(const Event &event)
[6443]401{
[6804]402  Playable::process(event);
[6443]403
[6637]404  if( event.type == KeyMapper::PEV_LEFT)
[6805]405    this->bLeft = event.bPressed;
[6637]406  else if( event.type == KeyMapper::PEV_RIGHT)
[6805]407    this->bRight = event.bPressed;
[6998]408  else if( event.type == KeyMapper::PEV_UP)
[6443]409    this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
[6998]410  else if( event.type == KeyMapper::PEV_DOWN)
[6443]411    this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);
[6997]412  else if( event.type == KeyMapper::PEV_FORWARD)
[6805]413    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
[6997]414  else if( event.type == KeyMapper::PEV_BACKWARD)
[6805]415    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
[6443]416  else if( event.type == EV_MOUSE_MOTION)
417  {
[6807]418    float xMouse, yMouse;
419    xMouse = event.xRel*mouseSensitivity;
420    yMouse = event.yRel*mouseSensitivity;
[6443]421
[6805]422    // rotate the Player around the y-axis
[6807]423    this->direction *= Quaternion(-M_PI/4.0*xMouse, Vector(0,1,0));
424    this->rotation += xMouse;
[6799]425
[6807]426    this->cameraLook += yMouse;
[6805]427    // rotate the Camera around the z-axis
[6807]428    if (cameraLook > M_PI_4)
429      cameraLook = M_PI_4;
[6880]430    else if (cameraLook < -M_PI_4)
431      cameraLook = -M_PI_4;
432    //this->cameraNode.setRelDirSoft(this->direction,10);
[6805]433  }
[6443]434}
Note: See TracBrowser for help on using the repository browser.