From cbdc7e6b9ca345c472fbe9ecef391f89d1aed4c7 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 6 Apr 2016 20:42:46 +0200 Subject: Fix CSG. --- src/physics.c | 54 ++++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) (limited to 'src/physics.c') diff --git a/src/physics.c b/src/physics.c index 38f9c88..a6735a1 100644 --- a/src/physics.c +++ b/src/physics.c @@ -306,6 +306,8 @@ void phy_sim_destroy_fields(phy_sim *sim) free(sim->aux); sim->aux = NULL; + phy_sim_csg_clear(sim); + sim->valid = false; } @@ -544,46 +546,10 @@ void phy_sim_step(phy_sim *sim) { SDL_mutexV(sim->rotate_lock); } -void phy_sim_csg_push(phy_sim *sim) +void phy_sim_csg_push(phy_sim *sim, phy_csg_step *step) { - char *shape_str; - phy_csg_shape shape; - phy_csg_step *step; - - shape_str = con_var_get("csg_shape"); - - shape = CSG_SPHERE; - - if (shape_str) { - if (!strcmp(shape_str, "cylinder-z")) - shape = CSG_CYLINDER_Z; - } - - step = malloc(sizeof(phy_csg_step)); - assert(step); - step->next = sim->csg_stack; sim->csg_stack = step; - - step->shape = shape; - step->value = con_var_get_float("csg_v"); - - switch (shape) { - case CSG_SPHERE: - step->x[0] = con_var_get_float("csg_x"); - step->x[1] = con_var_get_float("csg_y"); - step->x[2] = con_var_get_float("csg_z"); - step->d[0] = con_var_get_float("csg_r"); - break; - - case CSG_CYLINDER_Z: - step->x[0] = con_var_get_float("csg_x"); - step->x[1] = con_var_get_float("csg_y"); - step->x[2] = con_var_get_float("csg_z"); - step->d[0] = con_var_get_float("csg_r"); - step->d[1] = con_var_get_float("csg_h"); - break; - } } void phy_sim_csg_clear(phy_sim *sim) @@ -594,6 +560,8 @@ void phy_sim_csg_clear(phy_sim *sim) next = step->next; free(step); } + + sim->csg_stack = NULL; } void phy_sim_debug(phy_sim *sim, size_t *coords) @@ -601,6 +569,7 @@ void phy_sim_debug(phy_sim *sim, size_t *coords) phy_field_info *fi = &sim->field_info; phy_field_aux_point *aux; float *E, *H, Emag, Hmag; + phy_csg_step *step; aux = sim->aux + coords[2] * fi->zstr1 + coords[1] * fi->ystr1 + coords[0] * fi->xstr1; @@ -634,6 +603,15 @@ void phy_sim_debug(phy_sim *sim, size_t *coords) aux->uec_H[1][0], aux->uec_H[1][1], aux->uec_H[1][2], aux->uec_H[1][3], aux->uec_H[2][0], aux->uec_H[2][1], aux->uec_H[2][2], aux->uec_H[2][3]); printf("Emag = %E, Hmag = %E, Z = %E\n", Emag, Hmag, Emag/Hmag); + + printf("CSG:\n"); + for (step = sim->csg_stack; step; step = step->next) { + printf("\ttype=%i, value=%f, x=[%f %f %f], d=[%f %f %f]\n", + step->shape, step->value, + step->x[0], step->x[1], step->x[2], + step->d[0], step->d[1], step->d[2]); + } + printf("=======================\n"); } @@ -677,7 +655,7 @@ void phy_run_command(phy_sim *sim, int number, void *data) break; case PHY_CMD_CSG_PUSH: - phy_sim_csg_push(sim); + phy_sim_csg_push(sim, data); break; case PHY_CMD_CSG_CLEAR: -- cgit