22PStatCollector PointParticleRenderer::_render_collector(
"App:Particles:Point:Render");
29 PN_stdfloat point_size,
30 PointParticleBlendType bt,
31 ParticleRendererBlendMethod bm,
32 const LColor& sc,
const LColor& ec) :
33 BaseParticleRenderer(am),
34 _start_color(sc), _end_color(ec),
35 _blend_type(bt), _blend_method(bm)
37 set_point_size(point_size);
46 BaseParticleRenderer(copy)
48 _blend_type = copy._blend_type;
49 _blend_method = copy._blend_method;
50 _start_color = copy._start_color;
51 _end_color = copy._end_color;
52 _point_size = copy._point_size;
75void PointParticleRenderer::
76resize_pool(
int new_size) {
77 if (new_size == _max_pool_size)
80 _max_pool_size = new_size;
88void PointParticleRenderer::
90 _vdata =
new GeomVertexData
93 PT(Geom) geom =
new Geom(_vdata);
94 _point_primitive = geom;
95 _points =
new GeomPoints(Geom::UH_stream);
96 geom->add_primitive(_points);
100 render_node->
add_geom(_point_primitive, _render_state->add_attrib(_thick));
106void PointParticleRenderer::
113void PointParticleRenderer::
120LColor PointParticleRenderer::
123 PN_stdfloat life_t, vel_t;
124 PN_stdfloat parameterized_age = 1.0f;
125 bool have_alpha_t =
false;
127 switch (_blend_type) {
130 color = _start_color;
135 parameterized_age = p->get_parameterized_age();
136 life_t = parameterized_age;
139 if (_blend_method == PP_BLEND_CUBIC) {
140 life_t = CUBIC_T(life_t);
143 color = LERP(life_t, _start_color, _end_color);
148 vel_t = p->get_parameterized_vel();
150 if (_blend_method == PP_BLEND_CUBIC) {
151 vel_t = CUBIC_T(vel_t);
154 color = LERP(vel_t, _start_color, _end_color);
159 if (_alpha_mode != PR_ALPHA_NONE) {
160 if (_alpha_mode == PR_ALPHA_USER) {
161 parameterized_age = 1.0;
164 parameterized_age = p->get_parameterized_age();
167 if (_alpha_mode == PR_ALPHA_OUT) {
168 parameterized_age = 1.0f - parameterized_age;
169 }
else if (_alpha_mode == PR_ALPHA_IN_OUT) {
170 parameterized_age = 2.0f * std::min(parameterized_age,
171 1.0f - parameterized_age);
183void PointParticleRenderer::
184render(pvector< PT(
PhysicsObject) >& po_vector,
int ttl_particles) {
185 PStatTimer t1(_render_collector);
187 BaseParticle *cur_particle;
189 int remaining_particles = ttl_particles;
192 GeomVertexWriter vertex(_vdata, InternalName::get_vertex());
193 GeomVertexWriter color(_vdata, InternalName::get_color());
197 _aabb_min.set(99999.0f, 99999.0f, 99999.0f);
198 _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
202 for (i = 0; i < (int)po_vector.size(); i++) {
203 cur_particle = (BaseParticle *) po_vector[i].p();
205 if (!cur_particle->get_alive())
212 if (position[0] > _aabb_max[0])
213 _aabb_max[0] = position[0];
214 else if (position[0] < _aabb_min[0])
215 _aabb_min[0] = position[0];
219 if (position[1] > _aabb_max[1])
220 _aabb_max[1] = position[1];
221 else if (position[1] < _aabb_min[1])
222 _aabb_min[1] = position[1];
226 if (position[2] > _aabb_max[2])
227 _aabb_max[2] = position[2];
228 else if (position[2] < _aabb_min[2])
229 _aabb_min[2] = position[2];
233 vertex.add_data3(position);
234 color.add_data4(create_color(cur_particle));
238 remaining_particles--;
239 if (remaining_particles == 0)
243 _points->clear_vertices();
244 _points->add_next_vertices(ttl_particles);
248 LPoint3 aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f);
249 PN_stdfloat radius = (aabb_center - _aabb_min).length();
251 BoundingSphere sphere(aabb_center, radius);
252 _point_primitive->set_bounds(&sphere);
260output(std::ostream &out)
const {
262 out<<
"PointParticleRenderer";
270write(std::ostream &out,
int indent_level)
const {
271 indent(out, indent_level) <<
"PointParticleRenderer:\n";
272 indent(out, indent_level + 2) <<
"_start_color "<<_start_color<<
"\n";
273 indent(out, indent_level + 2) <<
"_end_color "<<_end_color<<
"\n";
274 indent(out, indent_level + 2) <<
"_point_size "<<_point_size<<
"\n";
275 indent(out, indent_level + 2) <<
"_point_primitive "<<_point_primitive<<
"\n";
276 indent(out, indent_level + 2) <<
"_max_pool_size "<<_max_pool_size<<
"\n";
277 indent(out, indent_level + 2) <<
"_blend_type "<<_blend_type<<
"\n";
278 indent(out, indent_level + 2) <<
"_blend_method "<<_blend_method<<
"\n";
279 indent(out, indent_level + 2) <<
"_aabb_min "<<_aabb_min<<
"\n";
280 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>.
An individual, physically-modelable particle abstract base class.
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.
virtual void write(std::ostream &out, int indent_level=0) const
Write a string representation of this instance to <out>.
virtual ~PointParticleRenderer()
Simple destructor.
PointParticleRenderer(const PointParticleRenderer ©)
Copy constructor.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
virtual BaseParticleRenderer * make_copy()
for spawning systems from dead particles
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.