Merge branch 'main' of git.h3cx.dev:h3cx/fphysics
This commit is contained in:
4 files changed
+36
No files matched your search
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#include "magnetism.h"
|
||||||
|
#include "consts.h"
|
||||||
|
#include "vec_utils.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define EPSILON 8.85418782E-12
|
||||||
|
|
||||||
|
void magnetism(universe_t* uni){
|
||||||
|
mass_body_t body_1;
|
||||||
|
mass_body_t body_2;
|
||||||
|
Vector2 diff, force;
|
||||||
|
for (unsigned int i = 0; i < uni->num_bodies-1; i++) {
|
||||||
|
body_1 = uni->bodies[i];
|
||||||
|
for (unsigned int y = i + 1; y < uni->num_bodies; y++) {
|
||||||
|
body_2 = uni->bodies[y];
|
||||||
|
diff=vec2_diff(body_2.position,body_1.position);
|
||||||
|
force = vec2_scale(diff,body_1.charge*body_2.charge/(4*PI*EPSILON*vec2_len(diff)));
|
||||||
|
body_1.speed=vec2_sum(body_1.speed,vec2_scale(force,1/body_1.mass));
|
||||||
|
body_2.speed=vec2_diff(body_2.speed,vec2_scale(force,1/body_2.mass));
|
||||||
|
uni->bodies[y] = body_2;
|
||||||
|
}
|
||||||
|
uni->bodies[i] = body_1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef MAGNETISM_H
|
||||||
|
#define MAGNETISM_H
|
||||||
|
#include "objects.h"
|
||||||
|
void magnetism(universe_t* univ);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MAGNETISM_H
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
#include "consts.h"
|
#include "consts.h"
|
||||||
#include "gravity.h"
|
#include "gravity.h"
|
||||||
#include "mechanics.h"
|
#include "mechanics.h"
|
||||||
|
<<<<<<< HEAD
|
||||||
|
#include "magnetism.h"
|
||||||
|
=======
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
#include "vec_utils.h"
|
#include "vec_utils.h"
|
||||||
#include <bits/time.h>
|
#include <bits/time.h>
|
||||||
@@ -35,6 +38,7 @@ void *physics(void *args) {
|
|||||||
clock_gettime(CLOCK_MONOTONIC, &ct);
|
clock_gettime(CLOCK_MONOTONIC, &ct);
|
||||||
gravity(uni);
|
gravity(uni);
|
||||||
mechanics(uni);
|
mechanics(uni);
|
||||||
|
magnetism(uni);
|
||||||
ot = ct;
|
ot = ct;
|
||||||
long long elapsed = timespec_diff_ns(ct, ot);
|
long long elapsed = timespec_diff_ns(ct, ot);
|
||||||
long long remaining = TIMESTEP / simx - elapsed;
|
long long remaining = TIMESTEP / simx - elapsed;
|
||||||
|
|||||||
Reference in new issue
Block a user