Panda3D
Loading...
Searching...
No Matches
spriteParticleRenderer.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file spriteParticleRenderer.I
10 * @author charles
11 * @date 2000-07-13
12 */
13
14/**
15 * Sets the renderer up to render the entire texture image. The scale of each
16 * particle is based on the size of the texture in each dimension, modified by
17 * texels_per_unit.
18 *
19 * Used to set the size of the particles. Will clear all previously loaded
20 * textures and animations.
21 */
23set_texture(Texture *tex, PN_stdfloat texels_per_unit) {
24 if (tex != nullptr) {
25 // Clear all texture information
26 _anims.clear();
27
28 // Insert the single texture
29 _anims.push_back(new SpriteAnim(tex,LTexCoord(0.0f, 0.0f),LTexCoord(1.0f, 1.0f)));
30
31 // We scale the particle size by the size of the texture.
32 set_size(tex->get_x_size() / texels_per_unit,
33 tex->get_y_size() / texels_per_unit);
34 get_last_anim()->set_source_info(tex->get_filename());
35 }
36 init_geoms();
37}
38
39/**
40 * Adds texture to image pool, effectively creating a single frame animation
41 * that can be selected at particle birth. This should only be called after a
42 * previous call to set_texture().
43 */
45add_texture(Texture *tex, PN_stdfloat texels_per_unit, bool resize) {
46 if (_anims.size() == 0) {
47 set_texture(tex, texels_per_unit);
48 } else {
49 if(tex != nullptr) {
50 if (tex != nullptr) {
51 _anims.push_back(new SpriteAnim(tex,LTexCoord(0.0f, 0.0f),LTexCoord(1.0f, 1.0f)));
52 }
53 if(resize) {
54 // We scale the particle size by the size of the texture.
55 set_size(tex->get_x_size() / texels_per_unit,
56 tex->get_y_size() / texels_per_unit);
57 }
58 get_last_anim()->set_source_info(tex->get_filename());
59 init_geoms();
60 }
61 }
62}
63
64/**
65 * Removes an animation texture set from the renderer.
66 */
68remove_animation(const int n) {
69 nassertv(n < (int)_anims.size());
70 int i,j;
71
72 for (i = 0; i < (int)_anims.size(); ++i) {
73 for (j = 0; j < (int)_anim_size[i]; ++j) {
74 _sprites[i][j]->clear_vertices();
75 }
76 }
77
78 _anims.erase(_anims.begin()+n);
79 _animation_removed = true;
80 init_geoms();
81}
82
83/**
84 * Sets the UV coordinate of the lower-left corner of all the sprites
85 * generated by this renderer. Normally this is (0, 0), but it might be set
86 * to something else to use only a portion of the texture.
87 */
89set_ll_uv(const LTexCoord &ll_uv) {
90 set_ll_uv(ll_uv,0,0);
91}
92
93/**
94 * Sets the UV coordinate of the lower-left corner of all the sprites
95 * generated by this renderer. Normally this is (0, 0), but it might be set
96 * to something else to use only a portion of the texture.
97 */
99set_ll_uv(const LTexCoord &ll_uv, const int anim, const int frame) {
100 if(anim < (int)_anims.size() && frame < (int)_anims[anim]->get_num_frames()) {
101 _anims[anim]->set_ll(frame,ll_uv);
102 }
103}
104
105/**
106 * Sets the UV coordinate of the upper-right corner of all the sprites
107 * generated by this renderer. Normally this is (1, 1), but it might be set
108 * to something else to use only a portion of the texture.
109 */
111set_ur_uv(const LTexCoord &ur_uv) {
112 set_ur_uv(ur_uv,0,0);
113}
114
115/**
116 * Sets the UV coordinate of the upper-right corner of all the sprites
117 * generated by this renderer. Normally this is (1, 1), but it might be set
118 * to something else to use only a portion of the texture.
119 */
121set_ur_uv(const LTexCoord &ur_uv, const int anim, const int frame) {
122 if(anim < (int)_anims.size() && frame < (int)_anims[anim]->get_num_frames()) {
123 _anims[anim]->set_ur(frame,ur_uv);
124 }
125}
126
127/**
128 * Sets the size of each particle in world units.
129 */
131set_size(PN_stdfloat width, PN_stdfloat height) {
132 _width = width;
133 _height = height;
134 init_geoms();
135}
136
137/**
138
139 */
140INLINE void SpriteParticleRenderer::
141set_color(const LColor &color) {
142 _color = color;
143 _color_interpolation_manager->set_default_color(_color);
144}
145
146/**
147
148 */
149INLINE void SpriteParticleRenderer::
150set_x_scale_flag(bool animate_x_ratio) {
151 _animate_x_ratio = animate_x_ratio;
152 init_geoms();
153}
154
155/**
156
157 */
158INLINE void SpriteParticleRenderer::
159set_y_scale_flag(bool animate_y_ratio) {
160 _animate_y_ratio = animate_y_ratio;
161 init_geoms();
162}
163
164/**
165
166 */
167INLINE void SpriteParticleRenderer::
168set_anim_angle_flag(bool animate_theta) {
169 _animate_theta = animate_theta;
170 init_geoms();
171}
172
173/**
174
175 */
176INLINE void SpriteParticleRenderer::
177set_initial_x_scale(PN_stdfloat initial_x_scale) {
178 _initial_x_scale = initial_x_scale;
179 init_geoms();
180}
181
182/**
183
184 */
185INLINE void SpriteParticleRenderer::
186set_final_x_scale(PN_stdfloat final_x_scale) {
187 _final_x_scale = final_x_scale;
188}
189
190/**
191
192 */
193INLINE void SpriteParticleRenderer::
194set_initial_y_scale(PN_stdfloat initial_y_scale) {
195 _initial_y_scale = initial_y_scale;
196 init_geoms();
197}
198
199/**
200
201 */
202INLINE void SpriteParticleRenderer::
203set_final_y_scale(PN_stdfloat final_y_scale) {
204 _final_y_scale = final_y_scale;
205}
206
207/**
208
209 */
210INLINE void SpriteParticleRenderer::
211set_nonanimated_theta(PN_stdfloat theta) {
212 _theta = theta;
213 init_geoms();
214}
215
216/**
217
218 */
219INLINE void SpriteParticleRenderer::
220set_alpha_blend_method(ParticleRendererBlendMethod bm) {
221 _blend_method = bm;
222}
223
224/**
225
226 */
227INLINE void SpriteParticleRenderer::
228set_alpha_disable(bool ad) {
229 _alpha_disable = ad;
230}
231
232/**
233
234 */
235INLINE void SpriteParticleRenderer::
236set_animate_frames_enable(bool an) {
237 _animate_frames = an;
238}
239
240/**
241
242 */
243INLINE void SpriteParticleRenderer::
244set_animate_frames_rate(PN_stdfloat r) {
245 nassertv( r >= 0.0);
246 _animate_frames_rate = r;
247}
248
249/**
250
251 */
252INLINE void SpriteParticleRenderer::
253set_animate_frames_index(int i) {
254 nassertv(i < (int)_anims[0]->get_num_frames());
255 _animate_frames_index = i;
256}
257
258/**
259
260 */
261INLINE Texture *SpriteParticleRenderer::
262get_texture() const {
263 return get_texture(0,0);
264}
265
266/**
267
268 */
269INLINE Texture *SpriteParticleRenderer::
270get_texture(const int anim, const int frame) const {
271 if(_anims.size() == 0) {
272 return nullptr;
273 }
274 nassertr(anim < (int)_anims.size() && anim >= 0, nullptr);
275 nassertr(frame < (int)_anims[anim]->get_num_frames() && frame >= 0,_anims[anim]->get_frame(0));
276 return _anims[anim]->get_frame(frame);
277}
278
279INLINE int SpriteParticleRenderer::
280get_num_anims() const {
281 return _anims.size();
282}
283
284INLINE SpriteAnim *SpriteParticleRenderer::
285get_anim(const int n) const {
286 nassertr(n < (int)_anims.size(), nullptr);
287 return _anims[n];
288}
289
290INLINE SpriteAnim *SpriteParticleRenderer::
291get_last_anim() const {
292 if (_anims.size()) {
293 return *(_anims.end()-1);
294 } else {
295 return nullptr;
296 }
297}
298
299/**
300 * Returns the UV coordinate of the lower-left corner; see set_ll_uv().
301 */
303get_ll_uv() const {
304 return get_ll_uv(0,0);
305}
306
307/**
308 * Returns the UV coordinate of the lower-left corner; see set_ll_uv().
309 */
311get_ll_uv(const int anim, const int frame) const {
312 int a = anim < (int)_anims.size()?anim:0;
313 int f = frame < (int)_anims[a]->get_num_frames()?frame:0;
314 return _anims[a]->get_ll(f);
315}
316
317/**
318 * Returns the UV coordinate of the lower-left corner; see set_ur_uv().
319 */
321get_ur_uv() const {
322 return get_ur_uv(0,0);
323}
324
325/**
326 * Returns the UV coordinate of the upper-right corner; see set_ur_uv().
327 */
329get_ur_uv(const int anim, const int frame) const {
330 int a = anim < (int)_anims.size()?anim:0;
331 int f = frame < (int)_anims[a]->get_num_frames()?frame:0;
332 return _anims[a]->get_ur(f);
333}
334
335/**
336 * Returns the width of each particle in world units.
337 */
338INLINE PN_stdfloat SpriteParticleRenderer::
339get_width() const {
340 return _width;
341}
342
343/**
344 * Returns the height of each particle in world units.
345 */
346INLINE PN_stdfloat SpriteParticleRenderer::
347get_height() const {
348 return _height;
349}
350
351/**
352
353 */
354INLINE LColor SpriteParticleRenderer::
355get_color() const {
356 return _color;
357}
358
359/**
360
361 */
362INLINE bool SpriteParticleRenderer::
363get_x_scale_flag() const {
364 return _animate_x_ratio;
365}
366
367/**
368
369 */
370INLINE bool SpriteParticleRenderer::
371get_y_scale_flag() const {
372 return _animate_y_ratio;
373}
374
375/**
376
377 */
378INLINE bool SpriteParticleRenderer::
379get_anim_angle_flag() const {
380 return _animate_theta;
381}
382
383/**
384
385 */
386INLINE PN_stdfloat SpriteParticleRenderer::
387get_initial_x_scale() const {
388 return _initial_x_scale;
389}
390
391/**
392
393 */
394INLINE PN_stdfloat SpriteParticleRenderer::
395get_final_x_scale() const {
396 return _final_x_scale;
397}
398
399/**
400
401 */
402INLINE PN_stdfloat SpriteParticleRenderer::
403get_initial_y_scale() const {
404 return _initial_y_scale;
405}
406
407/**
408
409 */
410INLINE PN_stdfloat SpriteParticleRenderer::
411get_final_y_scale() const {
412 return _final_y_scale;
413}
414
415/**
416
417 */
418INLINE PN_stdfloat SpriteParticleRenderer::
419get_nonanimated_theta() const {
420 return _theta;
421}
422
423/**
424
425 */
426INLINE BaseParticleRenderer::ParticleRendererBlendMethod SpriteParticleRenderer::
427get_alpha_blend_method() const {
428 return _blend_method;
429}
430
431/**
432
433 */
434INLINE bool SpriteParticleRenderer::
435get_alpha_disable() const {
436 return _alpha_disable;
437}
438
439/**
440
441 */
442INLINE bool SpriteParticleRenderer::
443get_animate_frames_enable() const {
444 return _animate_frames;
445}
446
447/**
448
449 */
450INLINE PN_stdfloat SpriteParticleRenderer::
451get_animate_frames_rate() const {
452 return _animate_frames_rate;
453}
454
455/**
456
457 */
458INLINE int SpriteParticleRenderer::
459get_animate_frames_index() const {
460 return _animate_frames_index;
461}
462
463/**
464
465 */
466INLINE ColorInterpolationManager* SpriteParticleRenderer::
467get_color_interpolation_manager() const {
468 return _color_interpolation_manager;
469}
High level class for color interpolation.
Helper class used by SpriteParticleRenderer to keep track of its textures and their respective UVs an...
LTexCoord get_ur_uv() const
Returns the UV coordinate of the lower-left corner; see set_ur_uv().
void add_texture(Texture *tex, PN_stdfloat texels_per_unit=1.0f, bool resize=false)
Adds texture to image pool, effectively creating a single frame animation that can be selected at par...
void set_ur_uv(const LTexCoord &ur_uv)
Sets the UV coordinate of the upper-right corner of all the sprites generated by this renderer.
PN_stdfloat get_height() const
Returns the height of each particle in world units.
void set_size(PN_stdfloat width, PN_stdfloat height)
Sets the size of each particle in world units.
void set_ll_uv(const LTexCoord &ll_uv)
Sets the UV coordinate of the lower-left corner of all the sprites generated by this renderer.
PN_stdfloat get_width() const
Returns the width of each particle in world units.
void remove_animation(const int n)
Removes an animation texture set from the renderer.
void set_texture(Texture *tex, PN_stdfloat texels_per_unit=1.0f)
Sets the renderer up to render the entire texture image.
LTexCoord get_ll_uv() const
Returns the UV coordinate of the lower-left corner; see set_ll_uv().
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition texture.h:72
get_filename
Returns the filename that has been set.
Definition texture.h:321
get_y_size
Returns the height of the texture image in texels.
Definition texture.h:347
get_x_size
Returns the width of the texture image in texels.
Definition texture.h:343