farmlands/src/math/GameMath.h

47 lines
896 B
C++

/*
* Math.h
*
* Created on: Nov 26, 2016
* Author: tibi
*/
#ifndef MATH_GAMEMATH_H_
#define MATH_GAMEMATH_H_
#include <model/Direction.h>
#include <model/GameObject.h>
#define _USE_MATH_DEFINES
#include <cmath>
namespace farmlands {
void move(float* x, float* y, model::Direction direction, float distance);
void moveTowards(float *x, float *y, float towardsX, float towardsY, float speed);
float distanceSq(float x0, float y0, float x1, float y1);
bool checkCollision(model::GameObject* objA, model::GameObject* objB);
template<typename TVal, typename TMin, typename TMax>
TVal clamp (TVal value, TMin min, TMax max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}
/**
* Converts from degrees to radians
*/
inline float degToRad(float angle)
{
return angle * (float)M_PI / 360.0f;
}
}
#endif /* MATH_GAMEMATH_H_ */