summaryrefslogtreecommitdiff
path: root/src/physics.c
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2016-03-31 18:10:42 +0200
committerPaweł Redman <pawel.redman@gmail.com>2016-03-31 18:10:42 +0200
commita5677db21bee18f8e5b67ba2b0615403ebe6dc8a (patch)
tree73be0f704b905b8bf6f00364c2c89b738f8138be /src/physics.c
parent523f6b460dcf1f864656a9a6ccc2a54d52f385c6 (diff)
Refactor ui_simview, minor physics fixes.
Diffstat (limited to 'src/physics.c')
-rw-r--r--src/physics.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/physics.c b/src/physics.c
index 5b904c6..49c6552 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -23,10 +23,10 @@ int phy_sim_create(phy_sim *sim) {
fi = &sim->field_info;
- fi->width = 30;
- fi->height = 30;
- fi->depth = 30;
- fi->spacing = 1.5e10 / max3(fi->width, fi->height, fi->depth);
+ fi->width = 50;
+ fi->height = 50;
+ fi->depth = 50;
+ fi->spacing = 1.5e9 / max3(fi->width, fi->height, fi->depth);
fi->xstr = 3;
fi->ystr = fi->xstr * fi->width;
@@ -165,11 +165,13 @@ void phy_sim_add_sources(phy_sim *sim)
E = sim->fields[2].E + z * fi->zstr + y * fi->ystr + x * fi->xstr;
H = sim->fields[2].H + z * fi->zstr + y * fi->ystr + x * fi->xstr;
- chuj = (0.3 - sqrt(fx * fx + fy * fy + fz * fz)) / 0.3;
+ chuj = (0.5 - sqrt(fx * fx + fy * fy + fz * fz)) / 0.5;
if (chuj < 0)
chuj = 0;
+ else
+ chuj = 1;
- chuj *= sin(sim->time) * 10;
+ chuj *= sin(sim->time * 3) * 1;
//chuj *= exp(-10.0f * pow(sim->time - 0.5, 2)) * 2;
E[0] += chuj;
}
@@ -177,20 +179,17 @@ void phy_sim_add_sources(phy_sim *sim)
void phy_sim_step(phy_sim *sim, float dt) {
phy_field_info *fi = &sim->field_info;
- phy_field_em *fields = sim->fields;
-
- size_t i, size_in_bytes;
+ phy_field_em *fields = sim->fields, tmp;
+ size_t i;
phy_sim_add_sources(sim);
- size_in_bytes = fi->size * sizeof(float);
-
+ // note: only pointers are rotated, not the entire fields
SDL_mutexP(sim->rotate_lock);
- for (i = 0; i < 2; i++) {
- // TODO: avoid copying, just switch around pointers
- memcpy(fields[i].E, fields[i + 1].E, size_in_bytes);
- memcpy(fields[i].H, fields[i + 1].H, size_in_bytes);
- }
+ memcpy(&tmp, fields, sizeof(phy_field_em));
+ memcpy(fields, fields + 1, sizeof(phy_field_em));
+ memcpy(fields + 1, fields + 2, sizeof(phy_field_em));
+ memcpy(fields + 2, &tmp, sizeof(phy_field_em));
SDL_mutexV(sim->rotate_lock);
phy_sim_step_1(fi, dt, sim->field_eps,