22PStatCollector SparkleParticleRenderer::_render_collector(
"App:Particles:Sparkle:Render");
29 BaseParticleRenderer(PR_ALPHA_NONE),
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) :
45 BaseParticleRenderer(alpha_mode),
46 _center_color(center), _edge_color(edge), _birth_radius(birth_radius),
47 _death_radius(death_radius), _life_scale(life_scale)
57 BaseParticleRenderer(copy) {
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;
85void SparkleParticleRenderer::
92void SparkleParticleRenderer::
99void SparkleParticleRenderer::
100resize_pool(
int new_size) {
101 _max_pool_size = new_size;
109void SparkleParticleRenderer::
111 _vdata =
new GeomVertexData
114 PT(Geom) geom =
new Geom(_vdata);
115 _line_primitive = geom;
116 _lines =
new GeomLines(Geom::UH_stream);
117 geom->add_primitive(_lines);
121 render_node->
add_geom(_line_primitive, _render_state);
127void SparkleParticleRenderer::
128render(pvector< PT(
PhysicsObject) >& po_vector,
int ttl_particles) {
129 PStatTimer t1(_render_collector);
130 if (!ttl_particles) {
134 BaseParticle *cur_particle;
136 int remaining_particles = ttl_particles;
139 GeomVertexWriter vertex(_vdata, InternalName::get_vertex());
140 GeomVertexWriter color(_vdata, InternalName::get_color());
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++) {
151 cur_particle = (BaseParticle *) po_vector[i].p();
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();
256 BoundingSphere sphere(aabb_center, radius);
257 _line_primitive->set_bounds(&sphere);
265output(std::ostream &out)
const {
267 out<<
"SparkleParticleRenderer";
275write(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";
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomNode * get_render_node() const
Query the geomnode pointer.
PN_stdfloat get_user_alpha() const
gets alpha for "user" alpha mode
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
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.
A lightweight class that represents a single element that may be timed and/or counted via stats.
void mark_internal_bounds_stale(Thread *current_thread=Thread::get_current_thread())
Should be called by a derived class to mark the internal bounding volume stale, so that compute_inter...
A body on which physics will be applied.
get_position
Position Query.
SparkleParticleRenderer()
Default Constructor.
virtual BaseParticleRenderer * make_copy()
child virtual for spawning systems
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
virtual ~SparkleParticleRenderer()
Destructor.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.