Changeset 6055 for code/branches/steering/src/orxonox/controllers
- Timestamp:
- Nov 13, 2009, 11:21:40 AM (15 years ago)
- Location:
- code/branches/steering/src/orxonox/controllers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/steering/src/orxonox/controllers/Controller.cc
r6045 r6055 46 46 { 47 47 } 48 49 Vector3 Controller::getTarget() {50 return this->controllableEntity_->getPosition() + (this->controllableEntity_->getOrientation() * Vector3::UNIT_Z);51 }52 48 } -
code/branches/steering/src/orxonox/controllers/Controller.h
r6045 r6055 58 58 virtual void changedControllableEntity() {} 59 59 60 virtual Vector3 getTarget(); 60 virtual bool canFindTarget() 61 { return false; } 62 virtual Vector3 getTarget() 63 { return Vector3::ZERO; } 61 64 62 65 protected: -
code/branches/steering/src/orxonox/controllers/NewHumanController.cc
r6045 r6055 37 37 #include "core/ConsoleCommand.h" 38 38 #include "worldentities/ControllableEntity.h" 39 #include "worldentities/pawns/Pawn.h"40 #include "gametypes/Gametype.h"41 39 #include "infos/PlayerInfo.h" 42 #include "overlays/ Map.h"40 #include "overlays/OrxonoxOverlay.h" 43 41 #include "graphics/Camera.h" 44 42 #include "sound/SoundManager.h" 45 #include "Radar.h"46 43 #include "Scene.h" 47 44 48 45 namespace orxonox 49 46 { 50 51 47 CreateUnloadableFactory(NewHumanController); 52 48 … … 55 51 RegisterObject(NewHumanController); 56 52 57 overlaySize = 0.08; 53 overlaySize_ = 0.08; 54 controlMode_ = 0; 58 55 59 controlMode = 0; 56 crossHairOverlay_ = new OrxonoxOverlay(this); 57 crossHairOverlay_->setBackgroundMaterial("Orxonox/Crosshair3"); 58 crossHairOverlay_->setSize(Vector2(overlaySize_, overlaySize_)); 59 crossHairOverlay_->show(); 60 60 61 CrossHairOverlay = new OrxonoxOverlay(this);62 CrossHairOverlay->setBackgroundMaterial("Orxonox/Crosshair3");63 CrossHairOverlay->setSize(Vector2(overlaySize,overlaySize));64 CrossHairOverlay->show();61 // HACK: Define which objects are targettable when considering the creator of an orxonox::Model 62 this->targetMask_.exclude(ClassByString("BaseObject")); 63 this->targetMask_.include(ClassByString("WorldEntity")); 64 this->targetMask_.exclude(ClassByString("Projectile")); 65 65 } 66 66 67 67 NewHumanController::~NewHumanController() 68 68 { 69 if ( this->isInitialized())69 if (this->isInitialized()) 70 70 { 71 71 } 72 72 } 73 73 74 void NewHumanController::tick(float dt) { 75 CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize/2)); 74 void NewHumanController::tick(float dt) 75 { 76 crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2)); 76 77 77 78 HumanController::tick(dt); … … 99 100 100 101 /* 101 102 // Get results, create a node/entity on the position 103 for ( itr = result.begin(); itr != result.end(); itr++ ) 104 { 105 if (itr->movable && itr->movable->getName() == "Head") 106 { 107 soundMgr->StopSound( &jaguarSoundChannel ); 108 soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel ); 109 break; 110 } // if 111 } 102 // Get results, create a node/entity on the position 103 for ( itr = result.begin(); itr != result.end(); itr++ ) 104 { 105 if (itr->movable && itr->movable->getName() == "Head") 106 { 107 soundMgr->StopSound( &jaguarSoundChannel ); 108 soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel ); 109 break; 110 } // if 111 } 112 112 */ 113 113 114 HumanController::localController_s->getControllableEntity()->fire(firemode); 115 //} 116 //} 114 HumanController::localController_s->getControllableEntity()->fire(firemode); 117 115 } 118 116 119 Vector3 NewHumanController::getTarget() { 120 Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray()); 117 Vector3 NewHumanController::getTarget() 118 { 119 Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray()); 121 120 122 //std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << " Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;121 //std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << " Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl; 123 122 124 123 Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5); 125 124 126 127 125 rsq->setRay(mouseRay); 126 rsq->setSortByDistance(true); 128 127 129 /*130 Distance of objects:131 ignore everything under 200 maybe even take 1000 as min distance to shoot at128 /* 129 Distance of objects: 130 ignore everything under 200 maybe even take 1000 as min distance to shoot at 132 131 133 shots are regularly traced and are entities!!!!!!!!! this is the biggest problem134 they vanish only after a distance of 10'000135 */132 shots are regularly traced and are entities!!!!!!!!! this is the biggest problem 133 they vanish only after a distance of 10'000 134 */ 136 135 137 136 138 Ogre::RaySceneQueryResult &result = rsq->execute();137 Ogre::RaySceneQueryResult& result = rsq->execute(); 139 138 140 Ogre::RaySceneQueryResult::iterator itr; 141 for ( itr = result.begin(); itr != result.end(); itr++ ) 139 Ogre::RaySceneQueryResult::iterator itr; 140 for (itr = result.begin(); itr != result.end(); ++itr) 141 { 142 //std::cout << "distance: " << itr->distance << " name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType(); 143 if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) 142 144 { 143 //std::cout << "distance: " << itr->distance << " name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType(); 144 if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) { 145 //std::cout << " TAGGED"; 146 itr->movable->getParentSceneNode()->showBoundingBox(true); 147 std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl; 148 return itr->movable->getParentSceneNode()->_getDerivedPosition(); 145 // Try to cast the user pointer 146 WorldEntity* wePtr = dynamic_cast<WorldEntity*>(itr->movable->getUserObject()); 147 if (wePtr) 148 { 149 BaseObject* creator = wePtr->getCreator(); 150 if (this->targetMask_.isExcluded(creator->getIdentifier())) 151 continue; 149 152 } 150 //std::cout << endl; 153 //std::cout << " TAGGED"; 154 itr->movable->getParentSceneNode()->showBoundingBox(true); 155 std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl; 156 return itr->movable->getParentSceneNode()->_getDerivedPosition(); 151 157 } 158 //std::cout << endl; 159 } 152 160 153 //if (result.front().movable->isInScene()) std::cout << "in scene" << endl;154 // && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);155 //result.front().movable->setVisible(false);161 //if (result.front().movable->isInScene()) std::cout << "in scene" << endl; 162 // && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true); 163 //result.front().movable->setVisible(false); 156 164 157 165 //std::cout << endl; 158 166 /* 159 160 161 162 167 if (!result.empty()) { 168 Ogre::RaySceneQueryResultEntry obj = result.front(); 169 std::cout << "distance: " << obj.distance << " name: " << obj.movable->getName() << endl; 170 } 163 171 */ 164 return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z );165 //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);172 return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 100); 173 //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z); 166 174 } 167 175 … … 174 182 //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl; 175 183 } 184 176 185 void NewHumanController::pitch(const Vector2& value) 177 186 { … … 182 191 //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl; 183 192 } 184 185 193 } -
code/branches/steering/src/orxonox/controllers/NewHumanController.h
r6045 r6055 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "core/ClassTreeMask.h" 34 35 #include "HumanController.h" 35 #include "overlays/OrxonoxOverlay.h"36 #include "util/OgreForwardRefs.h"37 36 38 37 namespace orxonox … … 53 52 void changeMode(unsigned int controleMode); 54 53 54 virtual bool canFindTarget() { return true; } 55 55 virtual Vector3 getTarget(); 56 56 … … 58 58 float currentYaw_; 59 59 float currentPitch_; 60 OrxonoxOverlay *CrossHairOverlay; 61 float overlaySize; 62 unsigned int controlMode; 60 OrxonoxOverlay* crossHairOverlay_; 61 float overlaySize_; 62 unsigned int controlMode_; 63 ClassTreeMask targetMask_; 63 64 }; 64 65 }
Note: See TracChangeset
for help on using the changeset viewer.