Changeset 10031 for code/branches/turretFS14
- Timestamp:
- Apr 10, 2014, 4:06:03 PM (11 years ago)
- Location:
- code/branches/turretFS14
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
r9939 r10031 48 48 <BlinkingBillboard position="17,-1.5,0" material="Examples/Flare" colour="1.0, 0.5, 0.3" amplitude=0.1 frequency=0.5 quadratic=1 /> 49 49 <BlinkingBillboard position="-17,-1.5,0" material="Examples/Flare" colour="0.5, 1.0, 0.3" amplitude=0.1 frequency=0.5 phase=180 quadratic=1 /> 50 51 <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000> 52 <templates> 53 <Template link=spaceshipturrettest /> 54 </templates> 55 <controller> 56 <TurretController team=10 /> 57 </controller> 58 </Turret> 59 50 60 </attached> 51 61 <collisionShapes> -
code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt
r10021 r10031 2 2 <Turret position="0,0,0" collisionType="dynamic" angularDamping=0.999999 mass=100> 3 3 <attached> 4 <Model position="0,0,0" pitch=" 90" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/>4 <Model position="0,0,0" pitch="-90" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/> 5 5 </attached> 6 6 <collisionShapes> -
code/branches/turretFS14/data/levels/turretTest.oxw
r10018 r10031 34 34 35 35 36 < StaticEntity position="0,0,0" yaw=0 pitch=0>36 <MovableEntity position="0,0,0" yaw=0 pitch=0> 37 37 <attached> 38 38 <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" /> … … 42 42 <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" /> 43 43 44 < Turret position="0,10,0" pitch="-90" yaw="0" roll="0" maxPitch=30 maxYaw=30>44 <!-- <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000> 45 45 <templates> 46 46 <Template link=spaceshipturrettest /> … … 49 49 <TurretController team=10 /> 50 50 </controller> 51 </Turret> 51 </Turret> --> 52 52 53 <Model mesh="sphere.mesh" position="2 5,0,0" scale=1/>53 <Model mesh="sphere.mesh" position="20,0,0" scale=1/> 54 54 55 <Model mesh="sphere.mesh" position="0,25,0" scale=1 55 <Model mesh="sphere.mesh" position="0,25,0" scale=1/> 56 56 57 <Model mesh="sphere.mesh" position="0,0, 25" scale=1/>57 <Model mesh="sphere.mesh" position="0,0,30" scale=1/> 58 58 59 59 </attached> 60 </ StaticEntity>60 </MovableEntity> 61 61 62 62 -
code/branches/turretFS14/src/modules/objects/Turret.cc
r10021 r10031 44 44 { 45 45 RegisterObject(Turret); 46 this->startOrientInv_ = Quaternion::IDENTITY; 46 this->startOrient_ = Quaternion::IDENTITY; 47 this->startDir_ = Vector3::ZERO; 48 this->localZ_ = Vector3::UNIT_Z; 49 this->localY_ = Vector3::UNIT_Y; 50 this->localX_ = Vector3::UNIT_X; 47 51 this->maxPitch_ = 0; 48 52 this->maxYaw_ = 0; 53 this->attackRadius_ = 200; 49 54 this->gotOrient_ = false; 50 55 this->rotationThrust_ = 50; … … 63 68 64 69 void Turret::rotatePitch(const Vector2& value) 65 { 66 if (this->maxPitch_ == 0) 67 { 68 return; 69 } 70 if (this->maxPitch_ >= 180) //no need to check, if the limit too big 71 { 72 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f); 73 return; 74 } 75 76 Quaternion drot = startOrientInv_ * this->getOrientation(); 77 78 Ogre::Real val = boundBetween(drot.getPitch(false).valueDegrees(), -180, 180); 79 Ogre::Real offset = boundBetween(Degree(value.x).valueDegrees(), -180, 180); 80 Ogre::Real lowerBound = offset - this->maxPitch_; 81 Ogre::Real upperBound = offset + this->maxPitch_; 82 if (lowerBound < -180) //Avoid wrapping around of the boundaries 83 { 84 lowerBound += this->maxPitch_; 85 upperBound += this->maxPitch_; 86 val = boundBetween(val + this->maxPitch_, -180, 180); //val might wrap around here 87 } 88 else if (upperBound >= 180) //Avoid wrapping around of the boundaries (the other side) 89 { 90 lowerBound -= this->maxPitch_; 91 upperBound -= this->maxPitch_; 92 val = boundBetween(val-this->maxPitch_, -180, 180); //val might wrap around here 93 } 94 if ((val >= lowerBound || value.x > 0) && (val <= upperBound || value.x < 0)) 70 { 71 //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?) 72 /* 73 Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_); 74 Vector3 currentDirProjected = currentDir; 75 currentDirProjected.x = 0; 76 Vector3 startDirProjected = this->startDir_; 77 startDirProjected.x = 0; 78 Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees(); 79 //orxout() << "Pitch: " << angle << endl; 80 //if(angle < this->maxPitch_ || (currentDirProjected.y <= 0 && value.x > 0) || (currentDirProjected.y > 0 && value.x < 0) ) 95 81 { 96 82 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f); 97 83 } 98 return; 84 */ 85 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f); 99 86 } 100 87 101 88 void Turret::rotateYaw(const Vector2& value) 102 89 { 103 if (this->maxPitch_ == 0) 104 { 105 return; 106 } 107 if (this->maxPitch_ >= 180) //no need to check, if the limit too big 90 //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?) 91 /* 92 Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_); 93 Vector3 currentDirProjected = currentDir; 94 currentDirProjected.y = 0; 95 Vector3 startDirProjected = this->startDir_; 96 startDirProjected.y = 0; 97 Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees(); 98 orxout() << "Yaw: " << angle << endl; 99 if(angle < this->maxYaw_ || (currentDirProjected.x <= 0 && value.x < 0) || (currentDirProjected.x > 0 && value.x > 0)) 108 100 { 109 101 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f); 110 return;111 102 } 112 113 Quaternion drot = startOrientInv_ * this->getOrientation(); 114 115 Ogre::Real val = boundBetween(drot.getYaw(false).valueDegrees(), -180, 180); 116 Ogre::Real offset = boundBetween(Degree(value.x).valueDegrees(), -180, 180); 117 Ogre::Real lowerBound = offset - this->maxPitch_; 118 Ogre::Real upperBound = offset + this->maxPitch_; 119 if (lowerBound < -180) //Avoid wrapping around of the boundaries 120 { 121 lowerBound += this->maxPitch_; 122 upperBound += this->maxPitch_; 123 val = boundBetween(val + this->maxPitch_, -180, 180); //val might wrap around here 124 } 125 else if (upperBound >= 180) //Avoid wrapping around of the boundaries (the other side) 126 { 127 lowerBound -= this->maxPitch_; 128 upperBound -= this->maxPitch_; 129 val = boundBetween(val-this->maxPitch_, -180, 180); //val might wrap around here 130 } 131 if ((val >= lowerBound || value.x > 0) && (val <= upperBound || value.x < 0)) 132 { 133 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f); 134 } 135 return; 103 */ 104 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f); 136 105 } 137 106 138 107 void Turret::rotateRoll(const Vector2& value) 139 108 { 140 return; //Standard turrets don't roll 109 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x*0.8f); 110 } 111 112 bool Turret::isInRange(Vector3 position) 113 { 114 Vector3 distance = position - this->getPosition(); 115 if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_)) 116 { 117 return false; 118 } 119 120 Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_); 121 Vector3 dirProjected = dir; 122 dirProjected.x = 0; 123 Vector3 startDirProjected = this->startDir_; 124 startDirProjected.x = 0; 125 Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees(); 126 if(angle > this->maxPitch_) 127 { 128 return false; 129 } 130 131 dirProjected = dir; 132 dirProjected.y = 0; 133 startDirProjected = this->startDir_; 134 startDirProjected.y = 0; 135 angle = startDirProjected.angleBetween(dirProjected).valueDegrees(); 136 if(angle > this->maxYaw_) 137 { 138 return false; 139 } 140 return true; 141 141 } 142 142 … … 145 145 XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode); 146 146 XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode); 147 XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode); 147 148 SUPER(Turret, XMLPort, xmlelement, mode); 148 149 } … … 154 155 if(!gotOrient_) 155 156 { 156 startOrientInv_ = this->getOrientation().Inverse(); 157 gotOrient_ = true; 157 this->startOrient_ = this->getOrientation(); 158 this->localX_ = this->startOrient_ * this->localX_; 159 this->localX_.normalise(); 160 this->localY_ = this->startOrient_ * this->localY_; 161 this->localY_.normalise(); 162 this->localZ_ = this->startOrient_ * this->localZ_; 163 this->localZ_.normalise(); 164 165 //startDir should always be (0,0,-1) 166 this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_); 167 168 this->gotOrient_ = true; 158 169 } 159 Quaternion drot = startOrientInv_ * this->getOrientation(); 160 orxout() << "Pitch: " << drot.getPitch(false).valueDegrees() << "\tYaw: " << drot.getYaw(false).valueDegrees() << "\tRoll: " << drot.getRoll(false).valueDegrees() << endl; 161 170 162 171 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 163 172 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); … … 165 174 } 166 175 167 168 Ogre::Real Turret::boundBetween(Ogre::Real val, Ogre::Real lowerBound, Ogre::Real upperBound)169 {170 if (lowerBound > upperBound){ std::swap(lowerBound, upperBound); }171 val -= lowerBound; //adjust to 0172 Ogre::Real rangeSize = upperBound - lowerBound;173 if (rangeSize == 0){ return upperBound; } //avoid dividing by 0174 return val - (rangeSize * std::floor(val / rangeSize)) + lowerBound;175 }176 177 176 } -
code/branches/turretFS14/src/modules/objects/Turret.h
r10021 r10031 37 37 38 38 #include "objects/ObjectsPrereqs.h" 39 #include "OgreQuaternion.h" 40 41 #include "worldentities/pawns/SpaceShip.h" 39 #include "worldentities/pawns/Pawn.h" 42 40 43 41 namespace orxonox … … 56 54 virtual void tick(float dt); 57 55 56 virtual bool isInRange(Vector3 position); 57 58 58 inline void setMaxPitch(Ogre::Real pitch) 59 59 {this->maxPitch_ = pitch;} … … 68 68 {return this->maxYaw_;} 69 69 70 inline void setAttackRadius(float radius) 71 {this->attackRadius_ = radius;} 72 73 inline float getAttackRadius() 74 {return this->attackRadius_;} 75 76 70 77 private: 71 78 bool gotOrient_; 72 79 Ogre::Real maxPitch_; 73 80 Ogre::Real maxYaw_; 74 Quaternion startOrientInv_; 81 float attackRadius_; 82 Quaternion startOrient_; 83 Vector3 startDir_; 84 Vector3 localZ_; 85 Vector3 localY_; 86 Vector3 localX_; 75 87 float rotationThrust_; 76 88 77 89 btVector3 localAngularAcceleration_; 78 79 Ogre::Real boundBetween(float val, float lowerBound, float upperBound);80 90 }; 81 91 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
r10018 r10031 27 27 */ 28 28 29 #include "TurretController.h" 29 #include "TurretController.h" 30 #include "worldentities/pawns/Pawn.h" 31 #include "Turret.h" 30 32 31 33 namespace orxonox … … 36 38 { 37 39 RegisterObject(TurretController); 38 counter = 0;39 flag = false;40 40 } 41 41 … … 45 45 } 46 46 47 void TurretController::searchTarget() 48 { 49 Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity()); 50 if(target_ && turret->isInRange(target_->getPosition())) 51 { 52 return; 53 } 54 else 55 { 56 this->forgetTarget(); 57 } 58 59 60 ControllableEntity* parent = orxonox_cast<ControllableEntity*>(turret->getParent()); 61 if(parent) 62 { 63 Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget()); 64 if(parenttarget && turret->isInRange(parenttarget->getPosition())) 65 { 66 this->setTarget(parenttarget); 67 turret->setTarget(parenttarget); 68 return; 69 } 70 } 71 72 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 73 { 74 Pawn* entity = orxonox_cast<Pawn*>(*it); 75 if (ArtificialController::sameTeam(this->getControllableEntity(), entity, this->getGametype())) 76 continue; 77 78 if(turret->isInRange(entity->getPosition())) 79 { 80 this->setTarget(entity); 81 turret->setTarget(entity); 82 break; 83 } 84 } 85 } 86 47 87 void TurretController::tick(float dt) 48 88 { 49 counter += dt; 50 if(counter >= 10) 89 if (!this->isActive() || !this->getControllableEntity()) 90 return; 91 this->searchTarget(); 92 this->getControllableEntity()->rotatePitch(0.2); 93 /*if(target_) 51 94 { 52 counter = 0; 53 flag = !flag; 54 orxout() << "Direction change" << endl; 55 } 56 if(flag) 57 { 58 this->getControllableEntity()->rotatePitch(10*dt); 59 //this->getControllableEntity()->rotateYaw(10*dt); 60 } 61 else 62 { 63 this->getControllableEntity()->rotatePitch(-10*dt); 64 //this->getControllableEntity()->rotateYaw(-10*dt); 65 } 95 this->aimAtTarget(); 96 //It says move, but really it only turns 97 this->moveToTargetPosition(); 98 if(this->isLookingAtTarget(Degree(5).valueRadians())) 99 { 100 orxout() << 42 << endl; 101 } 102 }*/ 66 103 } 67 104 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
r10018 r10031 44 44 45 45 private: 46 float counter; 47 bool flag; 46 void searchTarget(); 48 47 }; 49 48 } -
code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc
r9667 r10031 414 414 else if (this->isDynamic()) 415 415 { 416 orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;417 return false;416 //orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl; 417 //return false; 418 418 } 419 419 else if (this->isKinematic() && newParent->isDynamic())
Note: See TracChangeset
for help on using the changeset viewer.