|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
float util::random(float range){
|
|
|
|
return float(rand())/RAND_MAX*range;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf2d util::pointTo(vf2d posFrom,vf2d posTo){
|
|
|
|
return geom2d::line(posFrom,posTo).vector().norm();
|
|
|
|
}
|
|
|
|
|
|
|
|
float util::angleTo(vf2d posFrom,vf2d posTo){
|
|
|
|
return geom2d::line<float>(posFrom,posTo).vector().polar().y;
|
|
|
|
}
|
|
|
|
|
|
|
|
float util::degToRad(float deg){
|
|
|
|
return deg*(PI/180);
|
|
|
|
}
|
|
|
|
|
|
|
|
float util::radToDeg(float rad){
|
|
|
|
return rad*57.2957795130823208767;
|
|
|
|
}
|
|
|
|
|
|
|
|
float util::lerp(float n1,float n2,double t){
|
|
|
|
return n1*(1-t)+n2*t;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string util::timerStr(float time){
|
|
|
|
int seconds=int(time);
|
|
|
|
int hours=seconds/3600;
|
|
|
|
int minutes=seconds/60;
|
|
|
|
|
|
|
|
std::string timeStr="";
|
|
|
|
if(hours>0){
|
|
|
|
if(hours<10)timeStr+="0";
|
|
|
|
timeStr+=std::to_string(hours)+":";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(minutes%60<10)timeStr+="0";
|
|
|
|
timeStr+=std::to_string(minutes%60)+":";
|
|
|
|
|
|
|
|
if(seconds%60<10)timeStr+="0";
|
|
|
|
timeStr+=std::to_string(seconds%60);
|
|
|
|
|
|
|
|
return timeStr;
|
|
|
|
}
|