Commit da224dfe authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Tried some stuff, doesnt seem to work

parent 2ac010ee
......@@ -11,6 +11,7 @@
#include <stdint.h>
#include <SDL2/SDL.h>
#include <math.h>
#include "vec2.h"
#define MAKE_COLOR(r,g,b) ((uint32_t)b|((uint32_t)g<<8)|((uint32_t)r<<16))
......@@ -25,13 +26,12 @@
#define COLOR_WHITE 0x00FFFFFF
#define COLOR_YELLOW 0x00FFFF00
typedef struct
{
int32_t x;
int32_t y;
} coordinates_t;
// extern coordinates_t;
// typedef struct
// {
// int32_t x;
// int32_t y;
// } coordinates_t;
void GFX_ClearScreen(SDL_Renderer* ren, uint32_t color);
void GFX_DrawPixel(SDL_Renderer* ren, int x, int y, uint32_t color, int alpha);
......
......@@ -9,10 +9,17 @@ typedef struct _vec2
double x, y;
} vec2;
typedef struct _coordinates
// typedef struct _coordinates
// {
// uint32_t row, column;
// } coordinates;
typedef struct
{
uint32_t row, column;
} coordinates;
int32_t x;
int32_t y;
} coordinates_t;
vec2 vec2_create(double x_, double y_);
......@@ -38,7 +45,7 @@ vec2 vec2_normalize(vec2 v);
bool vec2_is_approx_equal(vec2 lhs, vec2 rhs, double eps);
coordinates vec2_to_coordinates(vec2 v, uint32_t width, uint32_t height);
coordinates_t vec2_to_coordinates(vec2 v, uint32_t width, uint32_t height);
vec2 vec2_map(vec2 v);
......
......@@ -21,10 +21,15 @@ bool compute_e(charge_t c, vec2 p, double eps, vec2 *e)
return !(vec2_norm(qP) < eps);
}
// // Compute the normalized sum of Ei*qiP/norm(qiP)
// // Return false if for some qiP, norm(qiP) < eps
// bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p,
// double eps, vec2 *e)
// {
// Compute the normalized sum of Ei*qiP/norm(qiP)
// Return false if for some qiP, norm(qiP) < eps
bool compute_total_normalized_e(charge_t *charges, int num_charges, vec2 p,
double eps, vec2 *e)
{
for (int i = 0; i < num_charges; i++)
{
if (!compute_e(charges[i], p, eps, e)) {return false;}
}
// }
\ No newline at end of file
return true;
}
\ No newline at end of file
......@@ -10,17 +10,26 @@
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "../includes/gfx.h"
#include "../includes/elec_charge.h"
#define WIDTH 500
#define HEIGHT 500
#define X_CHARGE_1 WIDTH/3
#define Y_CHARGE_1 HEIGHT/2
#define X_CHARGE_2 WIDTH*2/3
#define Y_CHARGE_2 HEIGHT/2
int32_t SDL_SpawnAll(SDL_Window ** pp_win_, SDL_Renderer ** pp_ren);
void SDL_killAll(SDL_Window ** pp_win_, SDL_Renderer ** pp_ren);
int main()
{
srand(time(NULL));
// ! CREATE EMPTY SDL STUFF
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
......@@ -33,6 +42,18 @@ int main()
printf("SDL STUFF SUCCESSFULLY SPAWNED!\n");
}
// ! INIT CHARGES
charge_t *charges = malloc(2 * sizeof(*charges));
charges[0].pos = (vec2){X_CHARGE_1, Y_CHARGE_1};
charges[0].q = -5;
charges[1].pos = (vec2){X_CHARGE_2, Y_CHARGE_2};
charges[1].q = -10;
vec2 p = {.x = (double)(rand() % 10)/10.0 , .y = (double)(rand() % 10)/10.0};
vec2_print(p, "p :");
vec2 next_p;
vec2 e;
while(running_loop)
{
......@@ -51,22 +72,28 @@ int main()
}
// DRAW
GFX_ClearScreen(renderer, COLOR_BLACK);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){75, 50}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){72, 62}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){62, 72}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){50, 75}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){38, 72}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){28, 62}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){25, 50}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){28, 38}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){37, 28}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){50, 25}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){62, 28}, COLOR_BLUE);
GFX_DrawLine(renderer, (coordinates_t){50, 50}, (coordinates_t){72, 37}, COLOR_BLUE);
GFX_DrawCircle(renderer, (coordinates_t){250, 250}, 50, COLOR_RED);
// GFX_ClearScreen(renderer, COLOR_BLACK);
// DESSINE LES CHARGES
GFX_DrawCircle(renderer, (coordinates_t){X_CHARGE_1, Y_CHARGE_1}, 25, COLOR_RED);
GFX_DrawCircle(renderer, (coordinates_t){X_CHARGE_2, Y_CHARGE_2}, 25, COLOR_BLUE);
// COMPUTE LA POSITION DES POINTS
e.x = 0;
e.y = 0;
compute_total_normalized_e(charges, 2, p, 0.5, &e);
// printf("%s\n", ? "TRUE" : "FALSE");
e = vec2_div(vec2_norm(e), e);
next_p = vec2_mul(1 / sqrt(WIDTH * WIDTH + HEIGHT * HEIGHT), e);
next_p = vec2_add(p, next_p);
vec2_print(e, "e :");
vec2_print(p, "p :");
vec2_print(next_p, "next_p :");
GFX_DrawLine(renderer, vec2_to_coordinates(p, WIDTH, HEIGHT), vec2_to_coordinates(next_p, WIDTH, HEIGHT), COLOR_WHITE);
p = next_p;
SDL_RenderPresent(renderer);
}
......@@ -76,6 +103,7 @@ int main()
return 0;
}
/**
* @brief Setup the basic SDL stuff
*
......
......@@ -121,12 +121,12 @@ bool vec2_is_approx_equal(vec2 lhs, vec2 rhs, double eps)
/// @param width The screen width.
/// @param height The screen height.
/// @return The coordinates (row, column).
coordinates vec2_to_coordinates(vec2 v, uint32_t width, uint32_t height)
coordinates_t vec2_to_coordinates(vec2 v, uint32_t width, uint32_t height)
{
coordinates c;
coordinates_t c;
c.column = v.x * (width-1)/2 + (width-1)/2 + 1;
c.row = v.y * (height-1)/2 + (height-1)/2 + 1;
c.x = v.x * width;
c.y = v.y * height;
return c;
}
......
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