*** empty log message ***

This commit is contained in:
Darren Ranalli 2000-10-11 23:48:59 +00:00
parent 3ca8c86cf0
commit bcd675aa89
5 changed files with 361 additions and 2 deletions

View File

@ -34,7 +34,8 @@
spriteParticleRenderer.h tangentRingEmitter.I \
tangentRingEmitter.cxx tangentRingEmitter.h zSpinParticle.I \
zSpinParticle.cxx zSpinParticle.h zSpinParticleFactory.I \
zSpinParticleFactory.cxx zSpinParticleFactory.h
zSpinParticleFactory.cxx zSpinParticleFactory.h \
particleCommonFuncs.h
#define INSTALL_HEADERS \
baseParticle.I baseParticle.h baseParticleEmitter.I \
@ -55,7 +56,8 @@
sphereSurfaceEmitter.h sphereVolumeEmitter.I sphereVolumeEmitter.h \
spriteParticleRenderer.I spriteParticleRenderer.h \
tangentRingEmitter.I tangentRingEmitter.h zSpinParticle.I \
zSpinParticle.h zSpinParticleFactory.I zSpinParticleFactory.h
zSpinParticle.h zSpinParticleFactory.I zSpinParticleFactory.h \
particleCommonFuncs.h
#define IGATESCAN all

View File

@ -0,0 +1,40 @@
// Filename: lineParticleRenderer.I
// Created by: darren (06Oct00)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function : set_head_color
// Access : public
////////////////////////////////////////////////////////////////////
INLINE void LineParticleRenderer::
set_head_color(const Colorf& c) {
_head_color = c;
}
////////////////////////////////////////////////////////////////////
// Function : set_tail_color
// Access : public
////////////////////////////////////////////////////////////////////
INLINE void LineParticleRenderer::
set_tail_color(const Colorf& c) {
_tail_color = c;
}
////////////////////////////////////////////////////////////////////
// Function : get_head_color
// Access : public
////////////////////////////////////////////////////////////////////
INLINE const Colorf& LineParticleRenderer::
get_head_color(void) const {
return _head_color;
}
////////////////////////////////////////////////////////////////////
// Function : get_tail_color
// Access : public
////////////////////////////////////////////////////////////////////
INLINE const Colorf& LineParticleRenderer::
get_tail_color(void) const {
return _tail_color;
}

View File

@ -0,0 +1,219 @@
// Filename: lineParticleRenderer.cxx
// Created by: darren (06Oct00)
//
////////////////////////////////////////////////////////////////////
#include "lineParticleRenderer.h"
#include <boundingSphere.h>
////////////////////////////////////////////////////////////////////
// Function : LineParticleRenderer
// Access : Public
// Description : Default Constructor
////////////////////////////////////////////////////////////////////
LineParticleRenderer::
LineParticleRenderer(void) :
_head_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)),
_tail_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)) {
_line_primitive = new GeomLine;
init_geoms();
}
////////////////////////////////////////////////////////////////////
// Function : LineParticleRenderer
// Access : Public
// Description : Constructor
////////////////////////////////////////////////////////////////////
LineParticleRenderer::
LineParticleRenderer(const Colorf& head,
const Colorf& tail,
ParticleRendererAlphaMode alpha_mode) :
_head_color(head), _tail_color(tail),
BaseParticleRenderer(alpha_mode) {
_line_primitive = new GeomLine;
init_geoms();
}
////////////////////////////////////////////////////////////////////
// Function : LineParticleRenderer
// Access : Public
// Description : Copy Constructor
////////////////////////////////////////////////////////////////////
LineParticleRenderer::
LineParticleRenderer(const LineParticleRenderer& copy) :
BaseParticleRenderer(copy) {
_head_color = copy._head_color;
_tail_color = copy._tail_color;
_line_primitive = new GeomLine;
init_geoms();
}
////////////////////////////////////////////////////////////////////
// Function : ~LineParticleRenderer
// Access : Public
// Description : Destructor
////////////////////////////////////////////////////////////////////
LineParticleRenderer::
~LineParticleRenderer(void) {
}
////////////////////////////////////////////////////////////////////
// Function : make copy
// Access : Public
// Description : child virtual for spawning systems
////////////////////////////////////////////////////////////////////
BaseParticleRenderer *LineParticleRenderer::
make_copy(void) {
return new LineParticleRenderer(*this);
}
////////////////////////////////////////////////////////////////////
// Function : birth_particle
// Access : Private, virtual
// Description : child birth
////////////////////////////////////////////////////////////////////
void LineParticleRenderer::
birth_particle(int) {
}
////////////////////////////////////////////////////////////////////
// Function : kill_particle
// Access : Private, virtual
// Description : child kill
////////////////////////////////////////////////////////////////////
void LineParticleRenderer::
kill_particle(int) {
}
////////////////////////////////////////////////////////////////////
// Function : resize_pool
// Access : private
// Description : resizes the render pool. Reference counting
// makes this easy.
////////////////////////////////////////////////////////////////////
void LineParticleRenderer::
resize_pool(int new_size) {
_vertex_array = PTA_Vertexf(new_size * 2);
_color_array = PTA_Colorf(new_size * 2);
_line_primitive->set_coords(_vertex_array, G_PER_VERTEX);
_line_primitive->set_colors(_color_array, G_PER_VERTEX);
_max_pool_size = new_size;
}
////////////////////////////////////////////////////////////////////
// Function : init_geoms
// Access : private
// Description : initializes the geomnodes
////////////////////////////////////////////////////////////////////
void LineParticleRenderer::
init_geoms(void) {
_line_primitive->set_num_prims(0);
_interface_node->clear();
_interface_node->add_geom(_line_primitive);
}
////////////////////////////////////////////////////////////////////
// Function : render
// Access : private
// Description : populates the GeomLine
////////////////////////////////////////////////////////////////////
void LineParticleRenderer::
render(vector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
if (!ttl_particles)
return;
BaseParticle *cur_particle;
int cur_index = 0;
int remaining_particles = ttl_particles;
int i;
Vertexf *cur_vert = &_vertex_array[0];
Colorf *cur_color = &_color_array[0];
// init the aabb
_aabb_min.set(99999.0f, 99999.0f, 99999.0f);
_aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
// run through the array
for (i = 0; i < po_vector.size(); i++) {
cur_particle = (BaseParticle *) po_vector[i].p();
if (cur_particle->get_alive() == false)
continue;
// adjust the aabb
if (cur_particle->get_position().get_x() > _aabb_max.get_x())
_aabb_max[0] = cur_particle->get_position().get_x();
else if (cur_particle->get_position().get_x() < _aabb_min.get_x())
_aabb_min[0] = cur_particle->get_position().get_x();
if (cur_particle->get_position().get_y() > _aabb_max.get_y())
_aabb_max[1] = cur_particle->get_position().get_y();
else if (cur_particle->get_position().get_y() < _aabb_min.get_y())
_aabb_min[1] = cur_particle->get_position().get_y();
if (cur_particle->get_position().get_z() > _aabb_max.get_z())
_aabb_max[2] = cur_particle->get_position().get_z();
else if (cur_particle->get_position().get_z() < _aabb_min.get_z())
_aabb_min[2] = cur_particle->get_position().get_z();
// draw the particle.
LPoint3f pos = cur_particle->get_position();
Colorf head_color = _head_color;
Colorf tail_color = _tail_color;
// handle alpha
if (_alpha_mode != PR_ALPHA_NONE) {
float alpha = cur_particle->get_parameterized_age();
if (_alpha_mode == PR_ALPHA_OUT)
alpha = 1.0f - alpha;
head_color[3] = alpha;
tail_color[3] = alpha;
}
// 1 line from current position to last position
*cur_vert++ = cur_particle->get_position();
*cur_vert++ = cur_particle->get_last_position();
*cur_color++ = head_color;
*cur_color++ = tail_color;
remaining_particles--;
if (remaining_particles == 0)
break;
}
_line_primitive->set_num_prims(ttl_particles);
// done filling geomline node, now do the bb stuff
LPoint3f aabb_center = _aabb_min + ((_aabb_max - _aabb_min) * 0.5f);
float radius = (aabb_center - _aabb_min).length();
_interface_node->set_bound(BoundingSphere(aabb_center, radius));
}

