22 PStatCollector SparkleParticleRenderer::_render_collector(
"App:Particles:Sparkle:Render");
30 _center_color(LColor(1.0f, 1.0f, 1.0f, 1.0f)),
31 _edge_color(LColor(1.0f, 1.0f, 1.0f, 1.0f)),
32 _birth_radius(0.1f), _death_radius(0.1f)
42 PN_stdfloat birth_radius, PN_stdfloat death_radius,
43 SparkleParticleLifeScale life_scale,
44 ParticleRendererAlphaMode alpha_mode) :
46 _center_color(center), _edge_color(edge), _birth_radius(birth_radius),
47 _death_radius(death_radius), _life_scale(life_scale)
58 _center_color = copy._center_color;
59 _edge_color = copy._edge_color;
60 _birth_radius = copy._birth_radius;
61 _death_radius = copy._death_radius;
62 _life_scale = copy._life_scale;
85 void SparkleParticleRenderer::
92 void SparkleParticleRenderer::
99 void SparkleParticleRenderer::
100 resize_pool(
int new_size) {
101 _max_pool_size = new_size;
109 void SparkleParticleRenderer::
115 _line_primitive = geom;
117 geom->add_primitive(_lines);
121 render_node->
add_geom(_line_primitive, _render_state);
127 void SparkleParticleRenderer::
130 if (!ttl_particles) {
136 int remaining_particles = ttl_particles;
141 _lines->clear_vertices();
145 _aabb_min.set(99999.0f, 99999.0f, 99999.0f);
146 _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
150 for (i = 0; i < (int)po_vector.size(); i++) {
153 if (cur_particle->get_alive() ==
false) {
161 if (position[0] > _aabb_max[0])
162 _aabb_max[0] = position[0];
163 else if (position[0] < _aabb_min[0])
164 _aabb_min[0] = position[0];
166 if (position[1] > _aabb_max[1])
167 _aabb_max[1] = position[1];
168 else if (position[1] < _aabb_min[1])
169 _aabb_min[1] = position[1];
171 if (position[2] > _aabb_max[2])
172 _aabb_max[2] = position[2];
173 else if (position[2] < _aabb_min[2])
174 _aabb_min[2] = position[2];
178 PN_stdfloat radius = get_radius(cur_particle);
179 PN_stdfloat neg_radius = -radius;
182 LColor center_color = _center_color;
183 LColor edge_color = _edge_color;
187 if (_alpha_mode != PR_ALPHA_NONE) {
188 if(_alpha_mode == PR_ALPHA_USER) {
191 alpha = cur_particle->get_parameterized_age();
192 if (_alpha_mode == PR_ALPHA_OUT)
193 alpha = 1.0f - alpha;
194 else if (_alpha_mode == PR_ALPHA_IN_OUT)
195 alpha = 2.0f * std::min(alpha, 1.0f - alpha);
200 center_color[3] = alpha;
201 edge_color[3] = alpha;
206 vertex.add_data3(position);
207 vertex.add_data3(position + LVertex(radius, 0.0f, 0.0f));
208 vertex.add_data3(position);
209 vertex.add_data3(position + LVertex(neg_radius, 0.0f, 0.0f));
210 vertex.add_data3(position);
211 vertex.add_data3(position + LVertex(0.0f, radius, 0.0f));
212 vertex.add_data3(position);
213 vertex.add_data3(position + LVertex(0.0f, neg_radius, 0.0f));
214 vertex.add_data3(position);
215 vertex.add_data3(position + LVertex(0.0f, 0.0f, radius));
216 vertex.add_data3(position);
217 vertex.add_data3(position + LVertex(0.0f, 0.0f, neg_radius));
219 color.add_data4(center_color);
220 color.add_data4(edge_color);
221 color.add_data4(center_color);
222 color.add_data4(edge_color);
223 color.add_data4(center_color);
224 color.add_data4(edge_color);
225 color.add_data4(center_color);
226 color.add_data4(edge_color);
227 color.add_data4(center_color);
228 color.add_data4(edge_color);
229 color.add_data4(center_color);
230 color.add_data4(edge_color);
232 _lines->add_next_vertices(2);
233 _lines->close_primitive();
234 _lines->add_next_vertices(2);
235 _lines->close_primitive();
236 _lines->add_next_vertices(2);
237 _lines->close_primitive();
238 _lines->add_next_vertices(2);
239 _lines->close_primitive();
240 _lines->add_next_vertices(2);
241 _lines->close_primitive();
242 _lines->add_next_vertices(2);
243 _lines->close_primitive();
245 remaining_particles--;
246 if (remaining_particles == 0) {
253 LPoint3 aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f);
254 PN_stdfloat radius = (aabb_center - _aabb_min).length();
257 _line_primitive->set_bounds(&sphere);
267 out<<
"SparkleParticleRenderer";
275 write(std::ostream &out,
int indent_level)
const {
276 indent(out, indent_level) <<
"SparkleParticleRenderer:\n";
277 indent(out, indent_level + 2) <<
"_center_color "<<_center_color<<
"\n";
278 indent(out, indent_level + 2) <<
"_edge_color "<<_edge_color<<
"\n";
279 indent(out, indent_level + 2) <<
"_birth_radius "<<_birth_radius<<
"\n";
280 indent(out, indent_level + 2) <<
"_death_radius "<<_death_radius<<
"\n";
281 indent(out, indent_level + 2) <<
"_line_primitive "<<_line_primitive<<
"\n";
282 indent(out, indent_level + 2) <<
"_max_pool_size "<<_max_pool_size<<
"\n";
283 indent(out, indent_level + 2) <<
"_life_scale "<<_life_scale<<
"\n";
284 indent(out, indent_level + 2) <<
"_aabb_min "<<_aabb_min<<
"\n";
285 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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
SparkleParticleRenderer()
Default Constructor.
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.
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 ~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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An individual, physically-modelable particle abstract base class.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
LPoint3 get_position() const
Position Query.
virtual void write(std::ostream &out, int indent_level=0) const
Write a string representation of this instance to <out>.
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.