Panda3D
|
00001 // Filename: spriteParticleRenderer.I 00002 // Created by: charles (13Jul00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function : SpriteParticleRenderer::set_texture 00018 // Access : Published 00019 // Description : Sets the renderer up to render the entire texture 00020 // image. The scale of each particle is based on the 00021 // size of the texture in each dimension, modified by 00022 // texels_per_unit. 00023 // 00024 // Used to set the size of the particles. Will clear 00025 // all previously loaded textures and animations. 00026 //////////////////////////////////////////////////////////////////// 00027 INLINE void SpriteParticleRenderer:: 00028 set_texture(Texture *tex, PN_stdfloat texels_per_unit) { 00029 if (tex != (Texture *)NULL) { 00030 // Clear all texture information 00031 _anims.clear(); 00032 00033 // Insert the single texture 00034 _anims.push_back(new SpriteAnim(tex,LTexCoord(0.0f, 0.0f),LTexCoord(1.0f, 1.0f))); 00035 00036 // We scale the particle size by the size of the texture. 00037 set_size(tex->get_x_size() / texels_per_unit, 00038 tex->get_y_size() / texels_per_unit); 00039 get_last_anim()->set_source_info(tex->get_filename()); 00040 } 00041 init_geoms(); 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function : SpriteParticleRenderer::add_texture 00046 // Access : Published 00047 // Description : Adds texture to image pool, effectively creating a 00048 // single frame animation that can be selected at 00049 // particle birth. This should only be called after 00050 // a previous call to set_texture(). 00051 //////////////////////////////////////////////////////////////////// 00052 INLINE void SpriteParticleRenderer:: 00053 add_texture(Texture *tex, PN_stdfloat texels_per_unit, bool resize) { 00054 if (_anims.size() == 0) { 00055 set_texture(tex, texels_per_unit); 00056 } else { 00057 if(tex != (Texture *)NULL) { 00058 if (tex != (Texture *)NULL) { 00059 _anims.push_back(new SpriteAnim(tex,LTexCoord(0.0f, 0.0f),LTexCoord(1.0f, 1.0f))); 00060 } 00061 if(resize) { 00062 // We scale the particle size by the size of the texture. 00063 set_size(tex->get_x_size() / texels_per_unit, 00064 tex->get_y_size() / texels_per_unit); 00065 } 00066 get_last_anim()->set_source_info(tex->get_filename()); 00067 init_geoms(); 00068 } 00069 } 00070 } 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function : SpriteParticleRenderer::remove_animation 00074 // Access : Published 00075 // Description : Removes an animation texture set from the renderer. 00076 //////////////////////////////////////////////////////////////////// 00077 INLINE void SpriteParticleRenderer:: 00078 remove_animation(const int n) { 00079 nassertv(n < (int)_anims.size()); 00080 int i,j; 00081 00082 for (i = 0; i < (int)_anims.size(); ++i) { 00083 for (j = 0; j < (int)_anim_size[i]; ++j) { 00084 _sprites[i][j]->clear_vertices(); 00085 } 00086 } 00087 00088 _anims.erase(_anims.begin()+n); 00089 _animation_removed = true; 00090 init_geoms(); 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function : SpriteParticleRenderer::set_ll_uv 00095 // Access : public 00096 // Description : Sets the UV coordinate of the lower-left corner of 00097 // all the sprites generated by this renderer. Normally 00098 // this is (0, 0), but it might be set to something else 00099 // to use only a portion of the texture. 00100 //////////////////////////////////////////////////////////////////// 00101 INLINE void SpriteParticleRenderer:: 00102 set_ll_uv(const LTexCoord &ll_uv) { 00103 set_ll_uv(ll_uv,0,0); 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function : SpriteParticleRenderer::set_ll_uv 00108 // Access : public 00109 // Description : Sets the UV coordinate of the lower-left corner of 00110 // all the sprites generated by this renderer. Normally 00111 // this is (0, 0), but it might be set to something else 00112 // to use only a portion of the texture. 00113 //////////////////////////////////////////////////////////////////// 00114 INLINE void SpriteParticleRenderer:: 00115 set_ll_uv(const LTexCoord &ll_uv, const int anim, const int frame) { 00116 if(anim < (int)_anims.size() && frame < (int)_anims[anim]->get_num_frames()) { 00117 _anims[anim]->set_ll(frame,ll_uv); 00118 } 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function : SpriteParticleRenderer::set_ur_uv 00123 // Access : public 00124 // Description : Sets the UV coordinate of the upper-right corner of 00125 // all the sprites generated by this renderer. Normally 00126 // this is (1, 1), but it might be set to something else 00127 // to use only a portion of the texture. 00128 //////////////////////////////////////////////////////////////////// 00129 INLINE void SpriteParticleRenderer:: 00130 set_ur_uv(const LTexCoord &ur_uv) { 00131 set_ur_uv(ur_uv,0,0); 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function : SpriteParticleRenderer::set_ur_uv 00136 // Access : public 00137 // Description : Sets the UV coordinate of the upper-right corner of 00138 // all the sprites generated by this renderer. Normally 00139 // this is (1, 1), but it might be set to something else 00140 // to use only a portion of the texture. 00141 //////////////////////////////////////////////////////////////////// 00142 INLINE void SpriteParticleRenderer:: 00143 set_ur_uv(const LTexCoord &ur_uv, const int anim, const int frame) { 00144 if(anim < (int)_anims.size() && frame < (int)_anims[anim]->get_num_frames()) { 00145 _anims[anim]->set_ur(frame,ur_uv); 00146 } 00147 } 00148 00149 //////////////////////////////////////////////////////////////////// 00150 // Function : SpriteParticleRenderer::set_size 00151 // Access : public 00152 // Description : Sets the size of each particle in world units. 00153 //////////////////////////////////////////////////////////////////// 00154 INLINE void SpriteParticleRenderer:: 00155 set_size(PN_stdfloat width, PN_stdfloat height) { 00156 _width = width; 00157 _height = height; 00158 init_geoms(); 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function : SpriteParticleRenderer::set_color 00163 // Access : public 00164 //////////////////////////////////////////////////////////////////// 00165 INLINE void SpriteParticleRenderer:: 00166 set_color(const LColor &color) { 00167 _color = color; 00168 _color_interpolation_manager->set_default_color(_color); 00169 } 00170 00171 //////////////////////////////////////////////////////////////////// 00172 // Function : SpriteParticleRenderer::set_x_scale_flag 00173 // Access : public 00174 //////////////////////////////////////////////////////////////////// 00175 INLINE void SpriteParticleRenderer:: 00176 set_x_scale_flag(bool animate_x_ratio) { 00177 _animate_x_ratio = animate_x_ratio; 00178 init_geoms(); 00179 } 00180 00181 //////////////////////////////////////////////////////////////////// 00182 // Function : SpriteParticleRenderer::set_y_scale_flag 00183 // Access : public 00184 //////////////////////////////////////////////////////////////////// 00185 INLINE void SpriteParticleRenderer:: 00186 set_y_scale_flag(bool animate_y_ratio) { 00187 _animate_y_ratio = animate_y_ratio; 00188 init_geoms(); 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function : SpriteParticleRenderer::set_anim_angle_flag 00193 // Access : public 00194 //////////////////////////////////////////////////////////////////// 00195 INLINE void SpriteParticleRenderer:: 00196 set_anim_angle_flag(bool animate_theta) { 00197 _animate_theta = animate_theta; 00198 init_geoms(); 00199 } 00200 00201 //////////////////////////////////////////////////////////////////// 00202 // Function : SpriteParticleRenderer::set_initial_x_scale 00203 // Access : public 00204 //////////////////////////////////////////////////////////////////// 00205 INLINE void SpriteParticleRenderer:: 00206 set_initial_x_scale(PN_stdfloat initial_x_scale) { 00207 _initial_x_scale = initial_x_scale; 00208 init_geoms(); 00209 } 00210 00211 //////////////////////////////////////////////////////////////////// 00212 // Function : SpriteParticleRenderer::set_final_x_scale 00213 // Access : public 00214 //////////////////////////////////////////////////////////////////// 00215 INLINE void SpriteParticleRenderer:: 00216 set_final_x_scale(PN_stdfloat final_x_scale) { 00217 _final_x_scale = final_x_scale; 00218 } 00219 00220 //////////////////////////////////////////////////////////////////// 00221 // Function : SpriteParticleRenderer::set_initial_y_scale 00222 // Access : public 00223 //////////////////////////////////////////////////////////////////// 00224 INLINE void SpriteParticleRenderer:: 00225 set_initial_y_scale(PN_stdfloat initial_y_scale) { 00226 _initial_y_scale = initial_y_scale; 00227 init_geoms(); 00228 } 00229 00230 //////////////////////////////////////////////////////////////////// 00231 // Function : SpriteParticleRenderer::set_final_y_scale 00232 // Access : public 00233 //////////////////////////////////////////////////////////////////// 00234 INLINE void SpriteParticleRenderer:: 00235 set_final_y_scale(PN_stdfloat final_y_scale) { 00236 _final_y_scale = final_y_scale; 00237 } 00238 00239 //////////////////////////////////////////////////////////////////// 00240 // Function : SpriteParticleRenderer::set_nonanimated_theta 00241 // Access : public 00242 //////////////////////////////////////////////////////////////////// 00243 INLINE void SpriteParticleRenderer:: 00244 set_nonanimated_theta(PN_stdfloat theta) { 00245 _theta = theta; 00246 init_geoms(); 00247 } 00248 00249 //////////////////////////////////////////////////////////////////// 00250 // Function : SpriteParticleRenderer::set_alpha_blend_method 00251 // Access : public 00252 //////////////////////////////////////////////////////////////////// 00253 INLINE void SpriteParticleRenderer:: 00254 set_alpha_blend_method(ParticleRendererBlendMethod bm) { 00255 _blend_method = bm; 00256 } 00257 00258 //////////////////////////////////////////////////////////////////// 00259 // Function : SpriteParticleRenderer::set_alpha_disable 00260 // Access : public 00261 //////////////////////////////////////////////////////////////////// 00262 INLINE void SpriteParticleRenderer:: 00263 set_alpha_disable(bool ad) { 00264 _alpha_disable = ad; 00265 } 00266 00267 //////////////////////////////////////////////////////////////////// 00268 // Function : SpriteParticleRenderer::set_animate_frames_enable 00269 // Access : public 00270 //////////////////////////////////////////////////////////////////// 00271 INLINE void SpriteParticleRenderer:: 00272 set_animate_frames_enable(bool an) { 00273 _animate_frames = an; 00274 } 00275 00276 //////////////////////////////////////////////////////////////////// 00277 // Function : SpriteParticleRenderer::set_animate_frames_rate 00278 // Access : public 00279 //////////////////////////////////////////////////////////////////// 00280 INLINE void SpriteParticleRenderer:: 00281 set_animate_frames_rate(PN_stdfloat r) { 00282 nassertv( r >= 0.0); 00283 _animate_frames_rate = r; 00284 } 00285 00286 //////////////////////////////////////////////////////////////////// 00287 // Function : SpriteParticleRenderer::set_animate_frames_index 00288 // Access : public 00289 // Purpose : Sets the frame to be used when animation is disabled. 00290 //////////////////////////////////////////////////////////////////// 00291 INLINE void SpriteParticleRenderer:: 00292 set_animate_frames_index(int i) { 00293 nassertv(i < (int)_anims[0]->get_num_frames()); 00294 _animate_frames_index = i; 00295 } 00296 00297 //////////////////////////////////////////////////////////////////// 00298 // Function : SpriteParticleRenderer::get_texture 00299 // Access : public 00300 //////////////////////////////////////////////////////////////////// 00301 INLINE Texture *SpriteParticleRenderer:: 00302 get_texture() const { 00303 return get_texture(0,0); 00304 } 00305 00306 //////////////////////////////////////////////////////////////////// 00307 // Function : SpriteParticleRenderer::get_texture 00308 // Access : public 00309 //////////////////////////////////////////////////////////////////// 00310 INLINE Texture *SpriteParticleRenderer:: 00311 get_texture(const int anim, const int frame) const { 00312 if(_anims.size() == 0) { 00313 return (Texture*)NULL; 00314 } 00315 nassertr(anim < (int)_anims.size() && anim >= 0, (Texture*)NULL); 00316 nassertr(frame < (int)_anims[anim]->get_num_frames() && frame >= 0,_anims[anim]->get_frame(0)); 00317 return _anims[anim]->get_frame(frame); 00318 } 00319 00320 INLINE int SpriteParticleRenderer:: 00321 get_num_anims() const { 00322 return _anims.size(); 00323 } 00324 00325 INLINE SpriteAnim *SpriteParticleRenderer:: 00326 get_anim(const int n) const { 00327 nassertr(n < (int)_anims.size(), (SpriteAnim*)NULL); 00328 return _anims[n]; 00329 } 00330 00331 INLINE SpriteAnim *SpriteParticleRenderer:: 00332 get_last_anim() const { 00333 if (_anims.size()) { 00334 return *(_anims.end()-1); 00335 } else { 00336 return (SpriteAnim *)NULL; 00337 } 00338 } 00339 00340 //////////////////////////////////////////////////////////////////// 00341 // Function : SpriteParticleRenderer::get_ll_uv 00342 // Access : public 00343 // Description : Returns the UV coordinate of the lower-left corner; 00344 // see set_ll_uv(). 00345 //////////////////////////////////////////////////////////////////// 00346 INLINE LTexCoord SpriteParticleRenderer:: 00347 get_ll_uv() const { 00348 return get_ll_uv(0,0); 00349 } 00350 00351 //////////////////////////////////////////////////////////////////// 00352 // Function : SpriteParticleRenderer::get_ll_uv 00353 // Access : public 00354 // Description : Returns the UV coordinate of the lower-left corner; 00355 // see set_ll_uv(). 00356 //////////////////////////////////////////////////////////////////// 00357 INLINE LTexCoord SpriteParticleRenderer:: 00358 get_ll_uv(const int anim, const int frame) const { 00359 int a = anim < (int)_anims.size()?anim:0; 00360 int f = frame < (int)_anims[a]->get_num_frames()?frame:0; 00361 return _anims[a]->get_ll(f); 00362 } 00363 00364 //////////////////////////////////////////////////////////////////// 00365 // Function : SpriteParticleRenderer::get_ur_uv 00366 // Access : public 00367 // Description : Returns the UV coordinate of the lower-left corner; 00368 // see set_ur_uv(). 00369 //////////////////////////////////////////////////////////////////// 00370 INLINE LTexCoord SpriteParticleRenderer:: 00371 get_ur_uv() const { 00372 return get_ur_uv(0,0); 00373 } 00374 00375 //////////////////////////////////////////////////////////////////// 00376 // Function : SpriteParticleRenderer::get_ur_uv 00377 // Access : public 00378 // Description : Returns the UV coordinate of the upper-right corner; 00379 // see set_ur_uv(). 00380 //////////////////////////////////////////////////////////////////// 00381 INLINE LTexCoord SpriteParticleRenderer:: 00382 get_ur_uv(const int anim, const int frame) const { 00383 int a = anim < (int)_anims.size()?anim:0; 00384 int f = frame < (int)_anims[a]->get_num_frames()?frame:0; 00385 return _anims[a]->get_ur(f); 00386 } 00387 00388 //////////////////////////////////////////////////////////////////// 00389 // Function : SpriteParticleRenderer::get_width 00390 // Access : public 00391 // Description : Returns the width of each particle in world units. 00392 //////////////////////////////////////////////////////////////////// 00393 INLINE PN_stdfloat SpriteParticleRenderer:: 00394 get_width() const { 00395 return _width; 00396 } 00397 00398 //////////////////////////////////////////////////////////////////// 00399 // Function : SpriteParticleRenderer::get_height 00400 // Access : public 00401 // Description : Returns the height of each particle in world units. 00402 //////////////////////////////////////////////////////////////////// 00403 INLINE PN_stdfloat SpriteParticleRenderer:: 00404 get_height() const { 00405 return _height; 00406 } 00407 00408 //////////////////////////////////////////////////////////////////// 00409 // Function : SpriteParticleRenderer::get_color 00410 // Access : public 00411 //////////////////////////////////////////////////////////////////// 00412 INLINE LColor SpriteParticleRenderer:: 00413 get_color() const { 00414 return _color; 00415 } 00416 00417 //////////////////////////////////////////////////////////////////// 00418 // Function : SpriteParticleRenderer::get_x_scale_flag 00419 // Access : public 00420 //////////////////////////////////////////////////////////////////// 00421 INLINE bool SpriteParticleRenderer:: 00422 get_x_scale_flag() const { 00423 return _animate_x_ratio; 00424 } 00425 00426 //////////////////////////////////////////////////////////////////// 00427 // Function : SpriteParticleRenderer::get_y_scale_flag 00428 // Access : public 00429 //////////////////////////////////////////////////////////////////// 00430 INLINE bool SpriteParticleRenderer:: 00431 get_y_scale_flag() const { 00432 return _animate_y_ratio; 00433 } 00434 00435 //////////////////////////////////////////////////////////////////// 00436 // Function : SpriteParticleRenderer::get_anim_angle_flag 00437 // Access : public 00438 //////////////////////////////////////////////////////////////////// 00439 INLINE bool SpriteParticleRenderer:: 00440 get_anim_angle_flag() const { 00441 return _animate_theta; 00442 } 00443 00444 //////////////////////////////////////////////////////////////////// 00445 // Function : SpriteParticleRenderer::get_initial_x_scale 00446 // Access : public 00447 //////////////////////////////////////////////////////////////////// 00448 INLINE PN_stdfloat SpriteParticleRenderer:: 00449 get_initial_x_scale() const { 00450 return _initial_x_scale; 00451 } 00452 00453 //////////////////////////////////////////////////////////////////// 00454 // Function : SpriteParticleRenderer::get_final_x_scale 00455 // Access : public 00456 //////////////////////////////////////////////////////////////////// 00457 INLINE PN_stdfloat SpriteParticleRenderer:: 00458 get_final_x_scale() const { 00459 return _final_x_scale; 00460 } 00461 00462 //////////////////////////////////////////////////////////////////// 00463 // Function : SpriteParticleRenderer::get_initial_y_scale 00464 // Access : public 00465 //////////////////////////////////////////////////////////////////// 00466 INLINE PN_stdfloat SpriteParticleRenderer:: 00467 get_initial_y_scale() const { 00468 return _initial_y_scale; 00469 } 00470 00471 //////////////////////////////////////////////////////////////////// 00472 // Function : SpriteParticleRenderer::get_final_y_scale 00473 // Access : public 00474 //////////////////////////////////////////////////////////////////// 00475 INLINE PN_stdfloat SpriteParticleRenderer:: 00476 get_final_y_scale() const { 00477 return _final_y_scale; 00478 } 00479 00480 //////////////////////////////////////////////////////////////////// 00481 // Function : SpriteParticleRenderer::get_nonanimated_theta 00482 // Access : public 00483 //////////////////////////////////////////////////////////////////// 00484 INLINE PN_stdfloat SpriteParticleRenderer:: 00485 get_nonanimated_theta() const { 00486 return _theta; 00487 } 00488 00489 //////////////////////////////////////////////////////////////////// 00490 // Function : SpriteParticleRenderer::get_alpha_blend_method 00491 // Access : public 00492 //////////////////////////////////////////////////////////////////// 00493 INLINE BaseParticleRenderer::ParticleRendererBlendMethod SpriteParticleRenderer:: 00494 get_alpha_blend_method() const { 00495 return _blend_method; 00496 } 00497 00498 //////////////////////////////////////////////////////////////////// 00499 // Function : SpriteParticleRenderer::get_alpha_disable 00500 // Access : public 00501 //////////////////////////////////////////////////////////////////// 00502 INLINE bool SpriteParticleRenderer:: 00503 get_alpha_disable() const { 00504 return _alpha_disable; 00505 } 00506 00507 //////////////////////////////////////////////////////////////////// 00508 // Function : SpriteParticleRenderer::get_animate_frames_enable 00509 // Access : public 00510 //////////////////////////////////////////////////////////////////// 00511 INLINE bool SpriteParticleRenderer:: 00512 get_animate_frames_enable() const { 00513 return _animate_frames; 00514 } 00515 00516 //////////////////////////////////////////////////////////////////// 00517 // Function : SpriteParticleRenderer::get_animate_frames_rate 00518 // Access : public 00519 //////////////////////////////////////////////////////////////////// 00520 INLINE PN_stdfloat SpriteParticleRenderer:: 00521 get_animate_frames_rate() const { 00522 return _animate_frames_rate; 00523 } 00524 00525 //////////////////////////////////////////////////////////////////// 00526 // Function : SpriteParticleRenderer::get_animate_frames_index 00527 // Access : public 00528 // Purpose : Gets the frame to be used when animation is disabled. 00529 //////////////////////////////////////////////////////////////////// 00530 INLINE int SpriteParticleRenderer:: 00531 get_animate_frames_index() const { 00532 return _animate_frames_index; 00533 } 00534 00535 //////////////////////////////////////////////////////////////////// 00536 // Function : SpriteParticleRenderer::get_color_interpolation_manager 00537 // Access : public 00538 //////////////////////////////////////////////////////////////////// 00539 INLINE ColorInterpolationManager* SpriteParticleRenderer:: 00540 get_color_interpolation_manager() const { 00541 return _color_interpolation_manager; 00542 }