Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9740


Ignore:
Timestamp:
Nov 4, 2013, 3:17:32 PM (11 years ago)
Author:
wroennin
Message:

HUDRadar:function call get3DProjection updated; Math.cc: get3DProjection new transform matrix; Math.h updated

Location:
code/branches/radarDreiD/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/radarDreiD/src/libraries/util/Math.cc

    r9719 r9740  
    196196            @param myposition My position
    197197            @param mydirection My viewing direction
     198            @param myorthonormal My orthonormalvector (pointing upwards through my head)
    198199            @param otherposition The position of the other object
    199200            @param mapangle The angle you look on the 3Dmap
     
    204205             -
    205206        */
    206     orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit)
     207    orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit)
    207208    {
    208209        //
    209210        orxonox::Vector3 distance = otherposition - myposition;
    210211
    211         // project difference vector on our plane
    212         orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
    213 
    214         //float projectionlength = projection.length();
    215 
    216         // project vector for the rotated 3DMap
    217         float xcoordinate = projection.y/(2*detectionlimit);
    218         float ycoordinate = (projection.x*sin(mapangle)+projection.z*cos(mapangle))/(2*detectionlimit);
     212        // new coordinate system base y_coordinate
     213        orxonox::Vector3 myside = -mydirection.crossProduct(myorthonormal);
     214
     215        // inverse of the transform matrix
     216        float determinant = +mydirection.x * (myside.y*myorthonormal.z - myorthonormal.y*myside.z)
     217                                                -mydirection.y * (myside.x*myorthonormal.z - myside.z*myorthonormal.x)
     218                                                +mydirection.z * (myside.x*myorthonormal.y - myside.y*myorthonormal.x);
     219        float invdet = 1/determinant;
     220        orxonox::Vector3 xinvtransform;
     221        orxonox::Vector3 yinvtransform;
     222        orxonox::Vector3 zinvtransform;
     223
     224        xinvtransform.x =  (myside.y      * myorthonormal.z - myorthonormal.y * myside.z       )*invdet;
     225        xinvtransform.y = -(mydirection.y * myorthonormal.z - mydirection.z   * myorthonormal.y)*invdet;
     226        xinvtransform.z =  (mydirection.y * myside.z        - mydirection.z   * myside.y       )*invdet;
     227        yinvtransform.x = -(myside.x      * myorthonormal.z - myside.z        * myorthonormal.x)*invdet;
     228        yinvtransform.y =  (mydirection.x * myorthonormal.z - mydirection.z   * myorthonormal.x)*invdet;
     229        yinvtransform.z = -(mydirection.x * myside.z        - myside.x        * mydirection.z  )*invdet;
     230        zinvtransform.x =  (myside.x      * myorthonormal.y - myorthonormal.x * myside.y       )*invdet;
     231        zinvtransform.y = -(mydirection.x * myorthonormal.y - myorthonormal.x * mydirection.y  )*invdet;
     232        zinvtransform.z =  (mydirection.x * myside.y        - myside.x        * mydirection.x  )*invdet;
     233
     234        // coordinate transformation
     235        distance.x = (xinvtransform.x + yinvtransform.x + zinvtransform.x) * distance.x;
     236        distance.y = (xinvtransform.y + yinvtransform.y + zinvtransform.y) * distance.y;
     237        distance.z = (xinvtransform.z + yinvtransform.z + zinvtransform.z) * distance.z;
     238
     239        // project vector for the rotated 3DMap on screen
     240        float xcoordinate = distance.y/(2*detectionlimit);
     241        float ycoordinate = (distance.x*sin(mapangle)+distance.z*cos(mapangle))/(2*detectionlimit);
    219242        return orxonox::Vector2(xcoordinate , ycoordinate);
    220243    }
  • code/branches/radarDreiD/src/libraries/util/Math.h

    r9719 r9740  
    9292    _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
    9393    _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
    94     _UtilExport orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit);
     94    _UtilExport orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit);
    9595    _UtilExport orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity);
    9696
  • code/branches/radarDreiD/src/modules/overlays/hud/HUDRadar.cc

    r9719 r9740  
    6464        this->shapeMaterials_[RadarViewable::Triangle] = "RadarTriangle.png";
    6565        this->shapeMaterials_[RadarViewable::Square]   = "RadarSquare.png";
    66         this->setDetectionLimit( 1000.0f );
     66        this->setDetectionLimit( 3000.0f );
    6767        this->owner_ = 0;
    6868    }
     
    170170            // calc position on radar...
    171171            //Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
    172             Vector2 coord = get3DProjection(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, wePointer->getWorldPosition(), 0.6435011, detectionLimit_);
     172            Vector2 coord = get3DProjection(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition(), 0.6435011, detectionLimit_);
    173173            coord *= math::pi / 3.5f; // small adjustment to make it fit the texture
    174174            it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f);
Note: See TracChangeset for help on using the changeset viewer.