2014-03-15 22:06:16 +00:00
|
|
|
#include "Util.h"
|
2014-05-23 22:21:01 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2014-05-23 23:38:31 +00:00
|
|
|
#include "resources/ResourceManager.h"
|
2014-03-15 22:06:16 +00:00
|
|
|
|
|
|
|
std::string strToUpper(const char* from)
|
|
|
|
{
|
|
|
|
std::string str(from);
|
|
|
|
for(unsigned int i = 0; i < str.size(); i++)
|
|
|
|
str[i] = toupper(from[i]);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string& strToUpper(std::string& str)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < str.size(); i++)
|
|
|
|
str[i] = toupper(str[i]);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string strToUpper(const std::string& str)
|
|
|
|
{
|
|
|
|
return strToUpper(str.c_str());
|
2014-03-19 20:03:23 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 21:51:24 +00:00
|
|
|
|
|
|
|
#if _MSC_VER < 1800
|
2014-03-19 20:03:23 +00:00
|
|
|
float round(float num)
|
|
|
|
{
|
|
|
|
return (float)((int)(num + 0.5f));
|
|
|
|
}
|
2014-05-23 21:51:24 +00:00
|
|
|
#endif
|
2014-03-19 20:03:23 +00:00
|
|
|
|
|
|
|
Eigen::Affine3f& roundMatrix(Eigen::Affine3f& mat)
|
|
|
|
{
|
|
|
|
mat.translation()[0] = round(mat.translation()[0]);
|
|
|
|
mat.translation()[1] = round(mat.translation()[1]);
|
|
|
|
return mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eigen::Affine3f roundMatrix(const Eigen::Affine3f& mat)
|
|
|
|
{
|
|
|
|
Eigen::Affine3f ret = mat;
|
|
|
|
roundMatrix(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eigen::Vector3f roundVector(const Eigen::Vector3f& vec)
|
|
|
|
{
|
|
|
|
Eigen::Vector3f ret = vec;
|
|
|
|
ret[0] = round(ret[0]);
|
|
|
|
ret[1] = round(ret[1]);
|
|
|
|
ret[2] = round(ret[2]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eigen::Vector2f roundVector(const Eigen::Vector2f& vec)
|
|
|
|
{
|
|
|
|
Eigen::Vector2f ret = vec;
|
|
|
|
ret[0] = round(ret[0]);
|
|
|
|
ret[1] = round(ret[1]);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-05-23 22:21:01 +00:00
|
|
|
|
|
|
|
std::string getCanonicalPath(const std::string& path)
|
|
|
|
{
|
2014-05-23 23:38:31 +00:00
|
|
|
// embedded resources, e.g. ":/font.ttf", need to be properly handled too
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const std::string canonical = boost::filesystem::canonical(path).generic_string();
|
|
|
|
return canonical.empty() ? path : canonical;
|
|
|
|
}
|
|
|
|
catch (boost::filesystem::filesystem_error& e)
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
2014-05-23 22:21:01 +00:00
|
|
|
}
|