From 2d5254428d6a153cbbdf1e96a555e0bbfe747984 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 1 Oct 2003 18:19:52 +0000 Subject: [PATCH] allow omitting -b --- pandatool/src/eggprogs/eggMakeTube.cxx | 36 +++++++++++++++++++------- pandatool/src/eggprogs/eggMakeTube.h | 1 + 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/pandatool/src/eggprogs/eggMakeTube.cxx b/pandatool/src/eggprogs/eggMakeTube.cxx index fecd6343e8..4b3cb64e3d 100644 --- a/pandatool/src/eggprogs/eggMakeTube.cxx +++ b/pandatool/src/eggprogs/eggMakeTube.cxx @@ -31,6 +31,14 @@ //////////////////////////////////////////////////////////////////// EggMakeTube:: EggMakeTube() { + + set_program_description + ("egg-make-tube generates an egg file representing a \"tube\" model, " + "a cylinder capped on both ends by hemispheres. This is similar " + "in shape to the CollisionTube object within Panda.\n\n" + "This program can also generate spheres if you omit -b; in this " + "case, you are generating a degenerate tube of length 0."); + add_option ("a", "x,y,z", 0, "Specify the first endpoint of the tube.", @@ -39,7 +47,7 @@ EggMakeTube() { add_option ("b", "x,y,z", 0, "Specify the second endpoint of the tube.", - &EggWriter::dispatch_double_triple, NULL, _point_a); + &EggWriter::dispatch_double_triple, &_got_point_b, _point_b); add_option ("r", "radius", 0, @@ -85,6 +93,12 @@ EggMakeTube() { //////////////////////////////////////////////////////////////////// void EggMakeTube:: run() { + if (!_got_point_b) { + _point_b[0] = _point_a[0]; + _point_b[1] = _point_a[1]; + _point_b[2] = _point_a[2]; + } + // We will generate the vertices in the canonical space (along the y // axis), then transform it to the desired point. LVector3d direction(_point_b[0] - _point_a[0], @@ -117,15 +131,17 @@ run() { } // Now the cylinder sides. - for (ri = 0; ri < _num_trings; ri++) { - vtx_1 = NULL; - vtx_2 = NULL; - for (si = 0; si <= _num_slices; si++) { - EggVertex *vtx_3 = calc_tube_vertex(ri, si); - EggVertex *vtx_4 = calc_tube_vertex(ri + 1, si); - add_polygon(vtx_1, vtx_2, vtx_4, vtx_3); - vtx_1 = vtx_3; - vtx_2 = vtx_4; + if (_length != 0.0) { + for (ri = 0; ri < _num_trings; ri++) { + vtx_1 = NULL; + vtx_2 = NULL; + for (si = 0; si <= _num_slices; si++) { + EggVertex *vtx_3 = calc_tube_vertex(ri, si); + EggVertex *vtx_4 = calc_tube_vertex(ri + 1, si); + add_polygon(vtx_1, vtx_2, vtx_4, vtx_3); + vtx_1 = vtx_3; + vtx_2 = vtx_4; + } } } diff --git a/pandatool/src/eggprogs/eggMakeTube.h b/pandatool/src/eggprogs/eggMakeTube.h index 4e2f60fc5c..800e4d227f 100644 --- a/pandatool/src/eggprogs/eggMakeTube.h +++ b/pandatool/src/eggprogs/eggMakeTube.h @@ -47,6 +47,7 @@ private: private: double _point_a[3]; double _point_b[3]; + bool _got_point_b; double _radius; int _num_slices; int _num_crings;