Changeset 8544 for code/branches/dockingsystem2/src
- Timestamp:
- May 23, 2011, 4:12:27 PM (14 years ago)
- Location:
- code/branches/dockingsystem2/src
- Files:
-
- 6 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 } -
code/branches/dockingsystem2/src/modules/docking/DockingController.h
r8493 r8544 50 50 51 51 void setDock(Dock* dock) { this->dock = dock; } 52 void set Entity(ControllableEntity* entity) { this->entity = entity; }52 void setPlayer(PlayerInfo* player) { this->player = player; } 53 53 54 54 protected: … … 56 56 57 57 private: 58 bool docking; 59 58 60 Dock* dock; 59 bool docking; 61 PlayerInfo* player; 62 60 63 ControllableEntity* entity; 61 64 }; -
code/branches/dockingsystem2/src/modules/docking/MoveToDockingTarget.cc
r8501 r8544 53 53 { 54 54 assert(parent); 55 parent->dockingAnimationFinished(player); 55 56 DockingController *dockingController = new DockingController(this); 57 dockingController->setDock(parent); 58 dockingController->setPlayer(player); 59 dockingController->takeControl(true); 60 56 61 return true; 57 62 } … … 59 64 bool MoveToDockingTarget::release(PlayerInfo *player) 60 65 { 61 assert(parent); 66 //TODO: Investigate strange things... 67 parent->detach((WorldEntity*)player->getControllableEntity()); 68 62 69 parent->undockingAnimationFinished(player); 63 70 return true; -
code/branches/dockingsystem2/src/modules/docking/MoveToDockingTarget.h
r8493 r8544 38 38 #include "DockingPrereqs.h" 39 39 #include "DockingAnimation.h" 40 #include "DockingController.h" 40 41 #include "Dock.h" 41 42 -
code/branches/dockingsystem2/src/orxonox/infos/PlayerInfo.cc
r8382 r8544 213 213 } 214 214 215 void PlayerInfo::pauseControl() 216 { 217 ControllableEntity* entity = this->controllableEntity_; 218 219 if (!entity) 220 return; 221 222 this->controllableEntity_->getController()->setActive(false); 223 //this->controllableEntity_->getController()->setControllableEntity(NULL); 224 this->controllableEntity_->setController(0); 225 } 226 215 227 void PlayerInfo::stopTemporaryControl() 216 228 { -
code/branches/dockingsystem2/src/orxonox/infos/PlayerInfo.h
r8289 r8544 68 68 void startControl(ControllableEntity* entity); 69 69 void stopControl(); 70 void pauseControl(); 70 71 void startTemporaryControl(ControllableEntity* entity); 71 72 void stopTemporaryControl();
Note: See TracChangeset
for help on using the changeset viewer.