Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 3, 2014, 1:50:22 PM (11 years ago)
Author:
landauf
Message:

replaced tabs with spaces. no changes in code

File:
1 edited

Legend:

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

    r9939 r9945  
    204204    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)
    205205    {
    206         // Orxonox Vectors: x_direction you are looking, y_direction points up, z_direction points to the right
    207         orxonox::Vector3 distance = otherposition - myposition; // get vector from Ship to object
    208 
    209         // new coordinate system:       x_axsis:        mydirection             (points front)
    210         //                                                      y_axsis:        myorthonormal   (points up)
    211         //                                                      z_axsis:        myside                  (points right)
    212 
    213         orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal); // get 3. base vector
    214 
    215         distance = 4*distance / detectionlimit; // shrink vector on map
    216         if(distance.length() > 1.0f) // if object would wander outside of the map
    217                 {
    218                 distance = distance / distance.length();
    219                         }
    220 
    221         // perform a coordinate transformation to get distance in relation of the position of the ship
    222         orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
    223 
    224         // calculate 2D vector on the map (with angle between x/z - plain and line of sight)
    225         float xcoordinate = distanceShip.z; // z; cause x direction on screen is to the right side
    226         float ycoordinate = distanceShip.x*sin(mapangle)+distanceShip.y*cos(mapangle);
    227         return orxonox::Vector2(xcoordinate , ycoordinate);
     206        // Orxonox Vectors: x_direction you are looking, y_direction points up, z_direction points to the right
     207        orxonox::Vector3 distance = otherposition - myposition; // get vector from Ship to object
     208
     209        // new coordinate system: x_axsis: mydirection   (points front)
     210        //                        y_axsis: myorthonormal (points up)
     211        //                        z_axsis: myside        (points right)
     212
     213        orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal); // get 3. base vector
     214
     215        distance = 4*distance / detectionlimit; // shrink vector on map
     216        if(distance.length() > 1.0f) // if object would wander outside of the map
     217        {
     218            distance = distance / distance.length();
     219        }
     220
     221        // perform a coordinate transformation to get distance in relation of the position of the ship
     222        orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
     223
     224        // calculate 2D vector on the map (with angle between x/z - plain and line of sight)
     225        float xcoordinate = distanceShip.z; // z; cause x direction on screen is to the right side
     226        float ycoordinate = distanceShip.x*sin(mapangle)+distanceShip.y*cos(mapangle);
     227        return orxonox::Vector2(xcoordinate , ycoordinate);
    228228    }
    229229
     
    243243    bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle)
    244244    {
    245         // Orxonox Vectors: x_direction you are looking, y_direction points up, z_direction points to the right
    246         orxonox::Vector3 distance = otherposition - myposition;
    247 
    248         // new coordinate system:       x_axsis:        mydirection             (points front)
    249         //                                                      y_axsis:        myorthonormal   (points up)
    250         //                                                      z_axsis:        myside                  (points right)
    251 
    252         orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal); // get vector from Ship to object
    253 
    254 
    255         // perform a coordinate transformation to get distance in relation of the position of the ship
    256         orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
    257 
    258         if(distanceShip.y >= 0)
    259                 return true;
    260         else
    261                 return false;
     245        // Orxonox Vectors: x_direction you are looking, y_direction points up, z_direction points to the right
     246        orxonox::Vector3 distance = otherposition - myposition;
     247
     248        // new coordinate system: x_axsis: mydirection   (points front)
     249        //                        y_axsis: myorthonormal (points up)
     250        //                        z_axsis: myside        (points right)
     251
     252        orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal); // get vector from Ship to object
     253
     254
     255        // perform a coordinate transformation to get distance in relation of the position of the ship
     256        orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
     257
     258        if(distanceShip.y >= 0)
     259            return true;
     260        else
     261            return false;
    262262    }
    263263
     
    265265                   @brief A value between 0 and 10, in order how other object is in front or in back
    266266                   @param myposition My position
    267                    @param mydirection My viewing direction
    268                    @param myorthonormal My orthonormalvector (pointing upwards through my head)
    269                    @param otherposition The position of the other object
    270                    @param detectionlimit The limit in which objects are shown on the map
     267                   @param mydirection My viewing direction
     268                   @param myorthonormal My orthonormalvector (pointing upwards through my head)
     269                   @param otherposition The position of the other object
     270                   @param detectionlimit The limit in which objects are shown on the map
    271271                   @return value between 0 and 100
    272272    */
    273273    int determineMap3DZOrder(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float detectionlimit)
    274274    {
    275         orxonox::Vector3 distance = otherposition - myposition; // get vector from Ship to object
    276         orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal);      // get vector to the side
    277 
    278         distance = 4*distance / detectionlimit; // shrink vector on map
    279         if(distance.length() > 1.0f) // if object would wander outside of the map
    280         {
    281                 distance = distance / distance.length();
    282         }
    283 
    284         // perform a coordinate transformation to get distance in relation of the position of the ship
    285         orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
    286 
    287         return (int) 50 - 100*distanceShip.x;
     275        orxonox::Vector3 distance = otherposition - myposition; // get vector from Ship to object
     276        orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal); // get vector to the side
     277
     278        distance = 4*distance / detectionlimit; // shrink vector on map
     279        if(distance.length() > 1.0f) // if object would wander outside of the map
     280        {
     281            distance = distance / distance.length();
     282        }
     283
     284        // perform a coordinate transformation to get distance in relation of the position of the ship
     285        orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
     286
     287        return (int) 50 - 100*distanceShip.x;
    288288    }
    289289
     
    300300                y is vector in old coordinates
    301301                T is transform matrix with:
    302                         T = (t1 , t2 , t3)
    303                         t1 = mydirection
    304                         t2 = myorthonormal
    305                         t3 = myside
     302                    T = (t1 , t2 , t3)
     303                    t1 = mydirection
     304                    t2 = myorthonormal
     305                    t3 = myside
    306306
    307307                y = T^(-1)*x
     
    309309    orxonox::Vector3 getTransformedVector(const orxonox::Vector3& distance, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& myside)
    310310    {
    311         // inverse of the transform matrix
    312         float determinant = +mydirection.x * (myorthonormal.y*myside.z - myside.y*myorthonormal.z)
    313                                                 -mydirection.y * (myorthonormal.x*myside.z - myorthonormal.z*myside.x)
    314                                                 +mydirection.z * (myorthonormal.x*myside.y - myorthonormal.y*myside.x);
    315         float invdet = 1/determinant;
    316 
    317         // transform matrix
    318         orxonox::Vector3 xinvtransform;
    319         orxonox::Vector3 yinvtransform;
    320         orxonox::Vector3 zinvtransform;
    321 
    322         xinvtransform.x = (myorthonormal.y * myside.z        - myside.y        * myorthonormal.z)*invdet;
    323         xinvtransform.y = (mydirection.z   * myside.y        - mydirection.y   * myside.z       )*invdet;
    324         xinvtransform.z = (mydirection.y   * myorthonormal.z - mydirection.z   * myorthonormal.y)*invdet;
    325         yinvtransform.x = (myorthonormal.z * myside.x        - myorthonormal.x * myside.z       )*invdet;
    326         yinvtransform.y = (mydirection.x   * myside.z        - mydirection.z   * myside.x       )*invdet;
    327         yinvtransform.z = (myorthonormal.x * mydirection.z   - mydirection.x   * myorthonormal.z)*invdet;
    328         zinvtransform.x = (myorthonormal.x * myside.y        - myside.x        * myorthonormal.y)*invdet;
    329         zinvtransform.y = (myside.x        * mydirection.y   - mydirection.x   * myside.y       )*invdet;
    330         zinvtransform.z = (mydirection.x   * myorthonormal.y - myorthonormal.x * mydirection.y  )*invdet;
    331 
    332         // coordinate transformation
    333         orxonox::Vector3 distanceShip;
    334         distanceShip.x = xinvtransform.x * distance.x + yinvtransform.x * distance.y + zinvtransform.x * distance.z;
    335         distanceShip.y = xinvtransform.y * distance.x + yinvtransform.y * distance.y + zinvtransform.y * distance.z;
    336         distanceShip.z = xinvtransform.z * distance.x + yinvtransform.z * distance.y + zinvtransform.z * distance.z;
    337 
    338         return distanceShip;
     311        // inverse of the transform matrix
     312        float determinant = +mydirection.x * (myorthonormal.y*myside.z - myside.y*myorthonormal.z)
     313                            -mydirection.y * (myorthonormal.x*myside.z - myorthonormal.z*myside.x)
     314                            +mydirection.z * (myorthonormal.x*myside.y - myorthonormal.y*myside.x);
     315        float invdet = 1/determinant;
     316
     317        // transform matrix
     318        orxonox::Vector3 xinvtransform;
     319        orxonox::Vector3 yinvtransform;
     320        orxonox::Vector3 zinvtransform;
     321
     322        xinvtransform.x = (myorthonormal.y * myside.z        - myside.y        * myorthonormal.z)*invdet;
     323        xinvtransform.y = (mydirection.z   * myside.y        - mydirection.y   * myside.z       )*invdet;
     324        xinvtransform.z = (mydirection.y   * myorthonormal.z - mydirection.z   * myorthonormal.y)*invdet;
     325        yinvtransform.x = (myorthonormal.z * myside.x        - myorthonormal.x * myside.z       )*invdet;
     326        yinvtransform.y = (mydirection.x   * myside.z        - mydirection.z   * myside.x       )*invdet;
     327        yinvtransform.z = (myorthonormal.x * mydirection.z   - mydirection.x   * myorthonormal.z)*invdet;
     328        zinvtransform.x = (myorthonormal.x * myside.y        - myside.x        * myorthonormal.y)*invdet;
     329        zinvtransform.y = (myside.x        * mydirection.y   - mydirection.x   * myside.y       )*invdet;
     330        zinvtransform.z = (mydirection.x   * myorthonormal.y - myorthonormal.x * mydirection.y  )*invdet;
     331
     332        // coordinate transformation
     333        orxonox::Vector3 distanceShip;
     334        distanceShip.x = xinvtransform.x * distance.x + yinvtransform.x * distance.y + zinvtransform.x * distance.z;
     335        distanceShip.y = xinvtransform.y * distance.x + yinvtransform.y * distance.y + zinvtransform.y * distance.z;
     336        distanceShip.z = xinvtransform.z * distance.x + yinvtransform.z * distance.y + zinvtransform.z * distance.z;
     337
     338        return distanceShip;
    339339    }
    340340
Note: See TracChangeset for help on using the changeset viewer.