- Timestamp:
- May 23, 2011, 4:12:27 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/dockingsystem2/src/modules/docking/DockingController.cc
r8501 r8544 29 29 #include "DockingController.h" 30 30 31 #include <cmath> 32 31 33 #include "infos/PlayerInfo.h" 32 34 #include "worldentities/ControllableEntity.h" … … 49 51 void DockingController::tick(float dt) 50 52 { 51 this->moveToTargetPosition(); 53 ControllableEntity* entity = this->getControllableEntity(); 54 if (!entity) 55 return; 56 57 float distance = (dock->getWorldPosition() - entity->getPosition()).length(); 58 Vector2 coord = get2DViewdirection( // I don't understand this too 59 entity->getPosition(), 60 entity->getOrientation() * WorldEntity::FRONT, 61 entity->getOrientation() * WorldEntity::UP, 62 dock->getWorldPosition() 63 ); 64 65 // adjust direction of spaceship 66 if (distance > 10) 67 { 68 entity->rotateYaw(-1.0f * 0.8f * sgn(coord.x) * coord.x*coord.x); 69 entity->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 70 } 71 72 /*// adjust speed 73 if (distance < 200 && entity->getVelocity().squaredLength() > dock->getVelocity().squaredLength()) 74 entity->moveFrontBack(0.2f); 75 else 76 entity->moveFrontBack(0.8f);*/ 77 78 entity->moveFrontBack(0.5f * log(distance/10.0f)); 79 80 if (distance < 20) 81 this->positionReached(); 52 82 53 83 SUPER(DockingController, tick, dt); 54 84 } 55 85 86 void DockingController::takeControl(bool docking) 87 { 88 this->docking = docking; 89 90 entity = player->getControllableEntity(); 91 assert(entity); 92 93 if (docking) 94 { 95 COUT(0) << "DockingController::takeControl Taking over control." << std::endl; 96 97 entity->setDestroyWhenPlayerLeft(false); 98 player->pauseControl(); 99 entity->setController(this); 100 this->setControllableEntity(entity); 101 } 102 } 103 56 104 void DockingController::positionReached() 57 105 { 58 // TODO; Give control back to player 59 PlayerInfo* player = this->entity->getPlayer(); 60 assert(player); 106 COUT(0) << "DockingController::positionReached() called." << std::endl; 107 108 assert(this->player); 109 assert(this->dock); 110 111 // stop spaceship 112 dock->attach(entity); 113 entity->setVelocity(0, 0, 0); 114 entity->setOrientation(dock->getOrientation()); 115 116 // give control back to player 117 player->startControl(entity); 118 this->setActive(false); 119 this->controllableEntity_ = NULL; 61 120 62 121 if (docking) 63 122 dock->dockingAnimationFinished(player); 64 else 65 dock->undockingAnimationFinished(player); 123 /*else 124 dock->undockingAnimationFinished(player);*/ 125 126 this->destroy(); 66 127 } 67 128 }
Note: See TracChangeset
for help on using the changeset viewer.