Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 26, 2009, 12:44:49 AM (15 years ago)
Author:
rgrieder
Message:

Stripped sandbox further down to get a light version that excludes almost all core features.
Also, the Ogre dependency has been removed and a little ogremath library been added.

Location:
sandbox_light/src/libraries/util
Files:
9 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • sandbox_light/src/libraries/util/CMakeLists.txt

    r5782 r5789  
    1919
    2020SET_SOURCE_FILES(UTIL_SRC_FILES
    21   CRC32.cc
    2221  Exception.cc
    23   ExprParser.cc
    2422  Math.cc
    2523  MultiType.cc
    2624  OutputBuffer.cc
    2725  OutputHandler.cc
    28   Scope.cc
    2926  SignalHandler.cc
    3027  Sleep.cc
     
    4340    "UTIL_SHARED_BUILD"
    4441  LINK_LIBRARIES
    45     ${CEGUI_LIBRARY}
    46     ${OGRE_LIBRARY}
     42    ogremath_orxonox
    4743  SOURCE_FILES
    4844    ${UTIL_SRC_FILES}
  • sandbox_light/src/libraries/util/Math.cc

    r5738 r5789  
    3434#include "Math.h"
    3535
    36 #include <OgrePlane.h>
    37 
    3836#include "MathConvert.h"
    3937#include "SubString.h"
    40 // Do not remove this include, it avoids linker errors.
    41 #include "mbool.h"
    4238
    4339namespace orxonox
     
    8177        degree = temp;
    8278        return in;
    83     }
    84 
    85 
    86     /**
    87         @brief Gets the angle between my viewing direction and the direction to the position of the other object.
    88         @param myposition My position
    89         @param mydirection My viewing direction
    90         @param otherposition The position of the other object
    91         @return The angle
    92 
    93         @example
    94         If the other object is exactly in front of me, the function returns 0.
    95         If the other object is exactly behind me, the function returns pi.
    96         If the other object is exactly right/left to me (or above/below), the function returns pi/2.
    97     */
    98     float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition)
    99     {
    100         orxonox::Vector3 distance = otherposition - myposition;
    101         float distancelength = distance.length();
    102         if (distancelength == 0)
    103             return 0;
    104         else
    105             return acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1));
    106     }
    107 
    108     /**
    109         @brief Gets the 2D viewing direction (up/down, left/right) to the position of the other object.
    110         @param myposition My position
    111         @param mydirection My viewing direction
    112         @param myorthonormal My orthonormalvector (pointing upwards through my head)
    113         @param otherposition The position of the other object
    114         @return The viewing direction
    115 
    116         @example
    117         If the other object is exactly in front of me, the function returns Vector2(0, 0).
    118         If the other object is exactly at my left, the function returns Vector2(-1, 0).
    119         If the other object is exactly at my right, the function returns Vector2(1, 0).
    120         If the other object is only a bit at my right, the function still returns Vector2(1, 0).
    121         If the other object is exactly above me, the function returns Vector2(0, 1).
    122     */
    123     orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
    124     {
    125         orxonox::Vector3 distance = otherposition - myposition;
    126 
    127         // project difference vector on our plane
    128         orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
    129 
    130         float projectionlength = projection.length();
    131         if (projectionlength == 0)
    132         {
    133             if (myposition.dotProduct(otherposition) >= 0)
    134                 return orxonox::Vector2(0, 0);
    135             else
    136                 return orxonox::Vector2(0, 1);
    137         }
    138        
    139         float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
    140         float sin_value = sqrt( 1 - cos_value*cos_value );
    141        
    142         if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
    143             return orxonox::Vector2( sin_value, cos_value );
    144         else
    145             return orxonox::Vector2( -sin_value, cos_value );
    146     }
    147 
    148     /**
    149         @brief Gets the 2D viewing direction (up/down, left/right) to the position of the other object, multiplied with the viewing distance to the object (0° = 0, 180° = 1).
    150         @param myposition My position
    151         @param mydirection My viewing direction
    152         @param myorthonormal My orthonormalvector (pointing upwards through my head)
    153         @param otherposition The position of the other object
    154         @return The viewing direction
    155 
    156         @example
    157         If the other object is exactly in front of me, the function returns Vector2(0, 0).
    158         If the other object is exactly at my left, the function returns Vector2(-0.5, 0).
    159         If the other object is exactly at my right, the function returns Vector2(0.5, 0).
    160         If the other object is only a bit at my right, the function still returns Vector2(0.01, 0).
    161         If the other object is exactly above me, the function returns Vector2(0, 0.5).
    162     */
    163     orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
    164     {
    165         orxonox::Vector3 distance = otherposition - myposition;
    166 
    167         // project difference vector on our plane
    168         orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
    169 
    170         float projectionlength = projection.length();
    171         if (projectionlength == 0)
    172         {
    173             if (myposition.dotProduct(otherposition) >= 0)
    174                 return orxonox::Vector2(0, 0);
    175             else
    176                 return orxonox::Vector2(0, 1);
    177         }
    178         //float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
    179        
    180         float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
    181         float sin_value = sqrt( 1 - cos_value*cos_value );
    182 
    183         float distancelength = distance.length();
    184         if (distancelength == 0) return orxonox::Vector2(0, 0);
    185         float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / Ogre::Math::PI;
    186 
    187         if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
    188             return orxonox::Vector2( sin_value * radius, cos_value * radius);
    189         else
    190             return orxonox::Vector2( -sin_value * radius, cos_value * radius);
    191     }
    192 
    193     /**
    194         @brief Returns the predicted position I have to aim at, if I want to hit a moving target with a moving projectile.
    195         @param myposition My position
    196         @param projectilespeed The speed of my projectile
    197         @param targetposition The position of my target
    198         @param targetvelocity The velocity of my target
    199         @return The predicted position
    200 
    201         The function predicts the position based on a linear velocity of the target. If the target changes speed or direction, the projectile will miss.
    202     */
    203     orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity)
    204     {
    205         float squaredProjectilespeed = projectilespeed * projectilespeed;
    206         orxonox::Vector3 distance = targetposition - myposition;
    207         float a = distance.squaredLength();
    208         float b = 2 * (distance.x + distance.y + distance.z) * (targetvelocity.x + targetvelocity.y + targetvelocity.z);
    209         float c = targetvelocity.squaredLength();
    210 
    211         float temp = 4*squaredProjectilespeed*c + a*a - 4*b*c;
    212         if (temp < 0)
    213             return orxonox::Vector3::ZERO;
    214 
    215         temp = sqrt(temp);
    216         float time = (temp + a) / (2 * (squaredProjectilespeed - b));
    217         return (targetposition + targetvelocity * time);
    21879    }
    21980
  • sandbox_light/src/libraries/util/Math.h

    r5738 r5789  
    4040#include <cmath>
    4141
    42 #include <OgreMath.h>
    43 #include <OgreVector2.h>
    44 #include <OgreVector3.h>
    45 #include <OgreVector4.h>
    46 #include <OgreQuaternion.h>
    47 #include <OgreColourValue.h>
     42#include <ogremath/OgreMath.h>
     43#include <ogremath/OgreVector2.h>
     44#include <ogremath/OgreVector3.h>
     45#include <ogremath/OgreVector4.h>
     46#include <ogremath/OgreQuaternion.h>
     47#include <ogremath/OgreColourValue.h>
    4848
    4949// Certain headers might define unwanted macros...
     
    6363    _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);
    6464    _UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree);
    65 
    66     _UtilExport float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition);
    67     _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
    68     _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
    69     _UtilExport orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity);
    7065
    7166    /**
  • sandbox_light/src/libraries/util/MultiType.h

    r5738 r5789  
    7171#include <cassert>
    7272#include <string>
    73 #include <OgreVector2.h>
    74 #include <OgreVector3.h>
    75 #include <OgreVector4.h>
    76 #include <OgreQuaternion.h>
    77 #include <OgreColourValue.h>
     73#include <ogremath/OgreVector2.h>
     74#include <ogremath/OgreVector3.h>
     75#include <ogremath/OgreVector4.h>
     76#include <ogremath/OgreQuaternion.h>
     77#include <ogremath/OgreColourValue.h>
    7878
    7979#include "TypeTraits.h"
Note: See TracChangeset for help on using the changeset viewer.