15 #include "geomParticleRenderer.h"
16 #include "baseParticle.h"
18 #include "transformState.h"
19 #include "colorScaleAttrib.h"
20 #include "colorAttrib.h"
21 #include "pStatTimer.h"
23 PStatCollector GeomParticleRenderer::_render_collector(
"App:Particles:Geom:Render");
34 _geom_node(geom_node),
37 _initial_x_scale(1.0f),
39 _initial_y_scale(1.0f),
41 _initial_z_scale(1.0f),
43 _animate_x_ratio(false),
44 _animate_y_ratio(false),
45 _animate_z_ratio(false)
47 if (_geom_node.is_null())
61 _initial_x_scale(copy._initial_x_scale),
62 _final_x_scale(copy._final_x_scale),
63 _initial_y_scale(copy._initial_y_scale),
64 _final_y_scale(copy._final_y_scale),
65 _initial_z_scale(copy._initial_z_scale),
66 _final_z_scale(copy._final_z_scale),
67 _animate_x_ratio(copy._animate_x_ratio),
68 _animate_y_ratio(copy._animate_y_ratio),
69 _animate_z_ratio(copy._animate_z_ratio)
71 _geom_node = copy._geom_node;
101 void GeomParticleRenderer::
112 void GeomParticleRenderer::
113 resize_pool(
int new_size) {
120 for (i = 0; i < new_size; i++) {
121 _node_vector.push_back(NULL);
124 _pool_size = new_size;
132 void GeomParticleRenderer::
137 for (; vec_iter != _node_vector.end(); vec_iter++) {
144 _node_vector.erase(_node_vector.begin(), _node_vector.end());
153 void GeomParticleRenderer::
154 birth_particle(
int index) {
155 if (_node_vector[index] == (
PandaNode *)NULL) {
159 _node_vector[index] = node;
169 void GeomParticleRenderer::
170 kill_particle(
int index) {
171 if (_node_vector[index] != (
PandaNode *)NULL) {
183 void GeomParticleRenderer::
188 int i, remaining_particles = ttl_particles;
194 for (i = 0; i < (int)po_vector.size(); i++) {
198 cur_node = *cur_node_iter;
200 if (cur_particle->get_alive()) {
204 cur_node = *cur_node_iter;
210 PN_stdfloat t = cur_particle->get_parameterized_age();
211 LColor c = _color_interpolation_manager->generateColor(t);
213 if ((_alpha_mode != PR_ALPHA_NONE)) {
214 PN_stdfloat alpha_scalar;
216 if(_alpha_mode == PR_ALPHA_USER) {
220 if (_alpha_mode == PR_ALPHA_OUT)
221 alpha_scalar = 1.0f - alpha_scalar;
222 else if (_alpha_mode == PR_ALPHA_IN_OUT)
223 alpha_scalar = 2.0f * min(alpha_scalar, 1.0f - alpha_scalar);
227 c[3] *= alpha_scalar;
229 (
LColor(1.0f, 1.0f, 1.0f, c[3])));
232 cur_node->
set_attrib(ColorAttrib::make_flat(c), 0);
235 PN_stdfloat current_x_scale = _initial_x_scale;
236 PN_stdfloat current_y_scale = _initial_y_scale;
237 PN_stdfloat current_z_scale = _initial_z_scale;
239 if (_animate_x_ratio || _animate_y_ratio || _animate_z_ratio) {
240 if (_animate_x_ratio) {
241 current_x_scale = (_initial_x_scale +
242 (t * (_final_x_scale - _initial_x_scale)));
244 if (_animate_y_ratio) {
245 current_y_scale = (_initial_y_scale +
246 (t * (_final_y_scale - _initial_y_scale)));
248 if (_animate_z_ratio) {
249 current_z_scale = (_initial_z_scale +
250 (t * (_final_z_scale - _initial_z_scale)));
257 LVecBase3(current_x_scale, current_y_scale, current_z_scale)));
261 remaining_particles--;
263 if (remaining_particles == 0)
280 out<<
"GeomParticleRenderer";
294 out<<
""<<
"_node_vector ("<<_node_vector.size()<<
" forces)\n";
296 i != _node_vector.end();
298 (*i)->write(out, indent+2);
310 write(ostream &out,
int indent)
const {
312 out.width(indent); out<<
""; out<<
"GeomParticleRenderer:\n";
313 out.width(indent+2); out<<
""; out<<
"_geom_node "<<_geom_node<<
"\n";
314 out.width(indent+2); out<<
""; out<<
"_pool_size "<<_pool_size<<
"\n";
316 out.width(indent+2); out<<
""; out<<
"_initial_x_scale "<<_initial_x_scale<<
"\n";
317 out.width(indent+2); out<<
""; out<<
"_final_x_scale "<<_final_x_scale<<
"\n";
318 out.width(indent+2); out<<
""; out<<
"_initial_y_scale "<<_initial_y_scale<<
"\n";
319 out.width(indent+2); out<<
""; out<<
"_final_y_scale "<<_final_y_scale<<
"\n";
320 out.width(indent+2); out<<
""; out<<
"_initial_z_scale "<<_initial_z_scale<<
"\n";
321 out.width(indent+2); out<<
""; out<<
"_final_z_scale "<<_final_z_scale<<
"\n";
322 out.width(indent+2); out<<
""; out<<
"_animate_x_ratio "<<_animate_x_ratio<<
"\n";
323 out.width(indent+2); out<<
""; out<<
"_animate_y_ratio "<<_animate_y_ratio<<
"\n";
324 out.width(indent+2); out<<
""; out<<
"_animate_z_ratio "<<_animate_z_ratio<<
"\n";
GeomParticleRenderer(ParticleRendererAlphaMode am=PR_ALPHA_NONE, PandaNode *geom_node=(PandaNode *) NULL)
constructor
A basic node of the scene graph or data graph.
LPoint3 get_position() const
Position Query.
This is the base class for all three-component vectors and points.
void remove_child(int child_index, Thread *current_thread=Thread::get_current_thread())
Removes the nth child from the node.
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
PN_stdfloat get_user_alpha() const
gets alpha for "user" alpha mode
A body on which physics will be applied.
LOrientation get_orientation() const
get current orientation.
GeomNode * get_render_node() const
Query the geomnode pointer.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
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.
void set_state(const RenderState *state, Thread *current_thread=Thread::get_current_thread())
Sets the complete RenderState that will be applied to all nodes at this level and below...
High level class for color interpolation.
void set_attrib(const RenderAttrib *attrib, int override=0)
Adds the indicated render attribute to the scene graph on this node.
This is the base class for all three-component vectors and points.
An individual, physically-modelable particle abstract base class.
virtual void write_linear_forces(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
virtual ~GeomParticleRenderer()
destructor
virtual BaseParticleRenderer * make_copy()
dynamic copying
void add_child(PandaNode *child_node, int sort=0, Thread *current_thread=Thread::get_current_thread())
Adds a new child to the node.
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Sets the transform that will be applied to this node and below.