00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "lineParticleRenderer.h"
00020
00021 #include <boundingSphere.h>
00022
00023
00024
00025
00026
00027
00028
00029 LineParticleRenderer::
00030 LineParticleRenderer(void) :
00031 _head_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)),
00032 _tail_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)) {
00033 _line_primitive = new GeomLine;
00034 init_geoms();
00035 }
00036
00037
00038
00039
00040
00041
00042
00043 LineParticleRenderer::
00044 LineParticleRenderer(const Colorf& head,
00045 const Colorf& tail,
00046 ParticleRendererAlphaMode alpha_mode) :
00047 BaseParticleRenderer(alpha_mode),
00048 _head_color(head), _tail_color(tail)
00049 {
00050 _line_primitive = new GeomLine;
00051 init_geoms();
00052 }
00053
00054
00055
00056
00057
00058
00059
00060 LineParticleRenderer::
00061 LineParticleRenderer(const LineParticleRenderer& copy) :
00062 BaseParticleRenderer(copy) {
00063 _head_color = copy._head_color;
00064 _tail_color = copy._tail_color;
00065
00066 _line_primitive = new GeomLine;
00067 init_geoms();
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 LineParticleRenderer::
00077 ~LineParticleRenderer(void) {
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 BaseParticleRenderer *LineParticleRenderer::
00087 make_copy(void) {
00088 return new LineParticleRenderer(*this);
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 void LineParticleRenderer::
00098 birth_particle(int) {
00099 }
00100
00101
00102
00103
00104
00105
00106
00107 void LineParticleRenderer::
00108 kill_particle(int) {
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118 void LineParticleRenderer::
00119 resize_pool(int new_size) {
00120 _vertex_array = PTA_Vertexf::empty_array(new_size * 2);
00121 _color_array = PTA_Colorf::empty_array(new_size * 2);
00122
00123 _line_primitive->set_coords(_vertex_array);
00124 _line_primitive->set_colors(_color_array, G_PER_VERTEX);
00125
00126 _max_pool_size = new_size;
00127
00128 init_geoms();
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 void LineParticleRenderer::
00138 init_geoms(void) {
00139 _line_primitive->set_num_prims(0);
00140
00141 GeomNode *render_node = get_render_node();
00142 render_node->remove_all_geoms();
00143 render_node->add_geom(_line_primitive, _render_state);
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 void LineParticleRenderer::
00153 render(pvector< PT(PhysicsObject) >& po_vector, int ttl_particles) {
00154
00155 if (!ttl_particles)
00156 return;
00157
00158 BaseParticle *cur_particle;
00159
00160 int remaining_particles = ttl_particles;
00161 int i;
00162
00163 Vertexf *cur_vert = &_vertex_array[0];
00164 Colorf *cur_color = &_color_array[0];
00165
00166
00167
00168 _aabb_min.set(99999.0f, 99999.0f, 99999.0f);
00169 _aabb_max.set(-99999.0f, -99999.0f, -99999.0f);
00170
00171
00172
00173 for (i = 0; i < (int)po_vector.size(); i++) {
00174 cur_particle = (BaseParticle *) po_vector[i].p();
00175
00176 if (cur_particle->get_alive() == false)
00177 continue;
00178
00179 LPoint3f pos = cur_particle->get_position();
00180
00181
00182
00183 if (pos.get_x() > _aabb_max.get_x())
00184 _aabb_max[0] = pos.get_x();
00185 if (pos.get_x() < _aabb_min.get_x())
00186 _aabb_min[0] = pos.get_x();
00187
00188 if (pos.get_y() > _aabb_max.get_y())
00189 _aabb_max[1] = pos.get_y();
00190 if (pos.get_y() < _aabb_min.get_y())
00191 _aabb_min[1] = pos.get_y();
00192
00193 if (pos.get_z() > _aabb_max.get_z())
00194 _aabb_max[2] = pos.get_z();
00195 if (pos.get_z() < _aabb_min.get_z())
00196 _aabb_min[2] = pos.get_z();
00197
00198
00199
00200 Colorf head_color = _head_color;
00201 Colorf tail_color = _tail_color;
00202
00203
00204
00205 if (_alpha_mode != PR_ALPHA_NONE) {
00206
00207 float alpha;
00208
00209 if (_alpha_mode == PR_ALPHA_USER) {
00210 alpha = get_user_alpha();
00211 } else {
00212 alpha = cur_particle->get_parameterized_age();
00213 if (_alpha_mode == PR_ALPHA_OUT)
00214 alpha = 1.0f - alpha;
00215 }
00216
00217 head_color[3] = alpha;
00218 tail_color[3] = alpha;
00219 }
00220
00221
00222
00223 *cur_vert++ = pos;
00224 *cur_vert++ = cur_particle->get_last_position();
00225
00226 *cur_color++ = head_color;
00227 *cur_color++ = tail_color;
00228
00229 remaining_particles--;
00230 if (remaining_particles == 0)
00231 break;
00232 }
00233
00234 _line_primitive->set_num_prims(ttl_particles);
00235
00236
00237
00238 LPoint3f aabb_center = (_aabb_min + _aabb_max) * 0.5f;
00239 float radius = (aabb_center - _aabb_min).length();
00240
00241 _line_primitive->set_bound(BoundingSphere(aabb_center, radius));
00242 get_render_node()->mark_bound_stale();
00243 }