View File

@ -0,0 +1,66 @@
// Filename: lineParticleRenderer.h
// Created by: darren (06Oct00)
//
////////////////////////////////////////////////////////////////////
#ifndef LINEPARTICLERENDERER_H
#define LINEPARTICLERENDERER_H
#include "baseParticle.h"
#include "baseParticleRenderer.h"
#include <pointerTo.h>
#include <pointerToArray.h>
#include <geom.h>
#include <geomLine.h>
////////////////////////////////////////////////////////////////////
// Class : LineParticleRenderer
// Description : renders a line from last position to current
// position -- good for rain, sparks, etc.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAPHYSICS LineParticleRenderer : public BaseParticleRenderer {
private:
Colorf _head_color;
Colorf _tail_color;
PT(GeomLine) _line_primitive;
PTA_Vertexf _vertex_array;
PTA_Colorf _color_array;
int _max_pool_size;
LPoint3f _aabb_min, _aabb_max;
virtual void birth_particle(int index);
virtual void kill_particle(int index);
virtual void init_geoms(void);
virtual void render(vector< PT(PhysicsObject) >& po_vector,
int ttl_particles);
virtual void resize_pool(int new_size);
public:
LineParticleRenderer(void);
LineParticleRenderer(const LineParticleRenderer& copy);
LineParticleRenderer(const Colorf& head,
const Colorf& tail,
ParticleRendererAlphaMode alpha_mode);
virtual ~LineParticleRenderer(void);
virtual BaseParticleRenderer *make_copy(void);
INLINE void set_head_color(const Colorf& c);
INLINE void set_tail_color(const Colorf& c);
INLINE const Colorf& get_head_color(void) const;
INLINE const Colorf& get_tail_color(void) const;
};
#include "lineParticleRenderer.I"
#endif // LINEPARTICLERENDERER_H

View File

@ -0,0 +1,32 @@
// Filename: particleCommonFuncs.h
// Created by: darren (02Oct00)
//
////////////////////////////////////////////////////////////////////
#ifndef PARTICLECOMMONFUNCS_H
#define PARTICLECOMMONFUNCS_H
// evaluates to a float in the range [0,1]
#define NORMALIZED_RAND() ((float)rand() / (float)RAND_MAX)
// linear interpolation
// t is in [0,1]
// result is in [X0,X1]
#define LERP(t,X0,X1) ((X0) + ((t) * ((X1) - (X0))))
// linear t -> cubic t
// t is in [0,1]
// result is in [0,1]
#define CUBIC_T(t) ((t)*(t)*(3-(2*(t))))
// cubic interpolation
// t is in [0,1]
// result is in [X0,X1]
#define CLERP(t,X0,X1) LERP(CUBIC_T(t), (X0), (X1))
// spread calculator
// spread is non-negative spread magnitude
// result is in [-spread,spread]
#define SPREAD(magnitude) ((magnitude) - (NORMALIZED_RAND() * 2.0f * (magnitude)))
#endif // PARTICLECOMMONFUNCS_H