Changeset 10049 for code/branches/turretFS14/src/modules/objects/Turret.cc
- Timestamp:
- May 8, 2014, 4:04:53 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/src/modules/objects/Turret.cc
r10044 r10049 38 38 39 39 /** 40 * @brief Constructor 40 @brief 41 Sets default values for all variables. Also hides the turret from the radar. 42 43 @param context 44 The context 41 45 */ 42 46 Turret::Turret(Context* context) : Pawn(context) … … 48 52 this->localY_ = Vector3::UNIT_Y; 49 53 this->localX_ = Vector3::UNIT_X; 50 this->attackRadius_ = 200; 54 this->maxAttackRadius_ = 200; 55 this->minAttackRadius_ = 0; 51 56 this->maxPitch_ = 90; 52 57 this->maxYaw_ = 90; … … 58 63 59 64 /** 60 * @brief Destructor 65 @brief 66 Destructor. Nothing to see here. 61 67 */ 62 68 Turret::~Turret() … … 65 71 } 66 72 67 73 /** 74 @brief 75 Checks, if a (world)position is inside the turret's range. 76 77 This function is safe to use on turrets that are attached, rotated, etc. 78 The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius'. 79 80 @param position 81 The position to check 82 */ 68 83 bool Turret::isInRange(const Vector3 &position) 69 84 { 70 85 //Check distance 71 86 Vector3 distance = position - this->getWorldPosition(); 72 if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_)) 87 float distanceVal = distance.squaredLength(); 88 if(distanceVal > (this->maxAttackRadius_ * this->maxAttackRadius_) || distanceVal < (this->minAttackRadius_ * this->minAttackRadius_)) 73 89 { 74 90 return false; … … 100 116 } 101 117 118 /** 119 @brief 120 Rotates the turret to make it aim at a certain position. 121 122 @note 123 There are no checks, if the position is valid (i.e. if the turret is allowed to aim there). 124 This function must be called again for every tick, or the turret will stop rotating. 125 126 @param position 127 The position to aim at 128 */ 102 129 void Turret::aimAtPosition(const Vector3& position) 103 130 { … … 106 133 107 134 this->rotation_ = currDir.getRotationTo(targetDir); 108 109 } 110 135 } 136 137 /** 138 @brief 139 Does currently nothing. 140 141 Should rotate the turret with the specified pitch. Contains a failed attempt at limiting said rotation. 142 */ 111 143 void Turret::rotatePitch(const Vector2& value) 112 144 { … … 127 159 } 128 160 161 /** 162 @brief 163 Does currently nothing. 164 165 Should rotate the turret with the specified yaw. Contains a failed attempt at limiting said rotation. 166 */ 129 167 void Turret::rotateYaw(const Vector2& value) 130 168 { … … 145 183 } 146 184 185 /** 186 @brief 187 Does currently nothing. 188 189 May be used to limit turret's rotation in the future. 190 */ 147 191 void Turret::rotateRoll(const Vector2& value) 148 192 { 149 193 } 150 194 195 /** 196 @brief 197 Loads parameters from xml 198 199 Parameters loaded are: rotationThrust, maxAttackRadius, minAttackRadius, maxYaw, maxPitch 200 */ 151 201 void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode) 152 202 { … … 154 204 155 205 XMLPortParamVariable(Turret, "rotationThrust", rotationThrust_, xmlelement, mode); 156 XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode); 206 XMLPortParam(Turret, "maxAttackRadius", setMaxAttackRadius, getMaxAttackRadius, xmlelement, mode); 207 XMLPortParam(Turret, "minAttackRadius", setMinAttackRadius, getMinAttackRadius, xmlelement, mode); 157 208 XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode); 158 209 XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode); 159 210 } 160 211 212 /** 213 @brief 214 The turret's actions are done here. 215 216 Every tick, the turret gets rotated if it should, and the local axes get updated with the parent's rotation. 217 */ 161 218 void Turret::tick(float dt) 162 219 { … … 166 223 if(!this->once_) 167 224 { 168 225 //Account for rotations done in xml 169 226 Quaternion startOrient = this->getOrientation(); 170 227 this->localXStart_ = startOrient * this->localX_; … … 198 255 if(this->rotation_ != Quaternion::IDENTITY) 199 256 { 200 //Don't make the rotation instantaneous 201 Quaternion drot = Quaternion:: Slerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);257 //Don't make the rotation instantaneous. Use an arbitrary interpolation, not that great... 258 Quaternion drot = Quaternion::nlerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_); 202 259 this->rotate(drot, WorldEntity::World); 203 260 this->rotation_ = Quaternion::IDENTITY;
Note: See TracChangeset
for help on using the changeset viewer.