22 PStatCollector LineParticleRenderer::_render_collector(
"App:Particles:Line:Render");
30 _head_color(LColor(1.0f, 1.0f, 1.0f, 1.0f)),
31 _tail_color(LColor(1.0f, 1.0f, 1.0f, 1.0f)) {
33 _line_scale_factor = 1.0f;
45 ParticleRendererAlphaMode alpha_mode) :
47 _head_color(head), _tail_color(tail)
59 _head_color = copy._head_color;
60 _tail_color = copy._tail_color;
86 void LineParticleRenderer::
94 void LineParticleRenderer::
102 void LineParticleRenderer::
103 resize_pool(
int new_size) {
104 _max_pool_size = new_size;
113 void LineParticleRenderer::
119 _line_primitive = geom;
121 geom->add_primitive(_lines);
125 render_node->
add_geom(_line_primitive, _render_state);
132 void LineParticleRenderer::
141 int remaining_particles = ttl_particles;
146 _lines->clear_vertices();
150 _aabb_min.set(99999.0f, 99999.0f, 99999.0f);
151 _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
155 for (i = 0; i < (int)po_vector.size(); i++) {
158 if (cur_particle->get_alive() ==
false)
165 if (position[0] > _aabb_max[0])
166 _aabb_max[0] = position[0];
167 if (position[0] < _aabb_min[0])
168 _aabb_min[0] = position[0];
170 if (position[1] > _aabb_max[1])
171 _aabb_max[1] = position[1];
172 if (position[1] < _aabb_min[1])
173 _aabb_min[1] = position[1];
175 if (position[2] > _aabb_max[2])
176 _aabb_max[2] = position[2];
177 if (position[2] < _aabb_min[2])
178 _aabb_min[2] = position[2];
182 LColor head_color = _head_color;
183 LColor tail_color = _tail_color;
187 if (_alpha_mode != PR_ALPHA_NONE) {
191 if (_alpha_mode == PR_ALPHA_USER) {
194 alpha = cur_particle->get_parameterized_age();
195 if (_alpha_mode == PR_ALPHA_OUT)
196 alpha = 1.0f - alpha;
197 else if (_alpha_mode == PR_ALPHA_IN_OUT)
198 alpha = 2.0f * std::min(alpha, 1.0f - alpha);
201 head_color[3] = alpha;
202 tail_color[3] = alpha;
207 vertex.add_data3(position);
208 LPoint3 last_position = position +
210 vertex.add_data3(last_position);
211 color.add_data4(head_color);
212 color.add_data4(tail_color);
213 _lines->add_next_vertices(2);
214 _lines->close_primitive();
216 remaining_particles--;
217 if (remaining_particles == 0)
223 LPoint3 aabb_center = (_aabb_min + _aabb_max) * 0.5f;
224 PN_stdfloat radius = (aabb_center - _aabb_min).length();
227 _line_primitive->set_bounds(&sphere);
237 out<<
"LineParticleRenderer";
245 write(std::ostream &out,
int indent_level)
const {
246 indent(out, indent_level) <<
"LineParticleRenderer:\n";
247 indent(out, indent_level + 2) <<
"_head_color "<<_head_color<<
"\n";
248 indent(out, indent_level + 2) <<
"_tail_color "<<_tail_color<<
"\n";
249 indent(out, indent_level + 2) <<
"_line_primitive "<<_line_primitive<<
"\n";
250 indent(out, indent_level + 2) <<
"_max_pool_size "<<_max_pool_size<<
"\n";
251 indent(out, indent_level + 2) <<
"_aabb_min "<<_aabb_min<<
"\n";
252 indent(out, indent_level + 2) <<
"_aabb_max "<<_aabb_max<<
"\n";
GeomNode * get_render_node() const
Query the geomnode pointer.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
virtual BaseParticleRenderer * make_copy()
child virtual for spawning systems
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LPoint3 get_last_position() const
Get the position of the physics object at the start of the most recent do_physics.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
This defines a bounding sphere, consisting of a center and a radius.
A body on which physics will be applied.
virtual ~LineParticleRenderer()
Destructor.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
This is our own Panda specialization on the default STL vector.
A lightweight class that represents a single element that may be timed and/or counted via stats.
virtual void write(std::ostream &out, int indent_level=0) const
Write a string representation of this instance to <out>.
Pure virtual particle renderer base class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
PN_stdfloat get_user_alpha() const
gets alpha for "user" alpha mode
Defines a series of disconnected line segments.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An individual, physically-modelable particle abstract base class.
LPoint3 get_position() const
Position Query.
LineParticleRenderer()
Default Constructor.
renders a line from last position to current position – good for rain, sparks, etc.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node that holds Geom objects, renderable pieces of geometry.
void add_geom(Geom *geom, const RenderState *state=RenderState::make_empty())
Adds a new Geom to the node.
void remove_all_geoms()
Removes all the geoms from the node at once.