forked from raydelto/GeometryWars
/
MathUtil.cpp
31 lines (26 loc) · 1.43 KB
/
MathUtil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "Utility/package.hpp"
#include "MathUtil.hpp"
//---------------------------------------------------------------------------------
// Written by Terence J. Grant - tjgrant [at] tatewake [dot] com
// Find the full tutorial at: http://gamedev.tutsplus.com/series/
//----------------------------------------------------------------------------------
tVector2f MathUtil::fromPolar(float angle, float magnitude)
{
return tVector2f((float)cosf(angle), (float)sinf(angle)) * magnitude;
}
float MathUtil::catmullRom(const float value1, const float value2, const float value3, const float value4, float amount)
{
// Using formula from http://www.mvps.org/directx/articles/catmull/
// Internally using doubles not to lose precission
float amountSquared = amount * amount;
float amountCubed = amountSquared * amount;
return (float)(0.5f * (2.0f * value2 +
(value3 - value1) * amount +
(2.0f * value1 - 5.0f * value2 + 4.0f * value3 - value4) * amountSquared +
(3.0f * value2 - value1 - 3.0f * value3 + value4) * amountCubed));
}
tVector2f MathUtil::catmullRom(const tVector2f& value1, const tVector2f& value2, const tVector2f& value3, const tVector2f& value4, float amount)
{
return tVector2f(MathUtil::catmullRom(value1.x, value2.x, value3.x, value4.x, amount),
MathUtil::catmullRom(value1.y, value2.y, value3.y, value4.y, amount));
}