Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (16 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/util

  • code/trunk/src/util/Math.cc

    r1791 r2087  
    2828
    2929/**
    30     @file Math.cc
     30    @file
    3131    @brief Implementation of several math-functions.
    3232*/
    3333
     34#include "Math.h"
     35
    3436#include <OgrePlane.h>
    35 
    36 #include "Math.h"
    37 #include "Convert.h"
     37#include "MathConvert.h"
     38#include "SubString.h"
    3839
    3940/**
     
    201202}
    202203
    203 std::string getUniqueNumberStr()
    204 {
    205     return convertToString(getUniqueNumber());
    206 }
     204
     205//////////////////////////
     206// Conversion functions //
     207//////////////////////////
     208
     209// std::string to Vector2
     210bool ConverterFallback<std::string, orxonox::Vector2>::convert(orxonox::Vector2* output, const std::string& input)
     211{
     212    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     213    if ((opening_parenthesis = input.find('(')) == std::string::npos)
     214        opening_parenthesis = 0;
     215    else
     216        opening_parenthesis++;
     217
     218    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis),
     219                     ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     220    if (tokens.size() >= 2)
     221    {
     222        if (!ConvertValue(&(output->x), tokens[0]))
     223            return false;
     224        if (!ConvertValue(&(output->y), tokens[1]))
     225            return false;
     226
     227        return true;
     228    }
     229    return false;
     230}
     231
     232// std::string to Vector3
     233bool ConverterFallback<std::string, orxonox::Vector3>::convert(orxonox::Vector3* output, const std::string& input)
     234{
     235    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     236    if ((opening_parenthesis = input.find('(')) == std::string::npos)
     237        opening_parenthesis = 0;
     238    else
     239        opening_parenthesis++;
     240
     241    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis),
     242                     ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     243    if (tokens.size() >= 3)
     244    {
     245        if (!ConvertValue(&(output->x), tokens[0]))
     246            return false;
     247        if (!ConvertValue(&(output->y), tokens[1]))
     248            return false;
     249        if (!ConvertValue(&(output->z), tokens[2]))
     250            return false;
     251
     252        return true;
     253    }
     254    return false;
     255}
     256
     257// std::string to Vector4
     258bool ConverterFallback<std::string, orxonox::Vector4>::convert(orxonox::Vector4* output, const std::string& input)
     259{
     260    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     261    if ((opening_parenthesis = input.find('(')) == std::string::npos)
     262        opening_parenthesis = 0;
     263    else
     264        opening_parenthesis++;
     265
     266    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis),
     267                     ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     268    if (tokens.size() >= 4)
     269    {
     270        if (!ConvertValue(&(output->x), tokens[0]))
     271            return false;
     272        if (!ConvertValue(&(output->y), tokens[1]))
     273            return false;
     274        if (!ConvertValue(&(output->z), tokens[2]))
     275            return false;
     276        if (!ConvertValue(&(output->w), tokens[3]))
     277            return false;
     278
     279        return true;
     280    }
     281    return false;
     282}
     283
     284// std::string to Quaternion
     285bool ConverterFallback<std::string, orxonox::Quaternion>::convert(orxonox::Quaternion* output, const std::string& input)
     286{
     287    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     288    if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     289
     290    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     291    if (tokens.size() >= 4)
     292    {
     293        if (!ConvertValue(&(output->w), tokens[0]))
     294            return false;
     295        if (!ConvertValue(&(output->x), tokens[1]))
     296            return false;
     297        if (!ConvertValue(&(output->y), tokens[2]))
     298            return false;
     299        if (!ConvertValue(&(output->z), tokens[3]))
     300            return false;
     301
     302        return true;
     303    }
     304    return false;
     305}
     306
     307// std::string to ColourValue
     308bool ConverterFallback<std::string, orxonox::ColourValue>::convert(orxonox::ColourValue* output, const std::string& input)
     309{
     310    size_t opening_parenthesis, closing_parenthesis = input.find(')');
     311    if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     312
     313    SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     314    if (tokens.size() >= 3)
     315    {
     316        if (!ConvertValue(&(output->r), tokens[0]))
     317            return false;
     318        if (!ConvertValue(&(output->g), tokens[1]))
     319            return false;
     320        if (!ConvertValue(&(output->b), tokens[2]))
     321            return false;
     322        if (tokens.size() >= 4)
     323        {
     324            if (!ConvertValue(&(output->a), tokens[3]))
     325                return false;
     326        }
     327        else
     328            output->a = 1.0;
     329
     330        return true;
     331    }
     332    return false;
     333}
Note: See TracChangeset for help on using the changeset viewer.