22PStatCollector 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) :
46 BaseParticleRenderer(alpha_mode),
47 _head_color(head), _tail_color(tail)
58 BaseParticleRenderer(copy) {
59 _head_color = copy._head_color;
60 _tail_color = copy._tail_color;
86void LineParticleRenderer::
94void LineParticleRenderer::
102void LineParticleRenderer::
103resize_pool(
int new_size) {
104 _max_pool_size = new_size;
113void LineParticleRenderer::
115 _vdata =
new GeomVertexData
118 PT(Geom) geom =
new Geom(_vdata);
119 _line_primitive = geom;
120 _lines =
new GeomLines(Geom::UH_stream);
121 geom->add_primitive(_lines);
125 render_node->
add_geom(_line_primitive, _render_state);
132void LineParticleRenderer::
133render(pvector< PT(
PhysicsObject) >& po_vector,
int ttl_particles) {
134 PStatTimer t1(_render_collector);
139 BaseParticle *cur_particle;
141 int remaining_particles = ttl_particles;
144 GeomVertexWriter vertex(_vdata, InternalName::get_vertex());
145 GeomVertexWriter color(_vdata, InternalName::get_color());
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++) {
156 cur_particle = (BaseParticle *) po_vector[i].p();
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();
226 BoundingSphere sphere(aabb_center, radius);
227 _line_primitive->set_bounds(&sphere);
235output(std::ostream &out)
const {
237 out<<
"LineParticleRenderer";
245write(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";
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.
virtual void write(std::ostream &out, int indent_level=0) const
Write a string representation of this instance to <out>.
virtual BaseParticleRenderer * make_copy()
child virtual for spawning systems
LineParticleRenderer()
Default Constructor.
virtual ~LineParticleRenderer()
Destructor.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
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.
get_last_position
Get the position of the physics object at the start of the most recent do_physics.
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.