Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/space_ships/space_ship.cc @ 10303

Last change on this file since 10303 was 10303, checked in by muellmic, 17 years ago

traveldistance calculations now work properly. note, that camera-distance and camera-fovy can be set in the level- xml- file and the traveldistance (how far can the player move the ship so thatit's still visible) will be calculated depending on the camera perspective.

File size: 34.3 KB
RevLine 
[6868]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 Knecht
13   co-programmer: Silvan Nellen
14
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19#include "executor/executor.h"
20#include "space_ship.h"
21
[7193]22#include "util/loading/resource_manager.h"
[6868]23
24#include "weapons/test_gun.h"
[9970]25#include "weapons/light_blaster.h"
26#include "weapons/medium_blaster.h"
27#include "weapons/heavy_blaster.h"
[10023]28#include "weapons/swarm_launcher.h"
[10170]29#include "weapons/spike_launcher.h"
[10196]30#include "weapons/spike_thrower.h"
[10298]31#include "weapons/acid_launcher.h"
[9970]32#include "weapons/boomerang_gun.h"
[6868]33#include "weapons/turret.h"
34#include "weapons/cannon.h"
35
[10120]36#include "elements/glgui_energywidgetvertical.h"
[10230]37#include "glgui_bar.h"
[10120]38
[9869]39#include "particles/dot_emitter.h"
[10073]40#include "particles/emitter_node.h"
[9869]41#include "particles/sprite_particles.h"
[10081]42#include "effects/trail.h"
[6868]43
[10154]44#include "effects/wobblegrid.h"
45
[7193]46#include "util/loading/factory.h"
[6868]47#include "key_mapper.h"
48
49#include "network_game_manager.h"
[8708]50#include "shared_network_data.h"
[6868]51
52#include "power_ups/weapon_power_up.h"
53#include "power_ups/param_power_up.h"
54
55#include "graphics_engine.h"
56
57#include "plane.h"
58
59#include "state.h"
60#include "player.h"
[10237]61#include "camera.h"
[6868]62
[10113]63
[7193]64#include "util/loading/load_param.h"
[10020]65#include "time.h"
[6868]66
[10096]67#include "track/track.h"
[10291]68#include "math.h"
[7056]69
[10096]70
[6868]71// #include "lib/gui/gl_gui/glgui_bar.h"
72// #include "lib/gui/gl_gui/glgui_pushbutton.h"
73
74
[9869]75#include "class_id_DEPRECATED.h"
76ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP);
77CREATE_FACTORY(SpaceShip);
[9406]78
[9061]79#include "script_class.h"
[9869]80CREATE_SCRIPTABLE_CLASS(SpaceShip,
81                        addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer))
82                        ->addMethod("fire", Executor1<Playable, lua_State*, bool>(&Playable::fire))
83                        ->addMethod("loadModel", Executor2<WorldEntity, lua_State*,const std::string& ,float>(&WorldEntity::loadModel2))
84                        ->addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName))
85                        ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide))
86                        ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide))
87                        //Coordinates
88                        ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
89                        ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
90                        ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
91                        ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
[10017]92                        //->addMethod("setCameraSpeed", Executor1<SpaceShip, lua_State*, float>(&SpaceShip::setCameraSpeed))
[9061]93                       );
[6868]94
95/**
96 *  destructs the spaceship, deletes alocated memory
97 */
98SpaceShip::~SpaceShip ()
99{
[6986]100  this->setPlayer(NULL);
[6868]101}
102
103/**
104 * loads a Spaceships information from a specified file.
105 * @param fileName the name of the File to load the spaceship from (absolute path)
106 */
[7221]107SpaceShip::SpaceShip(const std::string& fileName)
[10019]108    : secWeaponMan(this) //,
109    //supportedPlaymodes(Playable::Vertical) ,
110    //playmode(Playable::Vertical)
[6868]111{
112  this->init();
113  TiXmlDocument doc(fileName);
114
115  if(!doc.LoadFile())
116  {
[7221]117    PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str());
[6868]118    return;
119  }
120
121  this->loadParams(doc.RootElement());
122}
123
124/**
125 *  creates a new Spaceship from Xml Data
126 * @param root the xml element containing spaceship data
127
128   @todo add more parameters to load
129*/
130SpaceShip::SpaceShip(const TiXmlElement* root)
[10019]131    : secWeaponMan(this) //,
132    //supportedPlaymodes(Playable::Vertical) ,
133    //playmode(Playable::Vertical)
[6868]134{
135  this->init();
[10081]136  //this->setParentMode(PNODE_REPARENT_DELETE_CHILDREN);
[6868]137  if (root != NULL)
138    this->loadParams(root);
139
140}
141
142
143/**
144 * initializes a Spaceship
145 */
146void SpaceShip::init()
147{
[9998]148
[10022]149  srand(time(0));   //initialize Random Nomber Generator
150
[9869]151  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
152  this->registerObject(this, SpaceShip::_objectList);
[6868]153  PRINTF(4)("SPACESHIP INIT\n");
[10121]154  this->weaponMan.setParentEntity( this);
[6868]155  //weapons:
[10098]156 
[9996]157  Weapon* wpRight1 = new LightBlaster ();
[10073]158  wpRight1->setName( "LightBlaster");
[9996]159  Weapon* wpLeft1 = new LightBlaster ();
[10073]160  wpLeft1->setName( "LightBlaster");
[6868]161
[9996]162  Weapon* wpRight2 = new MediumBlaster ();
[10073]163  wpRight2->setName( "MediumBlaster");
[9996]164  Weapon* wpLeft2 = new MediumBlaster ();
[10073]165  wpLeft2->setName( "MediumBlaster");
[10252]166
[10152]167  Weapon* wpRight3 = new HeavyBlaster (1);
[10073]168  wpRight3->setName( "HeavyBlaster");
[10152]169  Weapon* wpLeft3 = new HeavyBlaster (0);
[10073]170  wpLeft3->setName( "HeavyBlaster");
[9996]171
[10173]172  Weapon* cannon = new SwarmLauncher();
173  cannon->setName( "SwarmLauncher");
[6868]174
[10252]175  Weapon* spike = new SpikeThrower();
176  spike->setName( "SpikeThrower" );
[9961]177
[10261]178//  Weapon* spike2 = new SpikeLauncher();
179//  spike2->setName( "SpikeLauncher" );
[10196]180
[10298]181  Weapon* acid0 = new AcidLauncher();
182  acid0->setName( "AcidSplasher" );
183
184  Weapon* acid1 = new AcidLauncher();
185  acid1->setName( "AcidSplasher" );
186
[10098]187  this->weaponMan.addWeapon( wpLeft1, 0, 0);
188  this->weaponMan.addWeapon( wpRight1, 0, 1);
[9998]189
[10121]190  this->weaponMan.addWeapon( wpLeft2, 1, 2);
191  this->weaponMan.addWeapon( wpRight2, 1, 3);
[9961]192
[10121]193  this->weaponMan.addWeapon( wpLeft3, 2, 4);
194  this->weaponMan.addWeapon( wpRight3, 2, 5);
[10113]195
[10152]196  this->weaponMan.addWeapon( wpLeft1, 3, 0);
197  this->weaponMan.addWeapon( wpRight1, 3, 1);
198
199  this->weaponMan.addWeapon( wpLeft2, 3, 2);
200  this->weaponMan.addWeapon( wpRight2, 3, 3);
201
202  this->weaponMan.addWeapon( wpLeft3, 3, 4);
203  this->weaponMan.addWeapon( wpRight3, 3, 5);
204
[10298]205  this->weaponMan.addWeapon( acid0, 0, 6);
206  this->weaponMan.addWeapon( acid1, 0, 7);
[9998]207
[10298]208  this->secWeaponMan.addWeapon( cannon, 0, 2);
209  this->secWeaponMan.addWeapon( spike, 1, 3);
210//   this->secWeaponMan.addWeapon( acid0, 2, 2);
211//   this->secWeaponMan.addWeapon( acid1, 2, 3);
[10252]212
[10298]213
214  this->weaponMan.changeWeaponConfig(0);
[10271]215  this->secWeaponMan.changeWeaponConfig(1);
[10113]216
[10188]217  curWeaponPrimary    = 3;
[10286]218  curWeaponSecondary  = 0;
[9965]219
220  Playable::weaponConfigChanged();
221
[9970]222  reactorOutput     = 10;
[9965]223
[9970]224  weaponEnergyRegen = 10;       // 10 einheiten pro Sekunde
225  engineSpeedBase   = 5;
226  shieldRegen       = 2;
227
228  shieldEnergyShare = 0.3;
229  weaponEnergyShare = 0.3;
230  engineEnergyShare = 0.4;
231
232  shieldCur         = 20;
233  shieldMax         = 100;
[10252]234  shieldTH          = .2 * shieldMax;   // shield power must be 20% before shield kicks in again
[9970]235
[10119]236  this->setHealth( 20);
237  this->setHealthMax( 100);
238
[10024]239  electronicCur = 50;
[10022]240  electronicMax = 50;
[10020]241  electronicRegen   = 3;
242  electronicTH      = .7 * electronicMax; // 30% of eDamage can be handled by the ship
243
[6868]244
[9970]245  this->loadModel("models/ships/mantawing.obj");
[10017]246  //this->setVisibiliy(false);
[6868]247
[10017]248  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[6868]249
[9970]250  this->setHealthMax(shieldMax);
251  this->setHealth(shieldCur);
[6868]252
[10017]253  this->travelNode = new PNode();
254
255  // camera - issue
256  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
257  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
258
[10120]259  // widget handling
[10139]260  /*
[10120]261  this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
262  this->electronicWidget->setDisplayedName(std::string(this->getClassName()) + " Electronics:");
263  this->electronicWidget->setSize2D(30,400);
264  this->electronicWidget->setAbsCoor2D(150,200);
265  this->electronicWidget->shiftDir2D(270);
266  this->updateElectronicWidget();
267  this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
268  this->shieldWidget->setDisplayedName(std::string(this->getClassName()) + " Shield:");
269  this->shieldWidget->setSize2D(30,400);
270  this->shieldWidget->setAbsCoor2D(200,200);
271  this->shieldWidget->shiftDir2D(270);
272  this->updateShieldWidget();
273  if (this->hasPlayer())
274  {
275    State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
276    State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
277  }
[10139]278  */
279  this->electronicWidget = NULL;
280  this->shieldWidget = NULL;
[6868]281
282  //add events to the eventlist
[6997]283  registerEvent(KeyMapper::PEV_FORWARD);
284  registerEvent(KeyMapper::PEV_BACKWARD);
[6868]285  registerEvent(KeyMapper::PEV_LEFT);
286  registerEvent(KeyMapper::PEV_RIGHT);
287  //registerEvent(SDLK_q);
288  //registerEvent(SDLK_e);
289  registerEvent(KeyMapper::PEV_FIRE1);
[9958]290  registerEvent(KeyMapper::PEV_FIRE2);                  // Added for secondary weapon support
[6868]291  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
292  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
293  //registerEvent(SDLK_PAGEUP);
294  //registerEvent(SDLK_PAGEDOWN);
295  registerEvent(EV_MOUSE_MOTION);
296
[10073]297  this->weaponMan.setParentEntity( this);
298  this->secWeaponMan.setParentEntity( this);
299
[10298]300  this->weaponMan.setSlotCount(8);
[6868]301
[10152]302  this->weaponMan.setSlotPosition(0, Vector(0.0, 0, -3.0));
[9965]303  this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]304
[10152]305  this->weaponMan.setSlotPosition(1, Vector(0.0, 0, 3.0));
[9965]306  this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]307
[10286]308  this->weaponMan.setSlotPosition(2, Vector(1.0, 0, -1.5));
[9965]309  this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
[6868]310
[10286]311  this->weaponMan.setSlotPosition(3, Vector(1.0, 0, 1.5));
[9965]312  this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
[6868]313
[10133]314  this->weaponMan.setSlotPosition(4, Vector(1.5, 0, .5));
[9965]315  this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
[6868]316
[10133]317  this->weaponMan.setSlotPosition(5, Vector(1.5, 0, -.5));
[9965]318  this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
[9961]319
[10298]320  this->weaponMan.setSlotPosition(6, Vector(0.5, 0, 2.5));
321  this->weaponMan.setSlotDirection(6, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
322
323  this->weaponMan.setSlotPosition(7, Vector(0.5, 0, -2.5));
324  this->weaponMan.setSlotDirection(7, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
325
[9961]326  this->secWeaponMan.setSlotCount(6);
327
[10073]328  this->secWeaponMan.setSlotPosition(0, Vector(1.5, 0, 0));
[9961]329  this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
330
[10073]331  this->secWeaponMan.setSlotPosition(1, Vector(2.6, 0, 3.0));
[9961]332  this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
333
[10073]334  this->secWeaponMan.setSlotPosition(2, Vector(1.5, 0, -.5));
[9961]335  this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
336
[10073]337  this->secWeaponMan.setSlotPosition(3, Vector(1.5, 0, .5));
[9961]338  this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
339
[10073]340  this->secWeaponMan.setSlotPosition(4, Vector(1.5, 0, .5));
[9961]341  this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
342
[10073]343  this->secWeaponMan.setSlotPosition(5, Vector(1.5, 0, -.5));
[9961]344  this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
[9965]345
[6868]346
[9965]347  this->weaponMan.getFixedTarget()->setParent(this);
348  this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[10004]349
[9998]350 
[9961]351  this->secWeaponMan.getFixedTarget()->setParent(this);
352  this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[10004]353  this->secWeaponMan.setRotationSpeed(0);
[6868]354
[9965]355  dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false);
[9961]356
[6868]357
[10017]358  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
359  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
360  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
361  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
362  registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) );
363  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
[10023]364  registerVar( new SynchronizeableBool( &bFire, &bFire, "bSecFire", PERMISSION_OWNER));
[10017]365  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
366
367  //this->airFriction = 0.5f;
[10291]368  //this->travelDistancePlus = Vector2D(38.0, 43.0);
369  //this->travelDistanceMinus = Vector2D(-38.0, -43.0);
370  this->travelDistancePlus = Vector2D(0,0);
371  this->travelDistancePlus = Vector2D(0,0);
372  this->isTravelDistanceInit = false;
373  this->actionWidthPercentage = 0.7;
374
[10017]375  this->cameraSpeed = 40;
[10019]376  this->cameraLook = 0.0f;
377  //this->airFriction = 0.0f;
[10017]378
[10020]379  srand(time(0));  //initaialize RNG
380
[10017]381  this->travelNode->debugDraw();
[10032]382
383  this->setSupportedPlaymodes(Playable::Horizontal | Playable::Vertical);
[10081]384
[10261]385  /// FIXME
386  this->trail = new Trail( 5, 10, .2, this);
[10081]387  this->trail->setTexture( "maps/engine.png");
388
[10261]389  this->trailL = new Trail( 5, 10, .2, this);
[10081]390  this->trailL->setTexture( "maps/engine.png");
391
[10261]392  this->trailR = new Trail( 5, 10, .2, this);
[10081]393  this->trailR->setTexture( "maps/engine.png");
[10098]394
[10113]395
[10098]396  this->toList(OM_GROUP_00);
[10154]397
[10155]398  //FIXME Just testaddition to show the wobblegrid
[10261]399/*
[10156]400  this->test  = new Wobblegrid(5);
[10159]401  test->setTexture("maps/blub.png");
[10154]402 
403  test->setAbsCoor( this->getAbsCoor() + Vector(0, 2, 0));
404  test->setParent( this);
[10261]405*/
[10154]406 
[6868]407}
408
409
410/**
411 * loads the Settings of a SpaceShip from an XML-element.
412 * @param root the XML-element to load the Spaceship's properties from
413 */
414void SpaceShip::loadParams(const TiXmlElement* root)
415{
416  Playable::loadParams(root);
[10032]417
418  LoadParam(root, "playmode", this, SpaceShip, setPlaymodeXML);
[10270]419  LoadParam(root, "cameraDistance", this, SpaceShip, setCameraDistance);
420  LoadParam(root, "cameraFovy", this, SpaceShip, setCameraFovy);
[10291]421  LoadParam(root, "actionWidthPercentage", this, SpaceShip, setActionWidthPercentage);
[10281]422
423  State::getCamera()->setViewMode(Camera::ViewTop);
[6868]424}
425
[10032]426
[10017]427void SpaceShip::setPlayDirection(const Quaternion& rot, float speed)
[7056]428{
[10032]429  //this->direction = Quaternion (rot.getHeading(), Vector(0,1,0));
[7056]430}
[6868]431
[7085]432void SpaceShip::reset()
433{
[10017]434  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[7056]435
[10017]436  //xMouse = yMouse = 0;
[7085]437
438  this->setHealth(80);
439  this->velocity = Vector(0.0, 0.0, 0.0);
440}
441
442
[6868]443void SpaceShip::enter()
444{
[10004]445  this->secWeaponMan.showCrosshair();
[10095]446  this->toList( OM_GROUP_01 );
[10270]447  State::getPlayer()->hud().setRadarCenterNode(this->travelNode);
[10233]448  State::getPlayer()->hud().setOverlayActive(true);
[10194]449  //dynamic_cast <OrxGui::GLGuiEnergyWidgetVertical*> (State::getPlayer()->hud().getArmorWidget())->setDisplayedName("Armor");
[10004]450  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true);
[10019]451  //this->attachCamera();
[10032]452 // this->setPlaymode(Playable::Horizontal);
[6868]453}
454
455void SpaceShip::leave()
456{
[10004]457  this->secWeaponMan.hideCrosshair();
[10095]458  this->toList( OM_GROUP_00);
[10233]459  State::getPlayer()->hud().setOverlayActive(false);
[10237]460  State::getCamera()->setEventHandling(true);
[10270]461  State::getPlayer()->hud().setRadarCenterNode(NULL);
[10004]462  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false);
[10019]463  //this->detachCamera();
[6868]464}
465
466
467/**
468 *  effect that occurs after the SpaceShip is spawned
469*/
470void SpaceShip::postSpawn ()
471{
[10261]472  if(this->hasPlayer())
473    Playable::postSpawn();
474
[6868]475  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
476}
477
478/**
479 *  the action occuring if the spaceship left the game
480*/
481void SpaceShip::leftWorld ()
[10073]482{
483
[10064]484}
[6868]485
486WorldEntity* ref = NULL;
487
488/**
489 *  draws the spaceship after transforming it.
490*/
491void SpaceShip::draw () const
492{
493  WorldEntity::draw();
494
[10081]495  glMatrixMode(GL_MODELVIEW);
496  glPushMatrix();
497
498  float matrix[4][4];
499  glTranslatef (this->getAbsCoor ().x-1, this->getAbsCoor ().y-.2, this->getAbsCoor ().z);
500  this->getAbsDir().matrix (matrix);
501  glMultMatrixf((float*)matrix);
502  //glScalef(2.0, 2.0, 2.0);  // no double rescale
[10282]503        // FIXME
[10081]504  this->trail->draw();
505 
506  glTranslatef(0,0,-.5);
507  this->trailL->draw();
508
509  glTranslatef(0,0,1);
510  this->trailR->draw();
[10282]511
[10081]512  glPopMatrix();
[6868]513  //this->debug(0);
514}
515
516/**
517 *  the function called for each passing timeSnap
518 * @param time The timespan passed since last update
519*/
520void SpaceShip::tick (float time)
521{
[10261]522  // Playable::tick(time);
523
524 // this->test->tick(time);
525
[9961]526  // Own Tick Setup, as a different fire routine is used on the weapon manager
[9965]527  this->weaponMan.tick(time);
[9961]528  this->secWeaponMan.tick(time);
529
[10020]530  if( this->systemFailure() )
531    bFire = bSecFire = false;
532
[10037]533  // fire reqeust/release for primary weapons
[9965]534  if( this->bFire)
535    this->weaponMan.fire();
[10036]536  else
537    this->weaponMan.releaseFire();
538
[10037]539  // fire reqeust/release for secondary weapons
[9961]540  if( this->bSecFire)
541    this->secWeaponMan.fire();
[10036]542  else
543    this->secWeaponMan.releaseFire();
[10096]544   
545  // Tracktick
546  if(this->entityTrack)
547    this->entityTrack->tick(time);
[9961]548
[9970]549
550  // Shield Regeneration and other regular calculations on the ship
551  this->regen(time);
552
553  // Weapon Regeneration and other regular calculations on the ship
[9965]554  this->weaponRegen(time);
555
[9970]556  // current engine speed output
557  this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare;
558
[10043]559  // calculation of maxSpeed and acceleration:
560  this->travelSpeed = this->engineSpeedCur * 5;
561  this->acceleration = this->travelSpeed * 2;
[9970]562
[10017]563  this->movement(time);
564
565   // TRYING TO FIX PNode.
566  this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
567  this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
568
[10095]569 
570  this->velocity  = (this->getAbsCoor() - this->oldPos) / time;
571  this->oldPos    = this->getAbsCoor();
572
[10261]573//FIXME
[10081]574  this->trail->tick(time);
575  this->trailL->tick(time);
576  this->trailR->tick(time);
[10095]577
[10291]578  if (!this->isTravelDistanceInit)
579  {
580    this->updateTravelDistance();
581    this->isTravelDistanceInit = true;
582  }
583
[6868]584  //orient the spaceship in direction of the mouse
[10017]585  /*
[9869]586  rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
587  if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
[6868]588    this->setAbsDir( rotQuat);
[9869]589  //this->setAbsDirSoft(mouseDir,5);
[10017]590  */
591  /*
[6868]592  this->shiftCoor(move);
[10017]593  */
[6868]594
[9869]595  //   PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber());
[6868]596
597}
598
599/**
600 * @todo switch statement ??
601 */
602void SpaceShip::process(const Event &event)
603{
[9961]604  //Playable::process(event);
[10113]605 
[6868]606  if( event.type == KeyMapper::PEV_LEFT)
[10017]607    this->bLeft = event.bPressed;
[6868]608  else if( event.type == KeyMapper::PEV_RIGHT)
[10291]609  {
[10017]610    this->bRight = event.bPressed;
[10291]611    printf("ShipCoorX: %f \n", this->getRelCoor().x);
612  }
[6997]613  else if( event.type == KeyMapper::PEV_FORWARD)
[10291]614  {
[10017]615    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
[10291]616   
617  }
[6997]618  else if( event.type == KeyMapper::PEV_BACKWARD)
[10017]619    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
[9961]620  else if( event.type == KeyMapper::PEV_FIRE2)
621    this->bSecFire = event.bPressed;
[9958]622  else if( event.type == KeyMapper::PEV_FIRE1)
[9965]623    this->bFire = event.bPressed;
[10113]624  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
625  {
626    this->nextWeaponConfig();
627  }
628  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
629    this->previousWeaponConfig();
[10017]630
[10237]631  if (!(State::getCamera()->getEventHandling()))
632  {
633    if( event.type == KeyMapper::PEV_VIEW0)
634    {
635      State::getCamera()->setViewMode(Camera::ViewNormal);
636      State::getCameraTargetNode()->setParent(this);
637      State::getCamera()->setParent(this);
638    }
639    else if( event.type == KeyMapper::PEV_VIEW1)
640    {
641      State::getCamera()->setViewMode(Camera::ViewBehind);
642      State::getCameraTargetNode()->setParent(this);
643      State::getCamera()->setParent(this);
644    }
645    else if( event.type == KeyMapper::PEV_VIEW2)
646    {
647      State::getCamera()->setViewMode(Camera::ViewFront);
648      State::getCameraTargetNode()->setParent(this);
649      State::getCamera()->setParent(this);
650    }
651    else if( event.type == KeyMapper::PEV_VIEW3)
652    {
653      State::getCamera()->setViewMode(Camera::ViewLeft);
654      State::getCameraTargetNode()->setParent(this);
655      State::getCamera()->setParent(this);
656    }
657    else if( event.type == KeyMapper::PEV_VIEW4)
658    {
659      State::getCamera()->setViewMode(Camera::ViewRight);
660      State::getCameraTargetNode()->setParent(this);
661      State::getCamera()->setParent(this);
662    }
663    else if( event.type == KeyMapper::PEV_VIEW5)
664    {
665      State::getCamera()->setViewMode(Camera::ViewTop);
666      State::getCameraTargetNode()->setParent(this->travelNode);
667      State::getCamera()->setParent(this->travelNode);
668    }
669  }
[10017]670
[10237]671
[10017]672  /*
[6868]673  else if( event.type == EV_MOUSE_MOTION)
674  {
[9961]675
[6868]676    this->xMouse += event.xRel;
677    this->yMouse += event.yRel;
678  }
[10017]679  */
[6868]680}
681
[9235]682void SpaceShip::destroy( WorldEntity* killer )
[9008]683{
[10261]684  if(this->hasPlayer())
685    Playable::destroy( killer);
686
[10107]687  PRINTF(5)("spaceship destroy\n");
[10261]688
[10073]689  EmitterNode* node  = NULL;
690  DotEmitter* emitter = NULL;
691  SpriteParticles*  explosionParticles  = NULL;
[10064]692
[10107]693  explosionParticles = new SpriteParticles(200);
694  explosionParticles->setName("SpaceShipExplosionParticles");
695  explosionParticles->setLifeSpan(.2, .3);
[10073]696  explosionParticles->setRadius(0.0, 10.0);
697  explosionParticles->setRadius(.5, 6.0);
698  explosionParticles->setRadius(1.0, 3.0);
[10098]699  explosionParticles->setColor(0.0, 1,1,1,.9);
700  explosionParticles->setColor(0.1,  1,1,0,.9);
701  explosionParticles->setColor(0.5, .8,.4,0,.5);
[10107]702  explosionParticles->setColor(1.0, .2,.2,.2,.5);
[10064]703
[10073]704 
[10107]705  emitter = new DotEmitter( 2000, 70, 360);
706  //emitter->setSpread( 0, M_2_PI);
707  emitter->setEmissionRate( 200.0);
[10098]708  //emitter->setEmissionVelocity( 200.0);
[10107]709  //emitter->setSystem( explosionParticles);
710  //emitter->setAbsCoor( this->getAbsCoor());
[10064]711
[10107]712  node  = new EmitterNode( .1f);
[10073]713  node->setupParticle( emitter, explosionParticles);
[10107]714  node->setAbsDir( this->getAbsDir());
715  node->setVelocity( this->getVelocity() * .9f);
[10073]716  node->setAbsCoor( this->getAbsCoor());
[10107]717  if( !node->start())
718    PRINTF(0)("Explosion node not correctly started!");
[10095]719/*
[10081]720  PNode* node          = new PNode();
721  node->setAbsCoor(this->getAbsCoor());
722  Explosion* explosion = new Explosion();
723  explosion->explode( node, Vector(5,5,5));
[10095]724*/
[10261]725/*
[10107]726  if( this->hasPlayer())
727  {
728        this->setAbsCoor(Vector(-10000,10000,10000));
729        this->hide();
730  }
731  else
[10261]732  {*/
[10113]733    this->setAbsCoor( this->getAbsCoor() + Vector(100,0,0) + Vector(1,0,0) * VECTOR_RAND(150).dot(Vector(1,0,0)));
[10261]734  //}
[10107]735
[9008]736}
[6868]737
[9008]738void SpaceShip::respawn( )
739{
[10261]740  Playable::respawn();
[9008]741}
[6868]742
743
[9957]744void SpaceShip::damage(float pDamage, float eDamage){
[10117]745  PRINTF(5)("ship hit for (%f,%f) \n",pDamage,eDamage);
[10081]746
[10064]747  if( this->shieldActive) {
[9950]748    if( this->shieldCur > pDamage) {
749      this->shieldCur = this->shieldCur - pDamage;
750    }
751    else { // shield <= pDamage
[9987]752      this->shieldCur -=pDamage;
753      this->shieldActive = false; //shield collapses
[10081]754      pDamage += this->shieldCur;
[9950]755      if( !this->shieldActive) {
[9957]756        this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate
[9953]757        this->electronicCur -= eDamage;
[9950]758      }
759    }
760  }
761  else {
762    this->armorCur = this->armorCur - pDamage;
763    this->electronicCur = this->electronicCur - eDamage;
764  }
765  if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ }
[10064]766    this->destroy(this);
[10119]767
[10120]768  updateElectronicWidget();
769  updateShieldWidget();
770
[10119]771  this->setHealth( this->armorCur);
[9950]772}
773
[9987]774
[9957]775void SpaceShip::regen(float time){
776  float tmp;
[9963]777  if (this->armorCur != this->armorMax || this->armorRegen != 0){
778    tmp = this->armorCur + this->armorRegen * time;
779    if ( tmp > electronicMax)
780      this->armorCur = this->armorMax;
781    else
782      this->armorCur = tmp;
783  }
784  if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){
[9970]785    tmp =  this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time;
[9957]786    if( tmp > shieldMax)
[9953]787      this->shieldCur = this->shieldMax;
788    else
[9957]789      this->shieldCur = tmp;
790    this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH);
[10120]791
792    updateShieldWidget();
[9953]793  }
[9970]794
795  this->setHealth( this->shieldCur);      // FIXME currently just to test share system
796
[9963]797  if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){
[9957]798    tmp = this->electronicCur + this->electronicRegen * time;
799    if ( tmp > electronicMax)
[9953]800      this->electronicCur = this->electronicMax;
801    else
[9957]802      this->electronicCur = tmp;
[10120]803
804    updateElectronicWidget();
[9953]805  }
[10120]806
[9950]807}
[9965]808
[9987]809
[9965]810/**
811 * Weapon regeneration
812 * does not use any reactor capacity, as it wouldn't work in a consistent way.
813 */
814void SpaceShip::weaponRegen(float time)
815{
816  float energy  = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time;
817  Weapon* weapon;
[9987]818  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++)
[9965]819  {
820    weapon = this->weaponMan.getWeapon(i);
821    if( weapon != NULL && weapon->isActive())
822    {
823      weapon->increaseEnergy( energy);
824    }
825
826  }
827  // weaponMan.increaseAmmunition( weapon, energy);
828}
[9975]829
[9987]830
[9975]831void SpaceShip::enterPlaymode(Playable::Playmode playmode)
832{
[10017]833  switch(playmode)
834  {
835    case Playable::Full3D:
836      /*
837      if (State::getCameraNode != NULL)
838      {
839        Vector absCoor = this->getAbsCoor();
840        this->setParent(PNode::getNullParent());
841        this->setAbsCoor(absCoor);
842        State::getCameraNode()->setParentSoft(&this->cameraNode);
843        State::getCameraNode()->setRelCoorSoft(-10, 0,0);
844        State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
845        State::getCameraTargetNode()->setRelCoorSoft(100, 0,0);
846
847      }
848      */
849      //break;
850
[10032]851      break;
852    case Playable::Horizontal:
[10017]853      if (State::getCameraNode != NULL)
854      {
855        this->debugNode(1);
856        this->travelNode->debugNode(1);
857
858        this->travelNode->setAbsCoor(this->getAbsCoor());
859        this->travelNode->updateNode(0.01f);
[10291]860        this->isTravelDistanceInit = false;
[10297]861       
862        if(this->entityTrack)
863           this->travelNode->setParent(this->entityTrack->getTrackNode());
[10289]864
[10098]865        this->setParent(this->travelNode);
[10017]866        this->setRelCoor(0,0,0);
867
[10098]868        State::getCameraNode()->setParentSoft(this->travelNode);
[10289]869        //State::getCameraNode()->setParentSoft(this);
[10237]870        //State::getCameraNode()->setRelCoorSoft(-0.01, 40, 0);
[10098]871        State::getCameraTargetNode()->setParentSoft(this->travelNode);
[10289]872        //State::getCameraTargetNode()->setParentSoft(this);
[10237]873        //State::getCameraTargetNode()->setRelCoorSoft(0,0,0);
874        this->setCameraMode(Camera::ViewTop);
875        State::getCamera()->setEventHandling(false);
876        registerEvent(KeyMapper::PEV_VIEW0);
877        registerEvent(KeyMapper::PEV_VIEW1);
878        registerEvent(KeyMapper::PEV_VIEW2);
879        registerEvent(KeyMapper::PEV_VIEW3);
880        registerEvent(KeyMapper::PEV_VIEW4);
881        registerEvent(KeyMapper::PEV_VIEW5);
[10017]882
[10237]883        State::getCamera()->setParentMode(PNODE_MOVEMENT);
884
[10291]885        //this->updateTravelDistance();
886
[10017]887        this->debugNode(1);
888        this->travelNode->debugNode(1);
889      }
890      break;
891
892    default:
893      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
894  }
[9975]895}
896
[10017]897/**
898 * @brief calculate the velocity
899 * @param time the timeslice since the last frame
900*/
[9987]901
[9975]902void SpaceShip::movement (float dt)
903{
[10019]904  //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so
905  //the ship doesn't slide too much.
906  float airCoeff = 2.5;
907  float pi = 3.14;
[10017]908
[10032]909  switch(this->getPlaymode())
[10017]910  {
[10032]911    case Playable::Horizontal:
[10017]912    {
[10032]913      // these routines will change the travel movement into zero in a short amout of time, if the player
914      // doesn't press any buttons.
[10098]915      if (this->travelVelocity.x >= 0)
[10017]916      {
[10098]917        if (this->travelVelocity.x > airCoeff*this->acceleration * dt)
918          this->travelVelocity.x -= airCoeff* this->acceleration * dt;
[10032]919        else
[10098]920          this->travelVelocity.x = 0;
[10017]921      }
922      else
923      {
[10098]924        if (this->travelVelocity.x < -airCoeff*this->acceleration * dt)
925          this->travelVelocity.x += airCoeff* this->acceleration * dt;
[10032]926        else
[10098]927          this->travelVelocity.x = 0;
[10017]928      }
[10098]929      if (this->travelVelocity.z >= 0)
[10017]930      {
[10098]931        if (this->travelVelocity.z > airCoeff*this->acceleration * dt)
932          this->travelVelocity.z -= airCoeff* this->acceleration * dt;
[10032]933        else
[10098]934          this->travelVelocity.z = 0;
[10017]935      }
936      else
937      {
[10098]938        if (this->travelVelocity.z < -airCoeff*this->acceleration * dt)
939          this->travelVelocity.z += airCoeff* this->acceleration * dt;
[10032]940        else
[10098]941          this->travelVelocity.z = 0;
[10017]942      }
[10032]943   
944      // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons
945      // and its continuing to slide a bit.
946      Vector oldCoor = this->getRelCoor();
947      if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z);
948      if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z);
949      if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y);
950      if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y);
951   
952      if( this->systemFailure() )
953        bForward = bBackward = bLeft = bRight = false;
954   
955      if( this->bForward )
[10019]956      {
[10291]957        //printf("ShipCoorX: %f \n", this->getRelCoor().x);
[10032]958        if(this->getRelCoor().x < this->travelDistancePlus.x)
959        {
[10098]960          if (this->travelVelocity.x < this->travelSpeed)
[10032]961          {
[10098]962            this->travelVelocity.x += (airCoeff + 1.0)*this->acceleration*dt;
[10032]963          }
964          else
965          {
[10098]966            this->travelVelocity.x = this->travelSpeed;
[10032]967          }
968        }
969        else
970        {
[10098]971          this->travelVelocity.x = 0.0f;
[10032]972        }
[10019]973      }
[10032]974   
975      if( this->bBackward )
[10019]976      {
[10032]977        if(this->getRelCoor().x > this->travelDistanceMinus.x)
978        {
[10098]979          if (this->travelVelocity.x > -this->travelSpeed)
[10032]980          {
[10098]981            this->travelVelocity.x -= (airCoeff + 1.0)*this->acceleration*dt;
[10032]982          }
983          else
984          {
[10098]985            this->travelVelocity.x = -this->travelSpeed;
[10032]986          }
987        }
988        else
989        {
[10098]990          this->travelVelocity.x = 0.0f;
[10032]991        }
[10019]992      }
[10032]993   
994      if( this->bLeft)
[10019]995      {
[10032]996        if(this->getRelCoor().z > this->travelDistanceMinus.y)
997        {
[10098]998          if (this->travelVelocity.z > -this->travelSpeed)
[10032]999          {
[10098]1000            this->travelVelocity.z -= (airCoeff + 1.0)*this->acceleration*dt;
[10032]1001          }
1002          else
1003          {
[10098]1004            this->travelVelocity.z = -this->travelSpeed;
[10032]1005          }
1006        }
1007        else
1008        {
[10098]1009          this->travelVelocity.z = 0.0f;
[10032]1010        }
[10043]1011        this->setRelDirSoft(Quaternion(-pi/6, Vector(1,0,0)), 6);
[10019]1012      }
[10032]1013   
1014      if( this->bRight)
[10019]1015      {
[10291]1016        //printf("ShipCoorZ: %f \n", this->getRelCoor().z);
[10032]1017        if(this->getRelCoor().z < this->travelDistancePlus.y)
1018        {
[10098]1019          if (this->travelVelocity.z < this->travelSpeed)
[10032]1020          {
[10098]1021            this->travelVelocity.z += (airCoeff + 1.0)*this->acceleration*dt;
[10032]1022          }
1023          else
1024          {
[10098]1025            this->travelVelocity.z = this->travelSpeed;
[10032]1026          }
1027        }
1028        else
1029        {
[10098]1030          this->travelVelocity.z = 0.0f;
[10032]1031        }
[10043]1032        this->setRelDirSoft(Quaternion(pi/6, Vector(1,0,0)), 6);
[10019]1033      }
[10032]1034      if (!this->bRight && !this->bLeft)
1035      {
[10043]1036        this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 6);
[10032]1037      }
1038
[10043]1039    //normalisation of the vectors (vector sum must be <= travelspeed)
[10098]1040    float xzNorm = sqrt(pow(this->travelVelocity.x, 2) + pow(this->travelVelocity.z, 2));
[10043]1041    if (xzNorm > this->travelSpeed)
1042    {
[10098]1043      this->travelVelocity.x = this->travelVelocity.x/xzNorm * this->travelSpeed;
1044      this->travelVelocity.z = this->travelVelocity.z/xzNorm * this->travelSpeed;
[10043]1045    }
[10032]1046
[10099]1047    //this moves camera and ship along the travel path.
[10297]1048    if(!this->entityTrack) 
1049       this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
[10099]1050
[10043]1051    break;
[10019]1052    }
[10032]1053    case Playable::Vertical:
1054      break;
[10017]1055    default:
[10032]1056      PRINTF(4)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
[10017]1057  }
[10099]1058   //set new coordinates calculated through key- events.
[10098]1059  this->shiftCoor (this->travelVelocity * dt);
[9975]1060}
[10017]1061
[10032]1062void SpaceShip::setPlaymodeXML(const std::string& playmode)
1063{
1064  this->setPlaymode(Playable::stringToPlaymode(playmode));
1065}
1066
[10113]1067/**
1068 * @brief jumps to the next WeaponConfiguration
1069 */
1070void SpaceShip::nextWeaponConfig()
1071{
[10117]1072  PRINTF(0)("Requested next weapon config!\n");
1073  this->weaponMan.nextWeaponConfig();
[10113]1074  Playable::weaponConfigChanged();
1075}
1076
1077/**
1078 * @brief moves to the last WeaponConfiguration
1079 */
1080void SpaceShip::previousWeaponConfig()
1081{
[10117]1082  this->curWeaponPrimary    = (this->curWeaponPrimary + 1) % 3;
[10113]1083  this->weaponMan.changeWeaponConfig(this->curWeaponPrimary);
1084  Playable::weaponConfigChanged();
[10117]1085}
1086
[10274]1087void SpaceShip::hit( float damage, WorldEntity* killer)
[10117]1088{
1089  this->damage(killer->getDamage(),0);
1090}
[10120]1091
1092void SpaceShip::updateElectronicWidget()
1093{
[10139]1094  if (this->electronicWidget != NULL)
1095  { //if it exists already: update it
1096     this->electronicWidget->setMaximum(this->electronicMax);
1097     this->electronicWidget->setValue(this->electronicCur);
1098  }
1099  else
1100  { //create the widget
1101    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
[10230]1102    this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
[10194]1103    //this->electronicWidget->setDisplayedName("Electronics:");
[10139]1104    //this->electronicWidget->setSize2D(100,20);
1105    //this->electronicWidget->setAbsCoor2D(150,200);
1106    this->updateElectronicWidget();
1107    if (this->hasPlayer())
1108      State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
1109  }
[10120]1110}
1111
1112void SpaceShip::updateShieldWidget()
1113{
[10139]1114  if (this->shieldWidget != NULL)
1115  { 
1116    this->shieldWidget->setMaximum(this->shieldMax);
1117    this->shieldWidget->setValue(this->shieldCur);;
1118  }
1119  else
1120  {
1121    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
[10230]1122    this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
[10194]1123    //this->shieldWidget->setDisplayedName("Shield:");
[10139]1124    //his->shieldWidget->setSize2D(100,20);
1125    //this->shieldWidget->setAbsCoor2D(200,200);
1126    this->updateShieldWidget();
1127    if (this->hasPlayer())
1128      State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
1129  }
[10120]1130}
[10270]1131
1132void SpaceShip::setCameraDistance(float dist)
1133{
1134  State::getCamera()->setViewTopDistance(dist);
1135}
1136
1137void SpaceShip::setCameraFovy(float fovy)
1138{
1139  State::getCamera()->setViewTopFovy(fovy);
1140}
[10291]1141
1142void SpaceShip::updateTravelDistance()
1143{
[10303]1144  float x = 1.25*fabsf(State::getCamera()->getAbsCoor().y) * tan(State::getCamera()->getFovy()*M_PI /360.0);
[10291]1145  float y = x / State::getCamera()->getAspectRatio();
1146  //State::getCamera()->setAbsCoor(-5, 1000, 0);
1147
1148
1149  //State::getCamera()->getAbsCoor().print();
1150  printf("CameraRelCoorY: %f \n", State::getCamera()->getRelCoor().y);
1151
1152  printf("x: %f, y: %f \n", x, y);
[10303]1153  this->travelDistancePlus = Vector2D(y, x);
1154  this->travelDistanceMinus = Vector2D(-y, -x);
[10291]1155
1156  //this->isTravelDistanceInit = true;
[10297]1157}
Note: See TracBrowser for help on using the repository browser.