15 #include "pointParticleRenderer.h" 16 #include "boundingSphere.h" 19 #include "geomVertexWriter.h" 21 #include "pStatTimer.h" 23 PStatCollector PointParticleRenderer::_render_collector(
"App:Particles:Point:Render");
33 PN_stdfloat point_size,
34 PointParticleBlendType bt,
35 ParticleRendererBlendMethod bm,
38 _start_color(sc), _end_color(ec),
39 _blend_type(bt), _blend_method(bm)
41 set_point_size(point_size);
55 _blend_type = copy._blend_type;
56 _blend_method = copy._blend_method;
57 _start_color = copy._start_color;
58 _end_color = copy._end_color;
59 _point_size = copy._point_size;
92 void PointParticleRenderer::
93 resize_pool(
int new_size) {
94 if (new_size == _max_pool_size)
97 _max_pool_size = new_size;
108 void PointParticleRenderer::
111 (
"point_particles", GeomVertexFormat::get_v3cp(),
114 _point_primitive = geom;
116 geom->add_primitive(_points);
120 render_node->
add_geom(_point_primitive, _render_state->add_attrib(_thick));
129 void PointParticleRenderer::
130 birth_particle(
int) {
139 void PointParticleRenderer::
149 LColor PointParticleRenderer::
152 PN_stdfloat life_t, vel_t;
153 PN_stdfloat parameterized_age = 1.0f;
154 bool have_alpha_t =
false;
156 switch (_blend_type) {
161 color = _start_color;
167 parameterized_age = p->get_parameterized_age();
168 life_t = parameterized_age;
171 if (_blend_method == PP_BLEND_CUBIC)
172 life_t = CUBIC_T(life_t);
174 color = LERP(life_t, _start_color, _end_color);
181 vel_t = p->get_parameterized_vel();
183 if (_blend_method == PP_BLEND_CUBIC)
184 vel_t = CUBIC_T(vel_t);
186 color = LERP(vel_t, _start_color, _end_color);
193 if(_alpha_mode != PR_ALPHA_NONE) {
194 if(_alpha_mode == PR_ALPHA_USER) {
195 parameterized_age = 1.0;
198 parameterized_age = p->get_parameterized_age();
200 if(_alpha_mode==PR_ALPHA_OUT) {
201 parameterized_age = 1.0f - parameterized_age;
202 }
else if(_alpha_mode==PR_ALPHA_IN_OUT) {
203 parameterized_age = 2.0f * min(parameterized_age,
204 1.0f - parameterized_age);
219 void PointParticleRenderer::
225 int remaining_particles = ttl_particles;
233 _aabb_min.set(99999.0f, 99999.0f, 99999.0f);
234 _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
238 for (i = 0; i < (int)po_vector.size(); i++) {
241 if (!cur_particle->get_alive())
248 if (position[0] > _aabb_max[0])
249 _aabb_max[0] = position[0];
250 else if (position[0] < _aabb_min[0])
251 _aabb_min[0] = position[0];
255 if (position[1] > _aabb_max[1])
256 _aabb_max[1] = position[1];
257 else if (position[1] < _aabb_min[1])
258 _aabb_min[1] = position[1];
262 if (position[2] > _aabb_max[2])
263 _aabb_max[2] = position[2];
264 else if (position[2] < _aabb_min[2])
265 _aabb_min[2] = position[2];
270 color.
add_data4(create_color(cur_particle));
274 remaining_particles--;
275 if (remaining_particles == 0)
279 _points->clear_vertices();
280 _points->add_next_vertices(ttl_particles);
284 LPoint3 aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f);
285 PN_stdfloat radius = (aabb_center - _aabb_min).length();
288 _point_primitive->set_bounds(&sphere);
301 out<<
"PointParticleRenderer";
312 write(ostream &out,
int indent_level)
const {
313 indent(out, indent_level) <<
"PointParticleRenderer:\n";
314 indent(out, indent_level + 2) <<
"_start_color "<<_start_color<<
"\n";
315 indent(out, indent_level + 2) <<
"_end_color "<<_end_color<<
"\n";
316 indent(out, indent_level + 2) <<
"_point_size "<<_point_size<<
"\n";
317 indent(out, indent_level + 2) <<
"_point_primitive "<<_point_primitive<<
"\n";
318 indent(out, indent_level + 2) <<
"_max_pool_size "<<_max_pool_size<<
"\n";
319 indent(out, indent_level + 2) <<
"_blend_type "<<_blend_type<<
"\n";
320 indent(out, indent_level + 2) <<
"_blend_method "<<_blend_method<<
"\n";
321 indent(out, indent_level + 2) <<
"_aabb_min "<<_aabb_min<<
"\n";
322 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...
Defines a series of disconnected points.
This defines a bounding sphere, consisting of a center and a radius.
A body on which physics will be applied.
PointParticleRenderer(const PointParticleRenderer ©)
Copy constructor.
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 BaseParticleRenderer * make_copy()
for spawning systems from dead particles
This is our own Panda specialization on the default STL vector.
virtual void write(ostream &out, int indent_level=0) 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...
Pure virtual particle renderer base class.
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual ~PointParticleRenderer()
Simple destructor.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Simple point/point particle renderer.
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. ...
PN_stdfloat get_user_alpha() const
gets alpha for "user" alpha mode
This is the base class for all three-component vectors and points.
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.