15 #include "sparkleParticleRenderer.h" 16 #include "boundingSphere.h" 19 #include "geomVertexWriter.h" 21 #include "pStatTimer.h" 23 PStatCollector SparkleParticleRenderer::_render_collector(
"App:Particles:Sparkle:Render");
33 _center_color(
LColor(1.0f, 1.0f, 1.0f, 1.0f)),
34 _edge_color(
LColor(1.0f, 1.0f, 1.0f, 1.0f)),
35 _birth_radius(0.1f), _death_radius(0.1f)
47 PN_stdfloat birth_radius, PN_stdfloat death_radius,
48 SparkleParticleLifeScale life_scale,
49 ParticleRendererAlphaMode alpha_mode) :
51 _center_color(center), _edge_color(edge), _birth_radius(birth_radius),
52 _death_radius(death_radius), _life_scale(life_scale)
65 _center_color = copy._center_color;
66 _edge_color = copy._edge_color;
67 _birth_radius = copy._birth_radius;
68 _death_radius = copy._death_radius;
69 _life_scale = copy._life_scale;
98 void SparkleParticleRenderer::
107 void SparkleParticleRenderer::
117 void SparkleParticleRenderer::
118 resize_pool(
int new_size) {
119 _max_pool_size = new_size;
129 void SparkleParticleRenderer::
132 (
"sparkle_particles", GeomVertexFormat::get_v3cp(),
135 _line_primitive = geom;
137 geom->add_primitive(_lines);
141 render_node->
add_geom(_line_primitive, _render_state);
149 void SparkleParticleRenderer::
152 if (!ttl_particles) {
158 int remaining_particles = ttl_particles;
163 _lines->clear_vertices();
167 _aabb_min.set(99999.0f, 99999.0f, 99999.0f);
168 _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
172 for (i = 0; i < (int)po_vector.size(); i++) {
175 if (cur_particle->get_alive() ==
false) {
183 if (position[0] > _aabb_max[0])
184 _aabb_max[0] = position[0];
185 else if (position[0] < _aabb_min[0])
186 _aabb_min[0] = position[0];
188 if (position[1] > _aabb_max[1])
189 _aabb_max[1] = position[1];
190 else if (position[1] < _aabb_min[1])
191 _aabb_min[1] = position[1];
193 if (position[2] > _aabb_max[2])
194 _aabb_max[2] = position[2];
195 else if (position[2] < _aabb_min[2])
196 _aabb_min[2] = position[2];
200 PN_stdfloat radius = get_radius(cur_particle);
201 PN_stdfloat neg_radius = -radius;
204 LColor center_color = _center_color;
205 LColor edge_color = _edge_color;
209 if (_alpha_mode != PR_ALPHA_NONE) {
210 if(_alpha_mode == PR_ALPHA_USER) {
213 alpha = cur_particle->get_parameterized_age();
214 if (_alpha_mode == PR_ALPHA_OUT)
215 alpha = 1.0f - alpha;
216 else if (_alpha_mode == PR_ALPHA_IN_OUT)
217 alpha = 2.0f * min(alpha, 1.0f - alpha);
222 center_color[3] = alpha;
223 edge_color[3] = alpha;
229 vertex.
add_data3(position + LVertex(radius, 0.0f, 0.0f));
231 vertex.
add_data3(position + LVertex(neg_radius, 0.0f, 0.0f));
233 vertex.
add_data3(position + LVertex(0.0f, radius, 0.0f));
235 vertex.
add_data3(position + LVertex(0.0f, neg_radius, 0.0f));
237 vertex.
add_data3(position + LVertex(0.0f, 0.0f, radius));
239 vertex.
add_data3(position + LVertex(0.0f, 0.0f, neg_radius));
254 _lines->add_next_vertices(2);
255 _lines->close_primitive();
256 _lines->add_next_vertices(2);
257 _lines->close_primitive();
258 _lines->add_next_vertices(2);
259 _lines->close_primitive();
260 _lines->add_next_vertices(2);
261 _lines->close_primitive();
262 _lines->add_next_vertices(2);
263 _lines->close_primitive();
264 _lines->add_next_vertices(2);
265 _lines->close_primitive();
267 remaining_particles--;
268 if (remaining_particles == 0) {
275 LPoint3 aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f);
276 PN_stdfloat radius = (aabb_center - _aabb_min).length();
279 _line_primitive->set_bounds(&sphere);
292 out<<
"SparkleParticleRenderer";
303 write(ostream &out,
int indent_level)
const {
304 indent(out, indent_level) <<
"SparkleParticleRenderer:\n";
305 indent(out, indent_level + 2) <<
"_center_color "<<_center_color<<
"\n";
306 indent(out, indent_level + 2) <<
"_edge_color "<<_edge_color<<
"\n";
307 indent(out, indent_level + 2) <<
"_birth_radius "<<_birth_radius<<
"\n";
308 indent(out, indent_level + 2) <<
"_death_radius "<<_death_radius<<
"\n";
309 indent(out, indent_level + 2) <<
"_line_primitive "<<_line_primitive<<
"\n";
310 indent(out, indent_level + 2) <<
"_max_pool_size "<<_max_pool_size<<
"\n";
311 indent(out, indent_level + 2) <<
"_life_scale "<<_life_scale<<
"\n";
312 indent(out, indent_level + 2) <<
"_aabb_min "<<_aabb_min<<
"\n";
313 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...
SparkleParticleRenderer()
Default Constructor.
This defines a bounding sphere, consisting of a center and a radius.
A body on which physics will be applied.
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. ...
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual ~SparkleParticleRenderer()
Destructor.
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. ...
virtual BaseParticleRenderer * make_copy()
child virtual for spawning systems
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.
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.