|
@@ -19,8 +19,8 @@
|
|
|
#include "geomParticleRenderer.h"
|
|
#include "geomParticleRenderer.h"
|
|
|
#include "baseParticle.h"
|
|
#include "baseParticle.h"
|
|
|
|
|
|
|
|
-#include <transformTransition.h>
|
|
|
|
|
-#include <colorTransition.h>
|
|
|
|
|
|
|
+#include "transformState.h"
|
|
|
|
|
+#include "colorAttrib.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function : GeomParticleRenderer
|
|
// Function : GeomParticleRenderer
|
|
@@ -29,13 +29,11 @@
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GeomParticleRenderer::
|
|
GeomParticleRenderer::
|
|
|
-GeomParticleRenderer(ParticleRendererAlphaMode am, Node *geom_node) :
|
|
|
|
|
|
|
+GeomParticleRenderer(ParticleRendererAlphaMode am, PandaNode *geom_node) :
|
|
|
BaseParticleRenderer(am), _geom_node(geom_node), _pool_size(0) {
|
|
BaseParticleRenderer(am), _geom_node(geom_node), _pool_size(0) {
|
|
|
|
|
|
|
|
- _dead_particle_parent_node = new Node;
|
|
|
|
|
-
|
|
|
|
|
if (_geom_node.is_null())
|
|
if (_geom_node.is_null())
|
|
|
- _geom_node = _dead_particle_parent_node;
|
|
|
|
|
|
|
+ _geom_node = new PandaNode("empty");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -47,9 +45,6 @@ GeomParticleRenderer(ParticleRendererAlphaMode am, Node *geom_node) :
|
|
|
GeomParticleRenderer::
|
|
GeomParticleRenderer::
|
|
|
GeomParticleRenderer(const GeomParticleRenderer& copy) :
|
|
GeomParticleRenderer(const GeomParticleRenderer& copy) :
|
|
|
BaseParticleRenderer(copy), _pool_size(0) {
|
|
BaseParticleRenderer(copy), _pool_size(0) {
|
|
|
-
|
|
|
|
|
- _dead_particle_parent_node = new Node;
|
|
|
|
|
-
|
|
|
|
|
_geom_node = copy._geom_node;
|
|
_geom_node = copy._geom_node;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -61,7 +56,7 @@ GeomParticleRenderer(const GeomParticleRenderer& copy) :
|
|
|
|
|
|
|
|
GeomParticleRenderer::
|
|
GeomParticleRenderer::
|
|
|
~GeomParticleRenderer(void) {
|
|
~GeomParticleRenderer(void) {
|
|
|
- kill_arcs();
|
|
|
|
|
|
|
+ kill_nodes();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -93,21 +88,39 @@ init_geoms(void) {
|
|
|
|
|
|
|
|
void GeomParticleRenderer::
|
|
void GeomParticleRenderer::
|
|
|
resize_pool(int new_size) {
|
|
resize_pool(int new_size) {
|
|
|
- kill_arcs();
|
|
|
|
|
|
|
+ kill_nodes();
|
|
|
|
|
|
|
|
- // now repopulate the vector
|
|
|
|
|
|
|
+ // now repopulate the vector with a bunch of NULLS, representing
|
|
|
|
|
+ // potential instances of the _geom_node.
|
|
|
|
|
|
|
|
int i;
|
|
int i;
|
|
|
- RenderRelation *rr;
|
|
|
|
|
-
|
|
|
|
|
for (i = 0; i < new_size; i++) {
|
|
for (i = 0; i < new_size; i++) {
|
|
|
- rr = new RenderRelation(_dead_particle_parent_node, _geom_node);
|
|
|
|
|
- _arc_vector.push_back(rr);
|
|
|
|
|
|
|
+ _node_vector.push_back(NULL);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_pool_size = new_size;
|
|
_pool_size = new_size;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function : kill_nodes
|
|
|
|
|
+// Access : private
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+
|
|
|
|
|
+INLINE void GeomParticleRenderer::
|
|
|
|
|
+kill_nodes(void) {
|
|
|
|
|
+ pvector< PT(PandaNode) >::iterator vec_iter = _node_vector.begin();
|
|
|
|
|
+
|
|
|
|
|
+ PandaNode *render_node = get_render_node();
|
|
|
|
|
+ for (; vec_iter != _node_vector.end(); vec_iter++) {
|
|
|
|
|
+ PandaNode *node = *vec_iter;
|
|
|
|
|
+ if (node != (PandaNode *)NULL) {
|
|
|
|
|
+ render_node->remove_child(node);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ _node_vector.erase(_node_vector.begin(), _node_vector.end());
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function : birth_particle
|
|
// Function : birth_particle
|
|
|
// Access : Private, virtual
|
|
// Access : Private, virtual
|
|
@@ -116,7 +129,11 @@ resize_pool(int new_size) {
|
|
|
|
|
|
|
|
void GeomParticleRenderer::
|
|
void GeomParticleRenderer::
|
|
|
birth_particle(int index) {
|
|
birth_particle(int index) {
|
|
|
- _arc_vector[index]->change_parent(_interface_node);
|
|
|
|
|
|
|
+ nassertv(_node_vector[index] == (PandaNode *)NULL);
|
|
|
|
|
+ PandaNode *node = new PandaNode("");
|
|
|
|
|
+ get_render_node()->add_child(node);
|
|
|
|
|
+ node->add_child(_geom_node);
|
|
|
|
|
+ _node_vector[index] = node;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -127,7 +144,8 @@ birth_particle(int index) {
|
|
|
|
|
|
|
|
void GeomParticleRenderer::
|
|
void GeomParticleRenderer::
|
|
|
kill_particle(int index) {
|
|
kill_particle(int index) {
|
|
|
- _arc_vector[index]->change_parent(_dead_particle_parent_node);
|
|
|
|
|
|
|
+ get_render_node()->remove_child(_node_vector[index]);
|
|
|
|
|
+ _node_vector[index] = (PandaNode *)NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -142,41 +160,39 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
|
|
|
LPoint3f pos;
|
|
LPoint3f pos;
|
|
|
int i, remaining_particles = ttl_particles;
|
|
int i, remaining_particles = ttl_particles;
|
|
|
|
|
|
|
|
- pvector< PT(RenderRelation) >::iterator cur_arc_iter = _arc_vector.begin();
|
|
|
|
|
|
|
+ pvector< PT(PandaNode) >::iterator cur_node_iter = _node_vector.begin();
|
|
|
|
|
|
|
|
// run through the particle vector
|
|
// run through the particle vector
|
|
|
|
|
|
|
|
for (i = 0; i < (int)po_vector.size(); i++) {
|
|
for (i = 0; i < (int)po_vector.size(); i++) {
|
|
|
- RenderRelation *cur_arc;
|
|
|
|
|
|
|
+ PandaNode *cur_node;
|
|
|
|
|
|
|
|
cur_particle = (BaseParticle *) po_vector[i].p();
|
|
cur_particle = (BaseParticle *) po_vector[i].p();
|
|
|
- cur_arc = *cur_arc_iter;
|
|
|
|
|
|
|
+ cur_node = *cur_node_iter;
|
|
|
|
|
|
|
|
if (cur_particle->get_alive() == true) {
|
|
if (cur_particle->get_alive() == true) {
|
|
|
// living particle
|
|
// living particle
|
|
|
|
|
|
|
|
pos = cur_particle->get_position();
|
|
pos = cur_particle->get_position();
|
|
|
|
|
|
|
|
- PT(TransformTransition) xform;
|
|
|
|
|
- PT(ColorTransition) alpha;
|
|
|
|
|
- xform = new TransformTransition(LMatrix4f::translate_mat(pos));
|
|
|
|
|
|
|
+ cur_node->set_state(_render_state);
|
|
|
|
|
|
|
|
if ((_alpha_mode != PR_ALPHA_NONE)) {
|
|
if ((_alpha_mode != PR_ALPHA_NONE)) {
|
|
|
float alpha_scalar;
|
|
float alpha_scalar;
|
|
|
|
|
|
|
|
- if(_alpha_mode == PR_ALPHA_USER) {
|
|
|
|
|
- alpha_scalar=get_user_alpha();
|
|
|
|
|
- } else {
|
|
|
|
|
- alpha_scalar = cur_particle->get_parameterized_age();
|
|
|
|
|
- if (_alpha_mode == PR_ALPHA_OUT)
|
|
|
|
|
- alpha_scalar = 1.0f - alpha_scalar;
|
|
|
|
|
|
|
+ if(_alpha_mode == PR_ALPHA_USER) {
|
|
|
|
|
+ alpha_scalar=get_user_alpha();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alpha_scalar = cur_particle->get_parameterized_age();
|
|
|
|
|
+ if (_alpha_mode == PR_ALPHA_OUT)
|
|
|
|
|
+ alpha_scalar = 1.0f - alpha_scalar;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- alpha = new ColorTransition(1.0f, 1.0f, 1.0f, alpha_scalar);
|
|
|
|
|
- cur_arc->set_transition(alpha);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ cur_node->set_attrib(ColorAttrib::make_flat
|
|
|
|
|
+ (Colorf(1.0f, 1.0f, 1.0f, alpha_scalar)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cur_arc->set_transition(xform);
|
|
|
|
|
|
|
+ cur_node->set_transform(TransformState::make_pos(pos));
|
|
|
|
|
|
|
|
// maybe get out early if possible.
|
|
// maybe get out early if possible.
|
|
|
|
|
|
|
@@ -186,6 +202,6 @@ render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- cur_arc_iter++;
|
|
|
|
|
|
|
+ cur_node_iter++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|