Code: Select all
//! GetVector3dfFromStr
/*!
This is a internal function that takes a string and converts it
into a vector3df.
\param val is the string to turn into a vector3df
\warning this function only takes strings formated as follows
value,value,value it will not take anything but that format.
*/
irr::core::vector3df GetVector3dfFromStr(std::string val)
{
irr::core::vector3df vec;
std::string temp;
std::istringstream temp2;
std::istringstream temp3;
std::istringstream temp4;
size_t found;
size_t found2;
//First we find the first instance of ',' in the given string
found = val.find(",");
//Then we cut the given string from the beginning up to the first instance of ','
temp = val.substr(0,found);
//Then we put the newly cut string into a istream
temp2.str(temp);
//Then we convert the istream to a float and place it in our vector as X
temp2 >> vec.X;
//Now we cut from the first instance of ',' on down
temp = val.substr(found+1);
//Now we find the first instance of ',' in our newly cut string
found2 = temp.find(",");
//Now we substring up to the first instance of ','
temp = temp.substr(0,found2);
//Then we turn the cut string into a istream
temp3.str(temp);
//Then we covert it into a float and place it in our vector as Y
temp3 >> vec.Y;
//Now we find the second instance of ',' in our val string
found2 = val.find(",",found+1);
//Then we cut the string from the last instnace till the
//end of the string
temp = val.substr(found2 + 1);
//Then we turn the cut string into a istream
temp4.str(temp);
//Then we convert it into a float and place it in our vector as Z
temp4 >> vec.Z;
//Finally we return the cut vector.
return vec;
}
//Example usage:
//std::string test = "2.0,4.55550,-32432.00";
//irr::core::vector3df ourvec;
//ourvec = GetVector3dfFromStr(test);
//Thats it.