summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2016-04-06 17:54:20 +0200
committerPaweł Redman <pawel.redman@gmail.com>2016-04-06 17:54:20 +0200
commit60c0a689450403854a1adb55f8b1185c8d3f9313 (patch)
tree7bae71d65f091399afa20191268da11d4f7042d2
parent85422fbdaf5c56ca817f0a8d8f17f2d725dd1c3a (diff)
New CSG shape: cylinder-z.
-rw-r--r--src/physics.c29
-rw-r--r--src/physics.h3
2 files changed, 28 insertions, 4 deletions
diff --git a/src/physics.c b/src/physics.c
index c7cc477..f8c46fa 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -68,6 +68,13 @@ static float phy_sim_csg_subsample(phy_csg_step *stack, float *x)
sq(x[2] - step->x[2]) > sq(step->d[0]))
goto next_step;
break;
+
+ case CSG_CYLINDER_Z:
+ if (x[2] > step->x[2] + step->d[1] ||
+ x[2] < step->x[2] - step->d[1] ||
+ sq(x[0] - step->x[0]) + sq(x[1] - step->x[1]) >
+ sq(step->d[0]))
+ goto next_step;
}
rv = step->value;
@@ -81,7 +88,6 @@ static float phy_sim_csg_subsample(phy_csg_step *stack, float *x)
static float phy_sim_csg_sample(phy_csg_step *stack, size_t *x)
{
- vec3_t xf = {x[0], x[1], x[2]};
size_t dx, dy, dz;
float total;
@@ -191,12 +197,15 @@ int phy_sim_create(phy_sim *sim)
con_var_set("src_z", "10");
con_var_set("src_angle", "0");
+
+ con_var_set("csg_shape", "sphere");
+ con_var_set("csg_v", NULL);
con_var_set("csg_x", NULL);
con_var_set("csg_y", NULL);
con_var_set("csg_z", NULL);
con_var_set("csg_r", NULL);
- con_var_set("csg_v", NULL);
+ con_var_set("csg_h", NULL);
phy_sim_create_fields(sim);
@@ -517,16 +526,22 @@ void phy_sim_csg_push(phy_sim *sim)
phy_csg_shape shape;
phy_csg_step *step;
- // TODO shape_str = con_var_get("csg_shape");
+ 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) {
@@ -536,6 +551,14 @@ void phy_sim_csg_push(phy_sim *sim)
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;
}
}
diff --git a/src/physics.h b/src/physics.h
index 80f3fdf..97c44d4 100644
--- a/src/physics.h
+++ b/src/physics.h
@@ -53,7 +53,8 @@ enum {
};
typedef enum {
- CSG_SPHERE
+ CSG_SPHERE,
+ CSG_CYLINDER_Z
} phy_csg_shape;
typedef struct phy_csg_step_s phy_csg_step;