Changeset 1745 for code/branches/core3/src/util/Math.cc
- Timestamp:
- Sep 8, 2008, 11:17:20 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/util/Math.cc
r1566 r1745 30 30 31 31 #include "Math.h" 32 #include "Convert.h" 32 33 33 34 /** … … 123 124 return (targetposition + targetvelocity * time); 124 125 } 126 127 // std::string to Vector2 128 bool explicitConversion(orxonox::Vector2* output, const std::string& input) 129 { 130 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 131 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 132 133 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 134 if (tokens.size() >= 2) 135 { 136 if (!ConvertValue(&(output->x), tokens[0])) 137 return false; 138 if (!ConvertValue(&(output->y), tokens[1])) 139 return false; 140 141 return true; 142 } 143 return false; 144 } 145 146 // std::string to Vector3 147 bool explicitConversion(orxonox::Vector3* output, const std::string& input) 148 { 149 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 150 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 151 152 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 153 if (tokens.size() >= 3) 154 { 155 if (!ConvertValue(&(output->x), tokens[0])) 156 return false; 157 if (!ConvertValue(&(output->y), tokens[1])) 158 return false; 159 if (!ConvertValue(&(output->z), tokens[2])) 160 return false; 161 162 return true; 163 } 164 return false; 165 } 166 167 // std::string to Vector4 168 bool explicitConversion(orxonox::Vector4* output, const std::string& input) 169 { 170 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 171 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 172 173 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 174 if (tokens.size() >= 4) 175 { 176 if (!ConvertValue(&(output->x), tokens[0])) 177 return false; 178 if (!ConvertValue(&(output->y), tokens[1])) 179 return false; 180 if (!ConvertValue(&(output->z), tokens[2])) 181 return false; 182 if (!ConvertValue(&(output->w), tokens[3])) 183 return false; 184 185 return true; 186 } 187 return false; 188 } 189 190 // std::string to Quaternion 191 bool explicitConversion(orxonox::Quaternion* output, const std::string& input) 192 { 193 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 194 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 195 196 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 197 if (tokens.size() >= 4) 198 { 199 if (!ConvertValue(&(output->w), tokens[0])) 200 return false; 201 if (!ConvertValue(&(output->x), tokens[1])) 202 return false; 203 if (!ConvertValue(&(output->y), tokens[2])) 204 return false; 205 if (!ConvertValue(&(output->z), tokens[3])) 206 return false; 207 208 return true; 209 } 210 return false; 211 } 212 213 // std::string to ColourValue 214 bool explicitConversion(orxonox::ColourValue* output, const std::string& input) 215 { 216 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 217 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 218 219 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 220 if (tokens.size() >= 4) 221 { 222 if (!ConvertValue(&(output->r), tokens[0])) 223 return false; 224 if (!ConvertValue(&(output->g), tokens[1])) 225 return false; 226 if (!ConvertValue(&(output->b), tokens[2])) 227 return false; 228 if (!ConvertValue(&(output->a), tokens[3])) 229 return false; 230 231 return true; 232 } 233 return false; 234 }
Note: See TracChangeset
for help on using the changeset viewer.