15 #include "lineParticleRenderer.h" 16 #include "boundingSphere.h" 19 #include "geomVertexWriter.h" 21 #include "pStatTimer.h" 23 PStatCollector LineParticleRenderer::_render_collector(
"App:Particles:Line:Render");
33 _head_color(
LColor(1.0f, 1.0f, 1.0f, 1.0f)),
34 _tail_color(
LColor(1.0f, 1.0f, 1.0f, 1.0f)) {
36 _line_scale_factor = 1.0f;
50 ParticleRendererAlphaMode alpha_mode) :
52 _head_color(head), _tail_color(tail)
66 _head_color = copy._head_color;
67 _tail_color = copy._tail_color;
99 void LineParticleRenderer::
100 birth_particle(
int) {
109 void LineParticleRenderer::
120 void LineParticleRenderer::
121 resize_pool(
int new_size) {
122 _max_pool_size = new_size;
133 void LineParticleRenderer::
136 (
"line_particles", GeomVertexFormat::get_v3cp(),
139 _line_primitive = geom;
141 geom->add_primitive(_lines);
145 render_node->
add_geom(_line_primitive, _render_state);
154 void LineParticleRenderer::
163 int remaining_particles = ttl_particles;
168 _lines->clear_vertices();
172 _aabb_min.set(99999.0f, 99999.0f, 99999.0f);
173 _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
177 for (i = 0; i < (int)po_vector.size(); i++) {
180 if (cur_particle->get_alive() ==
false)
187 if (position[0] > _aabb_max[0])
188 _aabb_max[0] = position[0];
189 if (position[0] < _aabb_min[0])
190 _aabb_min[0] = position[0];
192 if (position[1] > _aabb_max[1])
193 _aabb_max[1] = position[1];
194 if (position[1] < _aabb_min[1])
195 _aabb_min[1] = position[1];
197 if (position[2] > _aabb_max[2])
198 _aabb_max[2] = position[2];
199 if (position[2] < _aabb_min[2])
200 _aabb_min[2] = position[2];
204 LColor head_color = _head_color;
205 LColor tail_color = _tail_color;
209 if (_alpha_mode != PR_ALPHA_NONE) {
213 if (_alpha_mode == PR_ALPHA_USER) {
216 alpha = cur_particle->get_parameterized_age();
217 if (_alpha_mode == PR_ALPHA_OUT)
218 alpha = 1.0f - alpha;
219 else if (_alpha_mode == PR_ALPHA_IN_OUT)
220 alpha = 2.0f * min(alpha, 1.0f - alpha);
223 head_color[3] = alpha;
224 tail_color[3] = alpha;
230 LPoint3 last_position = position +
235 _lines->add_next_vertices(2);
236 _lines->close_primitive();
238 remaining_particles--;
239 if (remaining_particles == 0)
245 LPoint3 aabb_center = (_aabb_min + _aabb_max) * 0.5f;
246 PN_stdfloat radius = (aabb_center - _aabb_min).length();
249 _line_primitive->set_bounds(&sphere);
262 out<<
"LineParticleRenderer";
273 write(ostream &out,
int indent_level)
const {
274 indent(out, indent_level) <<
"LineParticleRenderer:\n";
275 indent(out, indent_level + 2) <<
"_head_color "<<_head_color<<
"\n";
276 indent(out, indent_level + 2) <<
"_tail_color "<<_tail_color<<
"\n";
277 indent(out, indent_level + 2) <<
"_line_primitive "<<_line_primitive<<
"\n";
278 indent(out, indent_level + 2) <<
"_max_pool_size "<<_max_pool_size<<
"\n";
279 indent(out, indent_level + 2) <<
"_aabb_min "<<_aabb_min<<
"\n";
280 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
LPoint3 get_last_position() const
Get the position of the physics object at the start of the most recent do_physics.
virtual void output(ostream &out) 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...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
void add_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w)
Sets the write row to a particular 4-component value, and advances the write row. ...
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...
Pure virtual particle renderer base class.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the write row to a particular 3-component value, and advances the write row. ...
PN_stdfloat get_user_alpha() const
gets alpha for "user" alpha mode
Defines a series of disconnected line segments.
This is the base class for all three-component vectors and points.
virtual void write(ostream &out, int indent_level=0) const
Write a string representation of this instance to <out>.
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.
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
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.