summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/physics.c31
-rw-r--r--src/ui.c122
2 files changed, 91 insertions, 62 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,
diff --git a/src/ui.c b/src/ui.c
index c79669d..4e2f791 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -305,25 +305,16 @@ void ui_animate_exp(float *val, float targ, float lambda, float dt)
*val = targ + (*val - targ) * exp(-lambda * dt);
}
-void ui_draw_window_simview(ui_window *uiw, int64_t time, float dt)
+void ui_draw_simview_xsection(ui_window *uiw, float *field)
{
ui_simview *sv = &uiw->simview;
phy_sim *sim = sv->sim;
float aspect_ratio;
vec2_t origin_s, scale_s;
- phy_field_em *field_em = sim->fields + 2;
-
- const char *xsection_type_strings[] = {
- "Przekrój XY przez Z",
- "Przekrój XZ przez Y",
- "Przekrój YZ przez X"
- };
-
- // xsection
SDL_mutexP(sim->rotate_lock);
r_xsection_update(uiw->rw, &sv->xsection, &sim->field_info,
- field_em->E, sv->xsection_type, sv->xsection_frac);
+ field, sv->xsection_type, sv->xsection_frac);
SDL_mutexV(sim->rotate_lock);
aspect_ratio = sv->xsection.aspect_ratio;
@@ -343,50 +334,53 @@ void ui_draw_window_simview(ui_window *uiw, int64_t time, float dt)
r_xsection_draw(uiw->rw, &sv->xsection, origin_s[0], origin_s[1],
scale_s[0], scale_s[1]);
+}
- // xsection - select
-
- if (sv->select_valid)
- {
- vec2_t select_s;
+void ui_draw_simview_selection(ui_window *uiw)
+{
+ ui_simview *sv = &uiw->simview;
+ phy_sim *sim = sv->sim;
+ vec2_t select_s;
- switch (sv->xsection_type) {
- case XSECTION_XY:
- v2_set(select_s, sv->select[0], sv->select[1]);
- break;
+ if (!sv->select_valid)
+ return;
- case XSECTION_XZ:
- v2_set(select_s, sv->select[0], sv->select[2]);
- break;
+ switch (sv->xsection_type) {
+ case XSECTION_XY:
+ v2_set(select_s, sv->select[0], sv->select[1]);
+ break;
- case XSECTION_YZ:
- v2_set(select_s, sv->select[1], sv->select[2]);
- break;
- }
+ case XSECTION_XZ:
+ v2_set(select_s, sv->select[0], sv->select[2]);
+ break;
- v2_mul_mst2(select_s, select_s, sv->tf_x2s);
+ case XSECTION_YZ:
+ v2_set(select_s, sv->select[1], sv->select[2]);
+ break;
+ }
- r_draw_line(uiw->rw, select_s[0], 0, select_s[0], uiw->h,
- theme.color_select);
- r_draw_line(uiw->rw, 0, select_s[1], uiw->w, select_s[1],
- theme.color_select);
+ v2_mul_mst2(select_s, select_s, sv->tf_x2s);
+ r_draw_line(uiw->rw, select_s[0], 0, select_s[0], uiw->h,
+ theme.color_select);
+ r_draw_line(uiw->rw, 0, select_s[1], uiw->w, select_s[1],
+ theme.color_select);
+}
- r_draw_rect(uiw->rw, 0, uiw->h - theme.font_size,
- uiw->w, theme.font_size, theme.color_main);
+void ui_draw_simview_bars(ui_window *uiw, float dt)
+{
+ const char *xsection_type_strings[] = {
+ "Przekrój XY przez Z",
+ "Przekrój XZ przez Y",
+ "Przekrój YZ przez X"
+ };
- r_draw_text(uiw->rw, 0, uiw->h - theme.font_size,
- theme.font_size,
- va("x = [%f %f %f]", sv->select[0],
- sv->select[1], sv->select[2]),
- theme.color_text, 0);
+ ui_simview *sv = &uiw->simview;
+ phy_sim *sim = sv->sim;
- sv->margin_bottom = 1 * theme.font_size;
- }
- else
- sv->margin_bottom = 0;
+ // upper
- // status
+ sv->margin_top = theme.font_size;
r_draw_rect(uiw->rw, 0, 0, uiw->w, theme.font_size, theme.color_main);
@@ -399,8 +393,44 @@ void ui_draw_window_simview(ui_window *uiw, int64_t time, float dt)
sv->xsection_frac),
theme.color_text, 0);
+ // lower
+
+ sv->margin_bottom = theme.font_size;
+ r_draw_rect(uiw->rw, 0, uiw->h - theme.font_size,
+ uiw->w, theme.font_size, theme.color_main);
+
+ r_draw_text(uiw->rw, 0, uiw->h - theme.font_size,
+ theme.font_size, va("t = %f", sim->time),
+ theme.color_text, 0);
+
+ if (sv->select_valid) {
+ size_t x, y, z, offs;
+
+ sv->margin_bottom += 2 * theme.font_size;
+
+ r_draw_rect(uiw->rw, 0, uiw->h - 3 * theme.font_size,
+ uiw->w, 2 * theme.font_size, theme.color_main);
+
+ r_draw_text(uiw->rw, 0, uiw->h - theme.font_size,
+ theme.font_size,
+ va("x = [%f %f %f]", sv->select[0],
+ sv->select[1], sv->select[2]),
+ theme.color_text, 0);
+ }
+}
+
+
+void ui_draw_simview(ui_window *uiw, int64_t time, float dt)
+{
+ ui_draw_simview_xsection(uiw, uiw->simview.sim->fields[1].E);
+ ui_draw_simview_selection(uiw);
+ ui_draw_simview_bars(uiw, dt);
+
+ // status
+
// info text
+/*
if (sv->info_valid && sv->info_time + 2000000000ll > time)
{
vec4_t color;
@@ -420,7 +450,7 @@ void ui_draw_window_simview(ui_window *uiw, int64_t time, float dt)
r_draw_text(uiw->rw, uiw->w / 2.0f, theme.font_size,
theme.font_size, sv->info, color, TEXT_CENTERX);
- }
+ }*/
}
void ui_draw_window(ui_window *uiw)
@@ -453,7 +483,7 @@ void ui_draw_window(ui_window *uiw)
dt = (get_time() - uiw->last_frame) * 1.0e-9;
r_clear(uiw->rw, r_color_black);
- ui_draw_window_simview(uiw, time, dt);
+ ui_draw_simview(uiw, time, dt);
r_flip(uiw->rw);
uiw->last_frame = time;