Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 5, 2008, 1:29:47 AM (16 years ago)
Author:
landauf
Message:

several changes:

  • XMLPort is now theoretically able to load something (but still buggy)
  • Expanded Convert with several partial template specializations
  • Expanded all MultiTypes with new functions, mostly to convert values
  • Expanded SubString with a new functionality: chars inside parentheses aren't split

It's not yet working as it should (at least not in all cases - loading the objects name works)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/util/MultiTypeMath.cc

    r797 r848  
    2828
    2929#include "MultiTypeMath.h"
     30#include "Convert.h"
    3031
    3132MultiTypeMath::MultiTypeMath(MultiType type) : MultiTypeString(type)
     
    100101}
    101102
     103MultiTypeMath::operator orxonox::Vector2() const
     104{
     105    return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Vector2>(*this);
     106}
     107
     108MultiTypeMath::operator orxonox::Vector3() const
     109{
     110    return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Vector3>(*this);
     111}
     112
     113MultiTypeMath::operator orxonox::Quaternion() const
     114{
     115    return (this->type_ == MT_quaternion) ? this->quaternion_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Quaternion>(*this);
     116}
     117
     118MultiTypeMath::operator orxonox::ColourValue() const
     119{
     120    return (this->type_ == MT_colourvalue) ? this->colourvalue_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::ColourValue>(*this);
     121}
     122
     123MultiTypeMath::operator orxonox::Radian() const
     124{
     125    return (this->type_ == MT_radian) ? this->radian_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Radian>(*this);
     126}
     127
     128MultiTypeMath::operator orxonox::Degree() const
     129{
     130    return (this->type_ == MT_degree) ? this->degree_ : ConvertValueAndReturn<MultiTypePrimitive, orxonox::Degree>(*this);
     131}
     132
    102133void MultiTypeMath::setValue(const MultiTypeMath& mtm)
    103134{
    104135    this->type_ = mtm.type_;
    105136    this->value_ = mtm.value_;
     137}
     138
     139std::string MultiTypeMath::toString() const
     140{
     141    std::string output;
     142
     143    if (this->type_ == MT_vector2)
     144        ConvertValue(&output, this->vector2_);
     145    else if (this->type_ == MT_vector3)
     146        ConvertValue(&output, this->vector3_);
     147    else if (this->type_ == MT_colourvalue)
     148        ConvertValue(&output, this->colourvalue_);
     149    else if (this->type_ == MT_quaternion)
     150        ConvertValue(&output, this->quaternion_);
     151    else if (this->type_ == MT_radian)
     152        ConvertValue(&output, this->radian_);
     153    else if (this->type_ == MT_degree)
     154        ConvertValue(&output, this->degree_);
     155    else
     156        return MultiTypeString::toString();
     157
     158    return output;
     159}
     160
     161bool MultiTypeMath::fromString(const std::string value)
     162{
     163    if (this->type_ == MT_vector2)
     164        return ConvertValue(&this->vector2_, value, orxonox::Vector2(0, 0));
     165    else if (this->type_ == MT_vector3)
     166        return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0));
     167    else if (this->type_ == MT_colourvalue)
     168        return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0));
     169    else if (this->type_ == MT_quaternion)
     170        return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0));
     171    else if (this->type_ == MT_radian)
     172        return ConvertValue(&this->radian_, value, orxonox::Radian(0));
     173    else if (this->type_ == MT_degree)
     174        return ConvertValue(&this->degree_, value, orxonox::Degree(0));
     175    else
     176        return MultiTypeString::fromString(value);
    106177}
    107178
Note: See TracChangeset for help on using the changeset viewer.