mirror of https://github.com/OpenMW/openmw.git
Merge branch 'movement_refactoring' into 'master'
Refactoring related to "smooth movement" See merge request OpenMW/openmw!285 (cherry picked from commit 6eaf0a389d5aed3b74ab1a7cf89574612f964bdf) e847b4c8 Split getSpeed() to getMaxSpeed() and getCurrentSpeed() a96c46bc Refactor calculation of movement.mSpeedFactor 03ee9090 Use getMaxSpeed instead of getCurrentSpeed where it makes sense. a178af5c Create helper functions `normalizeAngle` and `rotateVec2f`pull/2995/head
parent
51bec5948f
commit
f90a049702
@ -0,0 +1,27 @@
|
||||
#ifndef MISC_MATHUTIL_H
|
||||
#define MISC_MATHUTIL_H
|
||||
|
||||
#include <osg/Math>
|
||||
#include <osg/Vec2f>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
|
||||
/// Normalizes given angle to the range [-PI, PI]. E.g. PI*3/2 -> -PI/2.
|
||||
inline double normalizeAngle(double angle)
|
||||
{
|
||||
double fullTurns = angle / (2 * osg::PI) + 0.5;
|
||||
return (fullTurns - floor(fullTurns) - 0.5) * (2 * osg::PI);
|
||||
}
|
||||
|
||||
/// Rotates given 2d vector counterclockwise. Angle is in radians.
|
||||
inline osg::Vec2f rotateVec2f(osg::Vec2f vec, float angle)
|
||||
{
|
||||
float s = std::sin(angle);
|
||||
float c = std::cos(angle);
|
||||
return osg::Vec2f(vec.x() * c + vec.y() * -s, vec.x() * s + vec.y() * c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue