summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-10-23 22:02:26 -0700
committerAmin Mesbah <mesbahamin@gmail.com>2017-10-23 22:03:58 -0700
commit0ee2f1c2c9939ddc83ee2f97126842e54c4622bc (patch)
tree9900bd677fe4f2219e0e8f80840dcd33676e6ddb /src
parentb751c775026e8333e5f423958ee52c896e5eae71 (diff)
downloadohsp-0ee2f1c2c9939ddc83ee2f97126842e54c4622bc.zip
ohsp-0ee2f1c2c9939ddc83ee2f97126842e54c4622bc.tar.gz
Don't malloc when adding vectors
Diffstat (limited to 'src')
-rw-r--r--src/entity.c12
-rw-r--r--src/entity.h4
2 files changed, 12 insertions, 4 deletions
diff --git a/src/entity.c b/src/entity.c
index 08ba3a9..dc99195 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -1,5 +1,8 @@
#include "entity.h"
+#include <math.h>
+#include <stdio.h>
+
struct Vec2d vec2d_add(float angle1, float length1, float angle2, float length2)
{
@@ -7,8 +10,8 @@ struct Vec2d vec2d_add(float angle1, float length1, float angle2, float length2)
float y = cosf(angle1) * length1 + cosf(angle2) * length2;
struct Vec2d new_vec;
- new_vec->angle = 0.5 * M_PI - atan2f(y, x);
- new_vec->length = hypotf(x, y);
+ new_vec.angle = 0.5 * M_PI - atan2f(y, x);
+ new_vec.length = hypotf(x, y);
return new_vec;
}
@@ -16,6 +19,7 @@ struct Vec2d vec2d_add(float angle1, float length1, float angle2, float length2)
void entity_accelerate(struct Entity *e, float angle, float acceleration)
{
struct Vec2d new_vec = vec2d_add(e->angle, e->speed, angle, acceleration);
- e->angle = new_vec->angle;
- e->speed = new_vec->length;
+ //printf("(%f, %f)\n", new_vec.angle, new_vec.length);
+ e->angle = new_vec.angle;
+ e->speed = new_vec.length;
}
diff --git a/src/entity.h b/src/entity.h
index 198fcd9..4136d90 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -3,6 +3,10 @@
#include <stdint.h>
+#ifndef M_PI
+#define M_PI (3.14159265358979323846264338327950288)
+#endif
+
struct Entity
{
float angle;