[792] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[792] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | * Inspiration: MultiType by Benjamin Grauer |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef _MultiTypeMath_H__ |
---|
| 31 | #define _MultiTypeMath_H__ |
---|
| 32 | |
---|
| 33 | #include "UtilPrereqs.h" |
---|
| 34 | |
---|
| 35 | #include "MultiTypeString.h" |
---|
| 36 | #include "Math.h" |
---|
| 37 | |
---|
[1064] | 38 | // disable annoying warning about multiple assignment operators |
---|
| 39 | #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC |
---|
| 40 | #pragma warning(push) |
---|
| 41 | #pragma warning(disable:4522) |
---|
| 42 | #endif |
---|
| 43 | |
---|
[792] | 44 | class _UtilExport MultiTypeMath : public MultiTypeString |
---|
| 45 | { |
---|
| 46 | public: |
---|
[1052] | 47 | MultiTypeMath(MultiType type = MT_null); |
---|
| 48 | inline MultiTypeMath(void* value) : MultiTypeString(value) {} |
---|
[794] | 49 | inline MultiTypeMath(int value) : MultiTypeString(value) {} |
---|
| 50 | inline MultiTypeMath(unsigned int value) : MultiTypeString(value) {} |
---|
| 51 | inline MultiTypeMath(char value) : MultiTypeString(value) {} |
---|
| 52 | inline MultiTypeMath(unsigned char value) : MultiTypeString(value) {} |
---|
| 53 | inline MultiTypeMath(short value) : MultiTypeString(value) {} |
---|
| 54 | inline MultiTypeMath(unsigned short value) : MultiTypeString(value) {} |
---|
| 55 | inline MultiTypeMath(long value) : MultiTypeString(value) {} |
---|
| 56 | inline MultiTypeMath(unsigned long value) : MultiTypeString(value) {} |
---|
| 57 | inline MultiTypeMath(float value) : MultiTypeString(value) {} |
---|
| 58 | inline MultiTypeMath(double value) : MultiTypeString(value) {} |
---|
| 59 | inline MultiTypeMath(long double value) : MultiTypeString(value) {} |
---|
| 60 | inline MultiTypeMath(bool value) : MultiTypeString(value) {} |
---|
[1052] | 61 | inline MultiTypeMath(const char* value) : MultiTypeString(value) {} |
---|
| 62 | inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {} |
---|
[794] | 63 | inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } |
---|
| 64 | inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } |
---|
[1502] | 65 | inline MultiTypeMath(const orxonox::Vector4& value) { this->setValue(value); } |
---|
[794] | 66 | inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); } |
---|
| 67 | inline MultiTypeMath(const orxonox::Quaternion& value) { this->setValue(value); } |
---|
| 68 | inline MultiTypeMath(const orxonox::Radian& value) { this->setValue(value); } |
---|
| 69 | inline MultiTypeMath(const orxonox::Degree& value) { this->setValue(value); } |
---|
[853] | 70 | inline MultiTypeMath(const MultiTypeMath& mtm) { this->setValue(mtm); } |
---|
[1502] | 71 | inline MultiTypeMath(const MultiTypeString& mts) { this->setValue(mts); } |
---|
| 72 | inline MultiTypeMath(const MultiTypePrimitive& mtp) { this->setValue(mtp); } |
---|
[869] | 73 | virtual inline ~MultiTypeMath() {} |
---|
[792] | 74 | |
---|
[794] | 75 | using MultiTypeString::operator=; |
---|
| 76 | inline MultiTypeMath& operator=(const orxonox::Vector2& value) { this->setValue(value); return *this; } |
---|
| 77 | inline MultiTypeMath& operator=(const orxonox::Vector3& value) { this->setValue(value); return *this; } |
---|
[1502] | 78 | inline MultiTypeMath& operator=(const orxonox::Vector4& value) { this->setValue(value); return *this; } |
---|
[794] | 79 | inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; } |
---|
| 80 | inline MultiTypeMath& operator=(const orxonox::Quaternion& value) { this->setValue(value); return *this; } |
---|
| 81 | inline MultiTypeMath& operator=(const orxonox::Radian& value) { this->setValue(value); return *this; } |
---|
| 82 | inline MultiTypeMath& operator=(const orxonox::Degree& value) { this->setValue(value); return *this; } |
---|
[853] | 83 | inline MultiTypeMath& operator=(const MultiTypeMath& mtm) { this->setValue(mtm); return *this; } |
---|
[1502] | 84 | inline MultiTypeMath& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } |
---|
| 85 | inline MultiTypeMath& operator=(const MultiTypePrimitive mtp) { this->setValue(mtp); return *this; } |
---|
[792] | 86 | |
---|
[794] | 87 | using MultiTypeString::operator==; |
---|
| 88 | inline bool operator==(const orxonox::Vector2& value) const { return (this->vector2_ == value); } |
---|
| 89 | inline bool operator==(const orxonox::Vector3& value) const { return (this->vector3_ == value); } |
---|
[1502] | 90 | inline bool operator==(const orxonox::Vector4& value) const { return (this->vector4_ == value); } |
---|
[794] | 91 | inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); } |
---|
| 92 | inline bool operator==(const orxonox::Quaternion& value) const { return (this->quaternion_ == value); } |
---|
| 93 | inline bool operator==(const orxonox::Radian& value) const { return (this->radian_ == value); } |
---|
| 94 | inline bool operator==(const orxonox::Degree& value) const { return (this->degree_ == value); } |
---|
[792] | 95 | bool operator==(const MultiTypeMath& mtm) const; |
---|
[1502] | 96 | bool operator==(const MultiTypeString& mts) const; |
---|
| 97 | bool operator==(const MultiTypePrimitive& mtp) const; |
---|
[792] | 98 | |
---|
[794] | 99 | using MultiTypeString::operator!=; |
---|
| 100 | inline bool operator!=(const orxonox::Vector2& value) const { return (this->vector2_ != value); } |
---|
| 101 | inline bool operator!=(const orxonox::Vector3& value) const { return (this->vector3_ != value); } |
---|
[1502] | 102 | inline bool operator!=(const orxonox::Vector4& value) const { return (this->vector4_ != value); } |
---|
[794] | 103 | inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); } |
---|
| 104 | inline bool operator!=(const orxonox::Quaternion& value) const { return (this->quaternion_ != value); } |
---|
| 105 | inline bool operator!=(const orxonox::Radian& value) const { return (this->radian_ != value); } |
---|
| 106 | inline bool operator!=(const orxonox::Degree& value) const { return (this->degree_ != value); } |
---|
[792] | 107 | bool operator!=(const MultiTypeMath& mtm) const; |
---|
[1502] | 108 | bool operator!=(const MultiTypeString& mts) const; |
---|
| 109 | bool operator!=(const MultiTypePrimitive& mtp) const; |
---|
[792] | 110 | |
---|
[1052] | 111 | virtual operator void*() const; |
---|
[869] | 112 | virtual operator int() const; |
---|
| 113 | virtual operator unsigned int() const; |
---|
| 114 | virtual operator char() const; |
---|
| 115 | virtual operator unsigned char() const; |
---|
| 116 | virtual operator short() const; |
---|
| 117 | virtual operator unsigned short() const; |
---|
| 118 | virtual operator long() const; |
---|
| 119 | virtual operator unsigned long() const; |
---|
| 120 | virtual operator float () const; |
---|
| 121 | virtual operator double () const; |
---|
| 122 | virtual operator long double() const; |
---|
| 123 | virtual operator bool() const; |
---|
| 124 | virtual operator std::string() const; |
---|
| 125 | virtual operator const char*() const; |
---|
| 126 | virtual operator orxonox::Vector2() const; |
---|
| 127 | virtual operator orxonox::Vector3() const; |
---|
[1502] | 128 | virtual operator orxonox::Vector4() const; |
---|
[869] | 129 | virtual operator orxonox::ColourValue() const; |
---|
| 130 | virtual operator orxonox::Quaternion() const; |
---|
| 131 | virtual operator orxonox::Radian() const; |
---|
| 132 | virtual operator orxonox::Degree() const; |
---|
[834] | 133 | |
---|
[794] | 134 | using MultiTypeString::setValue; |
---|
[792] | 135 | inline void setValue(const orxonox::Vector2& value) { this->type_ = MT_vector2; this->vector2_ = value; } |
---|
[854] | 136 | inline void setValue(const orxonox::Vector3& value) { this->type_ = MT_vector3; this->vector3_ = value; } |
---|
[1502] | 137 | inline void setValue(const orxonox::Vector4& value) { this->type_ = MT_vector4; this->vector4_ = value; } |
---|
[792] | 138 | inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; } |
---|
| 139 | inline void setValue(const orxonox::Quaternion& value) { this->type_ = MT_quaternion; this->quaternion_ = value; } |
---|
| 140 | inline void setValue(const orxonox::Radian& value) { this->type_ = MT_radian; this->radian_ = value; } |
---|
| 141 | inline void setValue(const orxonox::Degree& value) { this->type_ = MT_degree; this->degree_ = value; } |
---|
| 142 | void setValue(const MultiTypeMath& mtm); |
---|
[1502] | 143 | void setValue(const MultiTypeString& mts); |
---|
| 144 | void setValue(const MultiTypePrimitive& mtp); |
---|
[792] | 145 | |
---|
[848] | 146 | inline orxonox::Vector2 getVector2() const { return this->vector2_; } |
---|
| 147 | inline orxonox::Vector3 getVector3() const { return this->vector3_; } |
---|
[1502] | 148 | inline orxonox::Vector4 getVector4() const { return this->vector4_; } |
---|
[848] | 149 | inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; } |
---|
| 150 | inline orxonox::Quaternion getQuaternion() const { return this->quaternion_; } |
---|
| 151 | inline orxonox::Radian getRadian() const { return this->radian_; } |
---|
| 152 | inline orxonox::Degree getDegree() const { return this->degree_; } |
---|
| 153 | |
---|
[792] | 154 | inline orxonox::Vector2& getVector2() { return this->vector2_; } |
---|
| 155 | inline orxonox::Vector3& getVector3() { return this->vector3_; } |
---|
[1502] | 156 | inline orxonox::Vector4& getVector4() { return this->vector4_; } |
---|
[792] | 157 | inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; } |
---|
| 158 | inline orxonox::Quaternion& getQuaternion() { return this->quaternion_; } |
---|
| 159 | inline orxonox::Radian& getRadian() { return this->radian_; } |
---|
| 160 | inline orxonox::Degree& getDegree() { return this->degree_; } |
---|
| 161 | |
---|
[794] | 162 | using MultiTypeString::getValue; |
---|
[792] | 163 | inline void getValue(orxonox::Vector2* variable) const { (*variable) = orxonox::Vector2 (this->vector2_); } |
---|
| 164 | inline void getValue(orxonox::Vector3* variable) const { (*variable) = orxonox::Vector3 (this->vector3_); } |
---|
[1502] | 165 | inline void getValue(orxonox::Vector4* variable) const { (*variable) = orxonox::Vector4 (this->vector4_); } |
---|
[792] | 166 | inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); } |
---|
| 167 | inline void getValue(orxonox::Quaternion* variable) const { (*variable) = orxonox::Quaternion (this->quaternion_); } |
---|
| 168 | inline void getValue(orxonox::Radian* variable) const { (*variable) = orxonox::Radian (this->radian_); } |
---|
| 169 | inline void getValue(orxonox::Degree* variable) const { (*variable) = orxonox::Degree (this->degree_); } |
---|
| 170 | |
---|
[1052] | 171 | virtual std::string getTypename() const; |
---|
| 172 | |
---|
[869] | 173 | virtual std::string toString() const; |
---|
| 174 | virtual bool fromString(const std::string value); |
---|
[848] | 175 | |
---|
[1502] | 176 | virtual bool assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue = MultiTypeMath()); |
---|
| 177 | |
---|
[792] | 178 | protected: |
---|
| 179 | orxonox::Vector2 vector2_; |
---|
| 180 | orxonox::Vector3 vector3_; |
---|
[1502] | 181 | orxonox::Vector4 vector4_; |
---|
[792] | 182 | orxonox::ColourValue colourvalue_; |
---|
| 183 | orxonox::Quaternion quaternion_; |
---|
| 184 | orxonox::Radian radian_; |
---|
| 185 | orxonox::Degree degree_; |
---|
| 186 | }; |
---|
| 187 | |
---|
[890] | 188 | _UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm); |
---|
[797] | 189 | |
---|
[1064] | 190 | #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC |
---|
| 191 | #pragma warning(pop) |
---|
| 192 | #endif |
---|
| 193 | |
---|
[792] | 194 | #endif /* _MultiTypeMath_H__ */ |
---|