From d7d049375cda075717426661e47a36796f5436b0 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 13 Jan 2005 02:58:06 +0000 Subject: [PATCH] add RM_tape --- panda/src/parametrics/ropeNode.I | 30 +++++++++++++ panda/src/parametrics/ropeNode.cxx | 70 ++++++++++++++++++++++++++++++ panda/src/parametrics/ropeNode.h | 12 ++++- 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/panda/src/parametrics/ropeNode.I b/panda/src/parametrics/ropeNode.I index 3cbdb014f0..0208de453c 100644 --- a/panda/src/parametrics/ropeNode.I +++ b/panda/src/parametrics/ropeNode.I @@ -31,6 +31,7 @@ CData() { _uv_scale = 1.0f; _normal_mode = RopeNode::NM_none; _tube_up = LVector3f::up(); + _matrix = LMatrix4f::ident_mat(); _use_vertex_color = false; _num_subdiv = 10; _num_slices = 5; @@ -51,6 +52,7 @@ CData(const RopeNode::CData ©) : _uv_scale(copy._uv_scale), _normal_mode(copy._normal_mode), _tube_up(copy._tube_up), + _matrix(copy._matrix), _use_vertex_color(copy._use_vertex_color), _num_subdiv(copy._num_subdiv), _num_slices(copy._num_slices), @@ -351,3 +353,31 @@ get_thickness() const { CDReader cdata(_cycler); return cdata->_thickness; } + +//////////////////////////////////////////////////////////////////// +// Function: set_matrix +// Access: Published +// Description: Specifies an optional matrix which is used to +// transform each control vertex after it has been +// transformed into the RopeNode's coordinate space, but +// before the polygon vertices are generated. +//////////////////////////////////////////////////////////////////// +INLINE void RopeNode:: +set_matrix(const LMatrix4f &matrix) { + CDWriter cdata(_cycler); + cdata->_matrix = matrix; +} + +//////////////////////////////////////////////////////////////////// +// Function: get_matrix +// Access: Published +// Description: Returns the optional matrix which is used to +// transform each control vertex after it has been +// transformed into the RopeNode's coordinate space, but +// before the polygon vertices are generated. +//////////////////////////////////////////////////////////////////// +INLINE const LMatrix4f &RopeNode:: +get_matrix() const { + CDReader cdata(_cycler); + return cdata->_matrix; +} diff --git a/panda/src/parametrics/ropeNode.cxx b/panda/src/parametrics/ropeNode.cxx index 198904efd5..10ee1dfcad 100644 --- a/panda/src/parametrics/ropeNode.cxx +++ b/panda/src/parametrics/ropeNode.cxx @@ -162,6 +162,10 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) { render_thread(trav, data, result); break; + case RM_tape: + render_tape(trav, data, result); + break; + case RM_billboard: render_billboard(trav, data, result); break; @@ -317,6 +321,68 @@ render_thread(CullTraverser *trav, CullTraverserData &data, trav->get_cull_handler()->record_object(object); } +//////////////////////////////////////////////////////////////////// +// Function: RopeNode::render_tape +// Access: Private +// Description: Draws the rope in RM_tape mode. This draws a +// series of triangle strips oriented to be +// perpendicular to the tube_up vector. +// +// In this mode, thickness is in spatial units, and +// determines the width of the triangle strips. +//////////////////////////////////////////////////////////////////// +void RopeNode:: +render_tape(CullTraverser *trav, CullTraverserData &data, + NurbsCurveResult *result) const { + CurveSegments curve_segments; + get_connected_segments(curve_segments, result); + + // Now we have stored one or more sequences of vertices down the + // center strips. Go back through and calculate the vertices on + // either side. + + PTA_Vertexf verts; + PTA_TexCoordf uvs; + PTA_Colorf colors; + + compute_billboard_vertices(verts, uvs, colors, -get_tube_up(), + curve_segments, result); + + // Finally, build the lengths array to make them into proper + // triangle strips. We don't need a vindex array here, since the + // vertices just happened to end up in tristrip order. + + PTA_int lengths; + int num_prims = 0; + + CurveSegments::const_iterator si; + for (si = curve_segments.begin(); si != curve_segments.end(); ++si) { + const CurveSegment &segment = (*si); + + lengths.push_back(segment.size() * 2); + num_prims++; + } + + // And create a Geom for the rendering. + + PT(Geom) geom = new GeomTristrip; + geom->set_num_prims(num_prims); + geom->set_coords(verts); + if (get_uv_mode() != UV_none) { + geom->set_texcoords(uvs, G_PER_VERTEX); + } + if (get_use_vertex_color()) { + geom->set_colors(colors, G_PER_VERTEX); + } else { + geom->set_colors(colors, G_OVERALL); + } + geom->set_lengths(lengths); + + CullableObject *object = new CullableObject(geom, data._state, + data._render_transform); + trav->get_cull_handler()->record_object(object); +} + //////////////////////////////////////////////////////////////////// // Function: RopeNode::render_billboard // Access: Private @@ -489,9 +555,12 @@ get_connected_segments(RopeNode::CurveSegments &curve_segments, CurveSegment *curve_segment = NULL; LPoint3f last_point; + const LMatrix4f &matrix = get_matrix(); + for (int segment = 0; segment < num_segments; ++segment) { LPoint3f point; result->eval_segment_point(segment, 0.0f, point); + point = point * matrix; if (curve_segment == (CurveSegment *)NULL || !point.almost_equal(last_point)) { @@ -517,6 +586,7 @@ get_connected_segments(RopeNode::CurveSegments &curve_segments, CurveVertex vtx; result->eval_segment_point(segment, t, vtx._p); + vtx._p = vtx._p * matrix; vtx._t = result->get_segment_t(segment, t); if (use_vertex_color) { result->eval_segment_extended_points(segment, t, 0, &vtx._c[0], 4); diff --git a/panda/src/parametrics/ropeNode.h b/panda/src/parametrics/ropeNode.h index c10c55abda..ff94c1515f 100644 --- a/panda/src/parametrics/ropeNode.h +++ b/panda/src/parametrics/ropeNode.h @@ -57,7 +57,11 @@ PUBLISHED: // Render the rope as a one-pixel thread using a linestrip. RM_thread, - // Render the rope as a continuous triangle strip oriented to be + // Render the rope as a triangle strip oriented to be + // perpendicular to the tube_up vector. + RM_tape, + + // Render the rope as a triangle strip oriented to be // perpendicular to the view vector. RM_billboard, @@ -127,6 +131,9 @@ PUBLISHED: INLINE void set_thickness(float thickness); INLINE float get_thickness() const; + INLINE void set_matrix(const LMatrix4f &matrix); + INLINE const LMatrix4f &get_matrix() const; + void reset_bound(const NodePath &rel_to); protected: @@ -136,6 +143,8 @@ private: BoundingVolume *do_recompute_bound(const NodePath &rel_to); void render_thread(CullTraverser *trav, CullTraverserData &data, NurbsCurveResult *result) const; + void render_tape(CullTraverser *trav, CullTraverserData &data, + NurbsCurveResult *result) const; void render_billboard(CullTraverser *trav, CullTraverserData &data, NurbsCurveResult *result) const; void render_tube(CullTraverser *trav, CullTraverserData &data, @@ -191,6 +200,7 @@ private: float _uv_scale; NormalMode _normal_mode; LVector3f _tube_up; + LMatrix4f _matrix; bool _use_vertex_color; int _num_subdiv; int _num_slices;