Changeset 6055 for code/branches/steering/src/orxonox
- Timestamp:
- Nov 13, 2009, 11:21:40 AM (15 years ago)
- Location:
- code/branches/steering/src/orxonox
- Files:
-
- 9 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 } -
code/branches/steering/src/orxonox/infos/PlayerInfo.cc
r6045 r6055 138 138 assert(this->controller_); 139 139 this->controller_->setPlayer(this); 140 if (this->controllableEntity_) { 140 if (this->controllableEntity_) 141 { 141 142 this->controller_->setControllableEntity(this->controllableEntity_); 142 143 this->controllableEntity_->setController(this->controller_); … … 160 161 this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_); 161 162 162 if (this->controller_) { 163 if (this->controller_) 164 { 163 165 this->controller_->setControllableEntity(entity); 164 166 this->controllableEntity_->setController(this->controller_); -
code/branches/steering/src/orxonox/weaponsystem/WeaponMode.cc
r5929 r6055 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/XMLPort.h" 34 #include "controllers/Controller.h" 35 #include "worldentities/pawns/Pawn.h" 34 36 35 37 #include "Munition.h" … … 194 196 } 195 197 196 Vector3 WeaponMode::getMuzzlePosition() const198 void WeaponMode::computeMuzzleParameters() 197 199 { 198 200 if (this->weapon_) 199 return (this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_); 200 else 201 return this->muzzleOffset_; 202 } 203 204 const Quaternion& WeaponMode::getMuzzleOrientation() const 201 { 202 this->muzzlePosition_ = this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_; 203 204 Controller* controller = this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getController(); 205 if (controller->canFindTarget()) 206 { 207 Vector3 muzzleDirection(controller->getTarget() - this->muzzlePosition_); 208 this->muzzleOrientation_ = this->weapon_->getWorldOrientation() * (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection); 209 } 210 else 211 this->muzzleOrientation_ = this->weapon_->getWorldOrientation(); 212 } 213 else 214 { 215 this->muzzlePosition_ = this->muzzleOffset_; 216 this->muzzleOrientation_ = Quaternion::IDENTITY; 217 } 218 } 219 220 Vector3 WeaponMode::getMuzzleDirection() const 205 221 { 206 222 if (this->weapon_) 207 return this->weapon_->getWorldOrientation(); 208 else 209 return Quaternion::IDENTITY; 210 } 211 212 Vector3 WeaponMode::getMuzzleDirection() const 213 { 214 if (this->weapon_) 215 return (this->weapon_->getWorldOrientation() * WorldEntity::FRONT); 223 return (this->getMuzzleOrientation() * WorldEntity::FRONT); 216 224 else 217 225 return WorldEntity::FRONT; -
code/branches/steering/src/orxonox/weaponsystem/WeaponMode.h
r6045 r6055 38 38 #include "core/SubclassIdentifier.h" 39 39 #include "tools/Timer.h" 40 41 #include "weaponsystem/Weapon.h"42 #include "weaponsystem/WeaponPack.h"43 #include "weaponsystem/WeaponSystem.h"44 #include "worldentities/pawns/Pawn.h"45 #include "controllers/Controller.h"46 40 47 41 namespace orxonox … … 115 109 { return this->muzzleOffset_; } 116 110 117 Vector3 getMuzzlePosition() const; 118 const Quaternion& getMuzzleOrientation() const; 111 void computeMuzzleParameters(); 112 const Vector3& getMuzzlePosition() const 113 { return this->muzzlePosition_; } 114 const Quaternion& getMuzzleOrientation() const 115 { return this->muzzleOrientation_; } 119 116 Vector3 getMuzzleDirection() const; 120 117 … … 131 128 { return this->mode_; } 132 129 133 inline Vector3 getTarget() 134 { return this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getController()->getTarget(); } 130 Vector3 getTarget(); 135 131 136 132 protected: … … 161 157 Timer reloadTimer_; 162 158 bool bReloading_; 159 160 Vector3 muzzlePosition_; 161 Quaternion muzzleOrientation_; 163 162 }; 164 163 } -
code/branches/steering/src/orxonox/worldentities/ControllableEntity.h
r6045 r6055 142 142 inline Controller* getController() const 143 143 { return this->controller_; } 144 inline void setController(Controller* c)145 { this->controller_ = c; }144 inline void setController(Controller* val) 145 { this->controller_ = val; } 146 146 147 147 protected: -
code/branches/steering/src/orxonox/worldentities/WorldEntity.cc
r6052 r6055 654 654 /** 655 655 @brief 656 Makes this WorldEntity look a specific target location.656 Makes this WorldEntity look at a specific target location. 657 657 @param relativeTo 658 658 @see WorldEntity::TransformSpace
Note: See TracChangeset
for help on using the changeset viewer.