Changeset 1566 for code/trunk
- Timestamp:
- Jun 8, 2008, 5:04:18 PM (17 years ago)
- Location:
- code/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/Navigation.cc
r1564 r1566 36 36 // TODO: remove the SpaceShip and CameraHandler dependencies 37 37 #include "objects/SpaceShip.h" 38 #include "objects/Projectile.h" 38 39 #include "objects/CameraHandler.h" 39 40 #include "RadarObject.h" … … 87 88 navMarker_->hide(); 88 89 aimMarker_->hide(); 90 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 91 aimMarker_->setDimensions(20, 20); 92 aimMarker_->setUV(0.0, 0.0, 1.0, 1.0); 89 93 container_->addChild(navMarker_); 90 94 container_->addChild(aimMarker_); … … 106 110 navText_->setCaption(Ogre::StringConverter::toString(dist)); 107 111 108 Vector3 pos = focus_->getPosition();109 112 Ogre::Camera* navCam = SpaceShip::getLocalShip()->getCamera()->cam_; 110 113 // transform to screen coordinates 111 pos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * pos; 114 Vector3 pos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * focus_->getPosition(); 115 Vector3 aimpos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), Projectile::getSpeed(), focus_->getPosition(), focus_->getOrientedVelocity()); 112 116 113 117 float xPosRel = 0.5*pos.x+0.5; 114 118 float yPosRel = 1-(0.5*pos.y+0.5); 119 float xAimPosRel = 0.5*aimpos.x+0.5; 120 float yAimPosRel = 1-(0.5*aimpos.y+0.5); 115 121 int xPos = (int) (xPosRel*windowW); 116 122 int yPos = (int) (yPosRel*windowH); 123 int xAimPos = (int) (xAimPosRel*windowW); 124 int yAimPos = (int) (yAimPosRel*windowH); 117 125 int xFromCenter = xPos-windowW/2; 118 126 int yFromCenter = yPos-windowH/2; … … 133 141 navMarker_->setMaterialName("Orxonox/NavArrows"); 134 142 navMarker_->setDimensions(16,16); 143 aimMarker_->hide(); 135 144 float phiUpperCorner = atan((float)(windowW)/(float)(windowH)); 136 145 // from the angle we find out on which edge to draw the marker … … 210 219 // object is in view 211 220 navMarker_->setMaterialName("Orxonox/NavTDC"); 212 navMarker_->setDimensions( 24,24);221 navMarker_->setDimensions(35, 35); 213 222 navMarker_->setUV(0.0, 0.0, 1.0, 1.0); 214 223 navMarker_->setPosition(xPos-navMarker_->getWidth()/2, yPos-navMarker_->getHeight()/2); 224 225 aimMarker_->show(); 226 aimMarker_->setPosition(xAimPos-aimMarker_->getWidth()/2, yAimPos-aimMarker_->getHeight()/2); 227 215 228 navText_->setPosition(xPos+navMarker_->getWidth()/2, yPos+navMarker_->getHeight()/2); 216 229 } … … 259 272 if(focus_ == NULL){ 260 273 navMarker_->hide(); 274 aimMarker_->hide(); 261 275 navText_->hide(); 262 276 } -
code/trunk/src/orxonox/hud/RadarObject.cc
r1564 r1566 120 120 } 121 121 122 const Vector3& RadarObject::getVelocity() const122 Vector3 RadarObject::getOrientedVelocity() const 123 123 { 124 return this->object_->get Velocity();124 return this->object_->getOrientation() * this->object_->getVelocity(); 125 125 } 126 126 } -
code/trunk/src/orxonox/hud/RadarObject.h
r1564 r1566 54 54 55 55 const Vector3& getPosition() const; 56 const Vector3& getVelocity() const;56 Vector3 getOrientedVelocity() const; 57 57 58 58 inline WorldEntity* getObject() const -
code/trunk/src/orxonox/objects/SpaceShipAI.cc
r1564 r1566 238 238 this->setMovePitch(0.8 * sgn(coord.y)); 239 239 240 if ((this->targetPosition_ - this->getPosition()).length() > 300)240 if ((this->targetPosition_ - this->getPosition()).length() > 500) 241 241 this->setMoveLongitudinal(0.8); 242 242 … … 287 287 return; 288 288 289 Vector3 enemymovement = this->target_->getVelocity(); 290 Vector3 distance_normalised = this->target_->getPosition() - this->getPosition(); 291 distance_normalised.normalise(); 292 293 float scalarprod = enemymovement.dotProduct(distance_normalised); 294 float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength(); 295 296 if (aimoffset < 0) 297 { 298 this->bHasTargetPosition_ = false; 299 return; 300 } 301 aimoffset = -scalarprod + sqrt(aimoffset); 302 this->targetPosition_ = this->getPosition() + enemymovement + distance_normalised * aimoffset; 303 this->bHasTargetPosition_ = true; 289 this->targetPosition_ = getPredictedPosition(this->getPosition(), Projectile::getSpeed(), this->target_->getPosition(), this->target_->getOrientation() * this->target_->getVelocity()); 290 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 304 291 } 305 292 -
code/trunk/src/util/Math.cc
r1564 r1566 106 106 return orxonox::Vector2(-sin(angle) * radius, cos(angle) * radius); 107 107 } 108 109 orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity) 110 { 111 float squaredProjectilespeed = projectilespeed * projectilespeed; 112 orxonox::Vector3 distance = targetposition - myposition; 113 float a = distance.squaredLength(); 114 float b = 2 * (distance.x + distance.y + distance.z) * (targetvelocity.x + targetvelocity.y + targetvelocity.z); 115 float c = targetvelocity.squaredLength(); 116 117 float temp = 4*squaredProjectilespeed*c + a*a - 4*b*c; 118 if (temp < 0) 119 return orxonox::Vector3::ZERO; 120 121 temp = sqrt(temp); 122 float time = (temp + a) / (2 * (squaredProjectilespeed - b)); 123 return (targetposition + targetvelocity * time); 124 } -
code/trunk/src/util/Math.h
r1564 r1566 62 62 _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition); 63 63 _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition); 64 _UtilExport orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity); 64 65 65 66 template <typename T>
Note: See TracChangeset
for help on using the changeset viewer.