ohsp

Prototype for a game with dual thruster controls.
git clone git://git.amin.space/ohsp.git
Log | Files | Refs | LICENSE

commit 3fed33a8a0f682c28fcba1c3788c03aefed6b933
parent 898cb12bb25b79536937b2db49d3469d3ba3203e
Author: amin <dev@aminmesbah.com>
Date:   Tue, 24 Oct 2017 05:03:58 +0000

Don't malloc when adding vectors

FossilOrigin-Name: 24824794187244532963720dcc19190f028441b79a755f31560a307f93c1dd48
Diffstat:
Msrc/entity.c | 12++++++++----
Msrc/entity.h | 4++++
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git 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 @@ -3,6 +3,10 @@ #include <stdint.h> +#ifndef M_PI +#define M_PI (3.14159265358979323846264338327950288) +#endif + struct Entity { float angle;