Skip to content
Snippets Groups Projects
Commit d7b34e78 authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

save

parent 5d3d4b0b
Branches
Tags v1.0.4
No related merge requests found
...@@ -7,6 +7,9 @@ TESTS:= draw_tests field_tests ...@@ -7,6 +7,9 @@ TESTS:= draw_tests field_tests
all: main all: main
exec: main
./main
main: main.o $(OBJFILES) main: main.o $(OBJFILES)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lSDL2 $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lSDL2
......
...@@ -41,11 +41,7 @@ bool is_in_screen(coordinates_t pos) { ...@@ -41,11 +41,7 @@ bool is_in_screen(coordinates_t pos) {
bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1, vec2 pos, vec2 *pos_next, double delta) { bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1, vec2 pos, vec2 *pos_next, double delta) {
vec2 e; vec2 e;
compute_total_normalized_e(charges, num_charges, pos, 0.01, &e); compute_total_normalized_e(charges, num_charges, pos, 0.01, &e);
double norm_e = vec2_norm(e); *pos_next = vec2_add(pos, vec2_mul(delta, vec2_normalize(e)));
// TODO: "Problème ici" ?
pos_next->x = pos.x + delta * (e.x / norm_e);
pos_next->y = pos.y + delta * (e.y / norm_e);
if (pos_next->x <= 0 || pos_next->x >= 1 || pos_next->y <= 0 || pos_next->y >= 1) if (pos_next->x <= 0 || pos_next->x >= 1 || pos_next->y <= 0 || pos_next->y >= 1)
return false; return false;
...@@ -61,6 +57,7 @@ bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int nu ...@@ -61,6 +57,7 @@ bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int nu
return !is_in_screen(coordinate_pos); return !is_in_screen(coordinate_pos);
} }
bool line_reach_charge(vec2 pos, charge_t *charges, int num_charges, double dx) { bool line_reach_charge(vec2 pos, charge_t *charges, int num_charges, double dx) {
for (int j = 0; j < num_charges; ++j) { for (int j = 0; j < num_charges; ++j) {
if (vec2_norm(vec2_sub(pos, charges[j].pos)) < dx / HEI) { if (vec2_norm(vec2_sub(pos, charges[j].pos)) < dx / HEI) {
...@@ -103,6 +100,7 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n ...@@ -103,6 +100,7 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n
return !stop_positive || !stop_negative; return !stop_positive || !stop_negative;
} }
/// Draw all the charges /// Draw all the charges
/// A circle with minus sign for negative charges /// A circle with minus sign for negative charges
/// A circle with a plus sign for positive charges /// A circle with a plus sign for positive charges
...@@ -129,6 +127,7 @@ static void draw_charges(struct gfx_context_t *context, charge_t *charges, int n ...@@ -129,6 +127,7 @@ static void draw_charges(struct gfx_context_t *context, charge_t *charges, int n
} }
} }
void draw_everything( void draw_everything(
struct gfx_context_t *ctxt, struct gfx_context_t *ctxt,
charge_t *charges, charge_t *charges,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment