Added AVR support
This commit is contained in:
parent
493a3f7489
commit
006ea046e4
@ -3,10 +3,15 @@
|
||||
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "Vector2.h"
|
||||
#include <math.h>
|
||||
#include "Angle.h"
|
||||
#include "FloatSingle.h"
|
||||
|
||||
#if defined(AVR)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
Vector2::Vector2() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
@ -111,7 +116,11 @@ float Vector2::SignedAngle(Vector2 from, Vector2 to) {
|
||||
if (sqrMagFrom == 0 || sqrMagTo == 0)
|
||||
return 0;
|
||||
if (!isfinite(sqrMagFrom) || !isfinite(sqrMagTo))
|
||||
#if defined(AVR)
|
||||
return NAN;
|
||||
#else
|
||||
return nanf("");
|
||||
#endif
|
||||
|
||||
float angleFrom = atan2(from.y, from.x);
|
||||
float angleTo = atan2(to.y, to.x);
|
||||
@ -119,13 +128,18 @@ float Vector2::SignedAngle(Vector2 from, Vector2 to) {
|
||||
}
|
||||
|
||||
Vector2 Vector2::Rotate(Vector2 v, float angle) {
|
||||
float sin = (float)sinf(angle * Angle::Deg2Rad);
|
||||
float cos = (float)cosf(angle * Angle::Deg2Rad);
|
||||
#if defined(AVR)
|
||||
float sinValue = sin(angle * Angle::Deg2Rad);
|
||||
float cosValue = cos(angle * Angle::Deg2Rad);
|
||||
#else
|
||||
float sinValue = (float)sinf(angle * Angle::Deg2Rad);
|
||||
float cosValue = (float)cosf(angle * Angle::Deg2Rad);
|
||||
#endif
|
||||
|
||||
float tx = v.x;
|
||||
float ty = v.y;
|
||||
v.x = (cos * tx) - (sin * ty);
|
||||
v.y = (sin * tx) + (cos * ty);
|
||||
v.x = (cosValue * tx) - (sinValue * ty);
|
||||
v.y = (sinValue * tx) + (cosValue * ty);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user