Changeset 10018
- Timestamp:
- Apr 3, 2014, 2:57:05 PM (11 years ago)
- Location:
- code/branches/turretFS14
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt
r10008 r10018 39 39 > 40 40 <attached> 41 <Model position="0,0,0" pitch=" 0" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/>41 <Model position="0,0,0" pitch="90" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/> 42 42 </attached> 43 43 <collisionShapes> -
code/branches/turretFS14/data/levels/turretTest.oxw
r10008 r10018 42 42 <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" /> 43 43 44 <Turret position="0,10,0" pitch=" 0" yaw="90" roll="0">44 <Turret position="0,10,0" pitch="-90" yaw="0" roll="0" maxPitch=30 maxYaw=30> 45 45 <templates> 46 46 <Template link=spaceshipturrettest /> -
code/branches/turretFS14/src/modules/objects/Turret.cc
r10008 r10018 45 45 { 46 46 RegisterObject(Turret); 47 this->controller_ = new WaypointPatrolController(this->getContext()); 48 gotOrient_ = false; 47 this->startOrientInv_ = Quaternion::IDENTITY; 48 this->maxPitch_ = 0; 49 this->maxYaw_ = 0; 50 this->gotOrient_ = false; 49 51 } 50 52 … … 60 62 void Turret::rotatePitch(const Vector2& value) 61 63 { 62 Radian currentPitch = this->getOrientation().getPitch(); 63 Radian startPitch = startOrient_.getPitch(); 64 Radian limit = Radian((Degree)45); 65 Radian upperBoundary = startPitch+limit; 66 if(upperBoundary > Radian(Degree(360))) 64 if (this->maxPitch_ == 0) 67 65 { 68 upperBoundary -= Radian(Degree(360));66 return; 69 67 } 70 Radian lowerBoundary = startPitch-limit; 71 if(lowerBoundary < Radian(Degree(0))) 68 if (this->maxPitch_ >= 180) //no need to check, if the limit too big 72 69 { 73 lowerBoundary += Radian(Degree(360)); 70 SpaceShip::rotatePitch(value); 71 return; 74 72 } 75 //orxout() << "Pitch:\t" << currentPitch << "\t" << startPitch << endl; 76 77 if(currentPitch > upperBoundary && value.x > 0 || 78 currentPitch < lowerBoundary && value.x < 0) 73 74 Quaternion drot = startOrientInv_ * this->getOrientation(); 75 76 Ogre::Real val = boundBetween(drot.getPitch(false).valueDegrees(), -180, 180); 77 Ogre::Real offset = boundBetween(Degree(value.x).valueDegrees(), -180, 180); 78 Ogre::Real lowerBound = offset - this->maxPitch_; 79 Ogre::Real upperBound = offset + this->maxPitch_; 80 if (lowerBound < -180) //Avoid wrapping around of the boundaries 79 81 { 80 //return; 82 lowerBound += this->maxPitch_; 83 upperBound += this->maxPitch_; 84 val = boundBetween(val + this->maxPitch_, -180, 180); //val might wrap around here 81 85 } 82 83 SpaceShip::rotatePitch(value); 86 else if (upperBound >= 180) //Avoid wrapping around of the boundaries (the other side) 87 { 88 lowerBound -= this->maxPitch_; 89 upperBound -= this->maxPitch_; 90 val = boundBetween(val-this->maxPitch_, -180, 180); //val might wrap around here 91 } 92 if ((val >= lowerBound || value.x > 0) && (val <= upperBound || value.x < 0)) 93 { 94 SpaceShip::rotatePitch(value); 95 } 96 return; 84 97 } 85 98 86 99 void Turret::rotateYaw(const Vector2& value) 87 100 { 101 if (this->maxPitch_ == 0) 102 { 103 return; 104 } 105 if (this->maxPitch_ >= 180) //no need to check, if the limit too big 106 { 107 SpaceShip::rotateYaw(value); 108 return; 109 } 88 110 89 Radian currentYaw = this->getOrientation().getYaw(); 90 Radian startYaw = startOrient_.getYaw(); 91 Radian limit = Radian(Degree(45)); 92 Radian upperBoundary = startYaw + limit; 93 Radian lowerBoundary = startYaw - limit; 94 /*if(upperBoundary >= Radian(Degree(180))); 111 Quaternion drot = startOrientInv_ * this->getOrientation(); 112 113 Ogre::Real val = boundBetween(drot.getYaw(false).valueDegrees(), -180, 180); 114 Ogre::Real offset = boundBetween(Degree(value.x).valueDegrees(), -180, 180); 115 Ogre::Real lowerBound = offset - this->maxPitch_; 116 Ogre::Real upperBound = offset + this->maxPitch_; 117 if (lowerBound < -180) //Avoid wrapping around of the boundaries 95 118 { 96 upperBoundary -= Radian(Degree(180));97 lowerBoundary -= Radian(Degree(180));98 currentYaw -= Radian(Degree(180));119 lowerBound += this->maxPitch_; 120 upperBound += this->maxPitch_; 121 val = boundBetween(val + this->maxPitch_, -180, 180); //val might wrap around here 99 122 } 100 if(lowerBoundary <= Radian(Degree(-180)))123 else if (upperBound >= 180) //Avoid wrapping around of the boundaries (the other side) 101 124 { 102 lowerBoundary += Radian(Degree(180)); 103 upperBoundary += Radian(Degree(180)); 104 currentYaw += Radian(Degree(180)); 105 }*/ 106 //orxout() << "Yaw:\t" << (Degree)currentYaw << "\t" << (Degree)upperBoundary << "\t" << (Degree)lowerBoundary << endl; 107 //if((currentYaw > upperBoundary && value.x > 0) || 108 // (currentYaw < lowerBoundary && value.x < 0)) 109 if((currentYaw < Radian(1) && value.x < 0) || (currentYaw > Radian(3) && value.x>0)) 125 lowerBound -= this->maxPitch_; 126 upperBound -= this->maxPitch_; 127 val = boundBetween(val-this->maxPitch_, -180, 180); //val might wrap around here 128 } 129 if ((val >= lowerBound || value.x > 0) && (val <= upperBound || value.x < 0)) 110 130 { 111 //return;131 SpaceShip::rotateYaw(value); 112 132 } 113 SpaceShip::rotateYaw(value);133 return; 114 134 } 115 135 116 136 void Turret::rotateRoll(const Vector2& value) 117 137 { 118 SpaceShip::rotateRoll(value); 119 } 120 121 void Turret::setAlertnessRadius(float value) 122 { 123 this->controller_->setAlertnessRadius(value); 124 } 125 float Turret::getAlertnessRadius() 126 { 127 return this->controller_->getAlertnessRadius(); 138 return; //Standard turrets don't roll 128 139 } 129 140 130 141 void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode) 131 142 { 143 XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode); 144 XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode); 132 145 SUPER(Turret, XMLPort, xmlelement, mode); 133 XMLPortParam(Turret, "alertnessRadius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues("400");134 146 } 135 147 136 148 void Turret::tick(float dt) 137 149 { 138 orxout() << "Pitch: " << this->getOrientation().getPitch() << "\tYaw: " << this->getOrientation().getYaw() << "\tRoll: " << this->getOrientation().getRoll() << endl;139 150 if(!gotOrient_) 140 151 { 141 startOrient _ = this->getOrientation();152 startOrientInv_ = this->getOrientation().Inverse(); 142 153 gotOrient_ = true; 143 154 } 155 Quaternion drot = startOrientInv_ * this->getOrientation(); 156 orxout() << "Pitch: " << drot.getPitch(false).valueDegrees() << "\tYaw: " << drot.getYaw(false).valueDegrees() << "\tRoll: " << drot.getRoll(false).valueDegrees() << endl; 144 157 SUPER(Turret, tick, dt); 145 158 } 146 159 160 161 Ogre::Real Turret::boundBetween(Ogre::Real val, Ogre::Real lowerBound, Ogre::Real upperBound) 162 { 163 if (lowerBound > upperBound){ std::swap(lowerBound, upperBound); } 164 val -= lowerBound; //adjust to 0 165 Ogre::Real rangeSize = upperBound - lowerBound; 166 if (rangeSize == 0){ return upperBound; } //avoid dividing by 0 167 return val - (rangeSize * std::floor(val / rangeSize)) + lowerBound; 168 } 169 147 170 } -
code/branches/turretFS14/src/modules/objects/Turret.h
r10008 r10018 40 40 41 41 #include "worldentities/pawns/SpaceShip.h" 42 #include "controllers/TurretController.h" 42 43 43 44 namespace orxonox … … 53 54 virtual void rotateRoll(const Vector2& value); 54 55 55 void setAlertnessRadius(float value);56 float getAlertnessRadius();57 58 56 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 59 57 virtual void tick(float dt); 60 58 59 inline void setMaxPitch(Ogre::Real pitch) 60 {this->maxPitch_ = pitch;} 61 61 62 protected: 63 WaypointPatrolController* controller_; 62 inline Ogre::Real getMaxPitch() 63 {return this->maxPitch_;} 64 65 inline void setMaxYaw(Ogre::Real yaw) 66 {this->maxYaw_ = yaw;} 67 68 inline Ogre::Real getMaxYaw() 69 {return this->maxYaw_;} 70 64 71 private: 65 72 bool gotOrient_; 66 Quaternion startOrient_; 73 Ogre::Real maxPitch_; 74 Ogre::Real maxYaw_; 75 Quaternion startOrientInv_; 76 77 Ogre::Real boundBetween(float val, float lowerBound, float upperBound); 67 78 }; 68 79 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
r10008 r10018 36 36 { 37 37 RegisterObject(TurretController); 38 counter = 0; 39 flag = false; 38 40 } 39 41 … … 45 47 void TurretController::tick(float dt) 46 48 { 47 this->getControllableEntity()->rotateYaw(10*dt); 49 counter += dt; 50 if(counter >= 10) 51 { 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 } 48 66 } 49 67 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
r10008 r10018 42 42 43 43 virtual void tick(float dt); 44 45 private: 46 float counter; 47 bool flag; 44 48 }; 45 49 }
Note: See TracChangeset
for help on using the changeset viewer.