22PStatCollector GeomParticleRenderer::_render_collector(
"App:Particles:Geom:Render");
30 BaseParticleRenderer(am),
31 _geom_node(geom_node),
34 _initial_x_scale(1.0f),
36 _initial_y_scale(1.0f),
38 _initial_z_scale(1.0f),
40 _animate_x_ratio(false),
41 _animate_y_ratio(false),
42 _animate_z_ratio(false)
44 if (_geom_node.is_null())
54 BaseParticleRenderer(copy),
56 _initial_x_scale(copy._initial_x_scale),
57 _final_x_scale(copy._final_x_scale),
58 _initial_y_scale(copy._initial_y_scale),
59 _final_y_scale(copy._final_y_scale),
60 _initial_z_scale(copy._initial_z_scale),
61 _final_z_scale(copy._final_z_scale),
62 _animate_x_ratio(copy._animate_x_ratio),
63 _animate_y_ratio(copy._animate_y_ratio),
64 _animate_z_ratio(copy._animate_z_ratio)
66 _geom_node = copy._geom_node;
90void GeomParticleRenderer::
99void GeomParticleRenderer::
100resize_pool(
int new_size) {
107 for (i = 0; i < new_size; i++) {
108 _node_vector.push_back(
nullptr);
111 _pool_size = new_size;
118void GeomParticleRenderer::
120 pvector< PT(PandaNode) >::iterator vec_iter = _node_vector.begin();
123 for (; vec_iter != _node_vector.end(); vec_iter++) {
124 PandaNode *node = *vec_iter;
125 if (node !=
nullptr) {
130 _node_vector.erase(_node_vector.begin(), _node_vector.end());
137void GeomParticleRenderer::
138birth_particle(
int index) {
139 if (_node_vector[index] ==
nullptr) {
140 PandaNode *node =
new PandaNode(
"");
143 _node_vector[index] = node;
151void GeomParticleRenderer::
152kill_particle(
int index) {
153 if (_node_vector[index] !=
nullptr) {
155 _node_vector[index] =
nullptr;
163void GeomParticleRenderer::
164render(pvector< PT(
PhysicsObject) >& po_vector,
int ttl_particles) {
165 PStatTimer t1(_render_collector);
167 BaseParticle *cur_particle;
168 int i, remaining_particles = ttl_particles;
170 pvector< PT(PandaNode) >::iterator cur_node_iter = _node_vector.begin();
174 for (i = 0; i < (int)po_vector.size(); i++) {
177 cur_particle = (BaseParticle *) po_vector[i].p();
178 cur_node = *cur_node_iter;
180 if (cur_particle->get_alive()) {
182 if (cur_node ==
nullptr) {
184 cur_node = *cur_node_iter;
186 nassertv(cur_node !=
nullptr);
190 PN_stdfloat t = cur_particle->get_parameterized_age();
191 LColor c = _color_interpolation_manager->generateColor(t);
193 if ((_alpha_mode != PR_ALPHA_NONE)) {
194 PN_stdfloat alpha_scalar;
196 if(_alpha_mode == PR_ALPHA_USER) {
200 if (_alpha_mode == PR_ALPHA_OUT)
201 alpha_scalar = 1.0f - alpha_scalar;
202 else if (_alpha_mode == PR_ALPHA_IN_OUT)
203 alpha_scalar = 2.0f * std::min(alpha_scalar, 1.0f - alpha_scalar);
207 c[3] *= alpha_scalar;
209 (LColor(1.0f, 1.0f, 1.0f, c[3])));
215 PN_stdfloat current_x_scale = _initial_x_scale;
216 PN_stdfloat current_y_scale = _initial_y_scale;
217 PN_stdfloat current_z_scale = _initial_z_scale;
219 if (_animate_x_ratio || _animate_y_ratio || _animate_z_ratio) {
220 if (_animate_x_ratio) {
221 current_x_scale = (_initial_x_scale +
222 (t * (_final_x_scale - _initial_x_scale)));
224 if (_animate_y_ratio) {
225 current_y_scale = (_initial_y_scale +
226 (t * (_final_y_scale - _initial_y_scale)));
228 if (_animate_z_ratio) {
229 current_z_scale = (_initial_z_scale +
230 (t * (_final_z_scale - _initial_z_scale)));
237 LVecBase3(current_x_scale, current_y_scale, current_z_scale)));
241 remaining_particles--;
243 if (remaining_particles == 0)
255output(std::ostream &out)
const {
257 out<<
"GeomParticleRenderer";
268 out<<
""<<
"_node_vector ("<<_node_vector.size()<<
" forces)\n";
270 i != _node_vector.end();
272 (*i)->write(out,
indent+2);
283 out.width(
indent); out<<
""; out<<
"GeomParticleRenderer:\n";
284 out.width(
indent+2); out<<
""; out<<
"_geom_node "<<_geom_node<<
"\n";
285 out.width(
indent+2); out<<
""; out<<
"_pool_size "<<_pool_size<<
"\n";
287 out.width(
indent+2); out<<
""; out<<
"_initial_x_scale "<<_initial_x_scale<<
"\n";
288 out.width(
indent+2); out<<
""; out<<
"_final_x_scale "<<_final_x_scale<<
"\n";
289 out.width(
indent+2); out<<
""; out<<
"_initial_y_scale "<<_initial_y_scale<<
"\n";
290 out.width(
indent+2); out<<
""; out<<
"_final_y_scale "<<_final_y_scale<<
"\n";
291 out.width(
indent+2); out<<
""; out<<
"_initial_z_scale "<<_initial_z_scale<<
"\n";
292 out.width(
indent+2); out<<
""; out<<
"_final_z_scale "<<_final_z_scale<<
"\n";
293 out.width(
indent+2); out<<
""; out<<
"_animate_x_ratio "<<_animate_x_ratio<<
"\n";
294 out.width(
indent+2); out<<
""; out<<
"_animate_y_ratio "<<_animate_y_ratio<<
"\n";
295 out.width(
indent+2); out<<
""; out<<
"_animate_z_ratio "<<_animate_z_ratio<<
"\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>.
static ConstPointerTo< RenderAttrib > make_flat(const LColor &color)
Constructs a new ColorAttrib object that indicates geometry should be rendered in the indicated color...
High level class for color interpolation.
static ConstPointerTo< RenderAttrib > make(const LVecBase4 &scale)
Constructs a new ColorScaleAttrib object that indicates geometry should be scaled by the indicated fa...
virtual ~GeomParticleRenderer()
destructor
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
virtual BaseParticleRenderer * make_copy()
dynamic copying
virtual void write_linear_forces(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
GeomParticleRenderer(ParticleRendererAlphaMode am=PR_ALPHA_NONE, PandaNode *geom_node=nullptr)
constructor
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.
A basic node of the scene graph or data graph.
void remove_child(int child_index, Thread *current_thread=Thread::get_current_thread())
Removes the nth child from the node.
set_state
Sets the complete RenderState that will be applied to all nodes at this level and below.
set_transform
Sets the transform that will be applied to this node and below.
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_attrib(const RenderAttrib *attrib, int override=0)
Adds the indicated render attribute to the scene graph on this node.
A body on which physics will be applied.
get_position
Position Query.
get_orientation
get current orientation.
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.