Jelajahi Sumber

Added line scale factor to line renderer

Mark Mine 21 tahun lalu
induk
melakukan
c3420d3985

+ 19 - 0
panda/src/particlesystem/lineParticleRenderer.I

@@ -51,3 +51,22 @@ INLINE const Colorf& LineParticleRenderer::
 get_tail_color() const {
   return _tail_color;
 }
+
+////////////////////////////////////////////////////////////////////
+//    Function : set_line_scale_factor
+// Description : accessor
+////////////////////////////////////////////////////////////////////
+INLINE void LineParticleRenderer::
+set_line_scale_factor(float sf) {
+  _line_scale_factor = sf;
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : get_line_scale_factor
+// Description : accessor
+////////////////////////////////////////////////////////////////////
+INLINE float LineParticleRenderer::
+get_line_scale_factor() const {
+  return _line_scale_factor;
+}
+

+ 9 - 2
panda/src/particlesystem/lineParticleRenderer.cxx

@@ -34,6 +34,8 @@ LineParticleRenderer() :
   _head_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)),
   _tail_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)) {
 
+  _line_scale_factor = 1.0f;
+
   resize_pool(0);
 }
 
@@ -243,14 +245,19 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
 
     if (use_qpgeom) {
       vertex.add_data3f(position);
-      vertex.add_data3f(cur_particle->get_last_position());
+      LPoint3f last_position = position + 
+        (cur_particle->get_last_position() - position) * _line_scale_factor;
+      vertex.add_data3f(last_position);
       color.add_data4f(head_color);
       color.add_data4f(tail_color);
       _lines->add_next_vertices(2);
       _lines->close_primitive();
     } else {
+      LPoint3f last_position = position + 
+        (cur_particle->get_last_position() - position) * _line_scale_factor;
+
       *cur_vert++ = position;
-      *cur_vert++ = cur_particle->get_last_position();
+      *cur_vert++ = last_position;
 
       *cur_color++ = head_color;
       *cur_color++ = tail_color;

+ 5 - 0
panda/src/particlesystem/lineParticleRenderer.h

@@ -52,6 +52,9 @@ PUBLISHED:
   INLINE const Colorf& get_head_color() const;
   INLINE const Colorf& get_tail_color() const;
   
+  INLINE void set_line_scale_factor(float sf);
+  INLINE float get_line_scale_factor() const;
+
   virtual void output(ostream &out) const;
   virtual void write(ostream &out, int indent=0) const;
 
@@ -71,6 +74,8 @@ private:
   LPoint3f _aabb_min;
   LPoint3f _aabb_max;
 
+  float _line_scale_factor;
+
   virtual void birth_particle(int index);
   virtual void kill_particle(int index);
   virtual void init_geoms();