Commit 3f1285ba authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Remove some hardcoded values

parent 24c64084
......@@ -21,6 +21,7 @@
#define Y_CHARGE_2 0.5
#define NB_OF_LINES 100
#define NB_OF_CHARGES 3
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
......@@ -58,14 +59,17 @@ int main()
}
// ! INIT CHARGES
charge_t *charges = malloc(2 * sizeof(*charges));
charge_t *charges = malloc(NB_OF_CHARGES * sizeof(*charges));
charges[0].pos = (vec2){X_CHARGE_1, Y_CHARGE_1};
charges[0].q = 1.6E-19;
charges[1].pos = (vec2){X_CHARGE_2, Y_CHARGE_2};
charges[1].q = 1.6E-19;
charges[2].pos = (vec2){X_CHARGE_2, Y_CHARGE_2};
charges[2].q = 1.6E-19;
// ! INIT LISTE DE POINTS
// Fait de cette manière pour le live update
vec2 *lines = malloc(NB_OF_LINES * sizeof(*lines));
for (int i = 0; i < NB_OF_LINES; i++)
{
......@@ -106,11 +110,10 @@ int main()
{
SDL_GetMouseState(&mouse_x, &mouse_y);
if (event.button.button == SDL_BUTTON_RIGHT)
{
choosen_part = -1;
for (int i = 0; i < 2; i++)
for (int i = 0; i < NB_OF_CHARGES; i++)
{
coordinates_t c = vec2_to_coordinates(charges[i].pos, WIDTH, HEIGHT);
......@@ -126,7 +129,7 @@ int main()
{
choosen_part = -1;
// ! HARDCODED VALUE
for (int i = 0; i < 2; i++)
for (int i = 0; i < NB_OF_CHARGES; i++)
{
coordinates_t c = vec2_to_coordinates(charges[i].pos, WIDTH, HEIGHT);
......@@ -157,13 +160,13 @@ int main()
case LIGNES:
GFX_ClearScreen(renderer, COLOR_BLACK);
draw_lines(renderer, charges, lines, NB_OF_LINES);
draw_charges(renderer, charges, 2, 10);
draw_charges(renderer, charges, NB_OF_CHARGES, 10);
SDL_RenderPresent(renderer);
state = IDLE;
break;
case HEATMAP:
draw_heatmap(renderer, charges);
draw_charges(renderer, charges, 2, 10);
draw_charges(renderer, charges, NB_OF_CHARGES, 10);
SDL_RenderPresent(renderer);
state = IDLE;
break;
......@@ -173,7 +176,7 @@ int main()
charges[choosen_part].pos.y = (double)mouse_y / HEIGHT;
GFX_ClearScreen(renderer, COLOR_BLACK);
draw_lines(renderer, charges, lines, NB_OF_LINES);
draw_charges(renderer, charges, 2, 10);
draw_charges(renderer, charges, NB_OF_CHARGES, 10);
SDL_RenderPresent(renderer);
break;
}
......@@ -221,7 +224,7 @@ void draw_heatmap(SDL_Renderer* renderer, charge_t* charges)
{
vec2 e = {.x = 0, .y = 0};
vec2 p = {.x = (double)(x) / (double)(WIDTH), .y = (double)(y) / (double)(HEIGHT)};
if (compute_total_normalized_e(charges, 2, p, 0.05, &e))
if (compute_total_normalized_e(charges, NB_OF_CHARGES, p, 0.05, &e))
{
e = vec2_mul(1E9, e);
double tmp = vec2_norm(e);
......@@ -268,7 +271,7 @@ void draw_lines(SDL_Renderer* renderer, charge_t* charges, vec2* lines, int nb_o
while (rendering)
{
vec2 e = {.x = 0, .y = 0};
if (compute_total_normalized_e(charges, 2, p, 0.025, &e) == false)
if (compute_total_normalized_e(charges, NB_OF_CHARGES, p, 0.025, &e) == false)
{
side++;
p = og_p;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment