Panda3D
baseParticleRenderer.cxx
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 baseParticleRenderer.cxx
10  * @author charles
11  * @date 2000-06-20
12  */
13 
14 #include "pandabase.h"
15 
16 #include "baseParticleRenderer.h"
17 #include "transparencyAttrib.h"
18 #include "colorAttrib.h"
19 #include "compassEffect.h"
20 
21 /**
22  * Default Constructor
23  */
24 BaseParticleRenderer::
25 BaseParticleRenderer(ParticleRendererAlphaMode alpha_mode) :
26  _alpha_mode(PR_NOT_INITIALIZED_YET) {
27  _render_node = new GeomNode("BaseParticleRenderer render node");
28  _render_node_path = NodePath(_render_node);
29 
30  _user_alpha = 1.0f;
31  _ignore_scale = false;
32 
33  update_alpha_mode(alpha_mode);
34 }
35 
36 /**
37  * Copy Constructor
38  */
39 BaseParticleRenderer::
40 BaseParticleRenderer(const BaseParticleRenderer& copy) :
41  _alpha_mode(PR_ALPHA_NONE) {
42  _render_node = new GeomNode("BaseParticleRenderer render node");
43  _render_node_path = NodePath(_render_node);
44 
45  _user_alpha = copy._user_alpha;
46  set_ignore_scale(copy._ignore_scale);
47 
48  update_alpha_mode(copy._alpha_mode);
49 }
50 
51 /**
52  * Destructor
53  */
56 }
57 
58 /**
59  * Sets the "ignore scale" flag. When this is true, particles will be drawn
60  * as if they had no scale, regardless of whatever scale might be inherited
61  * from above the render node in the scene graph.
62  *
63  * This flag is mainly useful to support legacy code that was written for a
64  * very early version of Panda, whose sprite particle renderer had a bug that
65  * incorrectly ignored the inherited scale.
66  */
68 set_ignore_scale(bool ignore_scale) {
69  _ignore_scale = ignore_scale;
70 
71  if (_ignore_scale) {
72  _render_node->set_effect(CompassEffect::make(NodePath(), CompassEffect::P_scale));
73  } else {
74  _render_node->clear_effect(CompassEffect::get_class_type());
75  }
76 }
77 
78 /**
79  * Write a string representation of this instance to <out>.
80  */
82 output(std::ostream &out) const {
83  #ifndef NDEBUG //[
84  out<<"BaseParticleRenderer";
85  #endif //] NDEBUG
86 }
87 
88 /**
89  * Write a string representation of this instance to <out>.
90  */
92 write(std::ostream &out, int indent) const {
93  #ifndef NDEBUG //[
94  out.width(indent); out<<""; out<<"BaseParticleRenderer:\n";
95  out.width(indent+2); out<<""; out<<"_render_node "<<_render_node_path<<"\n";
96  out.width(indent+2); out<<""; out<<"_user_alpha "<<_user_alpha<<"\n";
97  // ReferenceCount::write(out, indent+2);
98  #endif //] NDEBUG
99 }
100 
101 /**
102  * handles the base class part of alpha updating.
103  */
104 void BaseParticleRenderer::
105 update_alpha_mode(ParticleRendererAlphaMode am) {
106  if (_alpha_mode == am)
107  return;
108 
109  if ((am == PR_ALPHA_NONE) && (_alpha_mode != PR_ALPHA_NONE))
110  disable_alpha();
111  else if ((am != PR_ALPHA_NONE) && (_alpha_mode == PR_ALPHA_NONE))
112  enable_alpha();
113 
114  _alpha_mode = am;
115 }
116 
117 /**
118  * Builds an intermediate node and transition that enables alpha channeling.
119  */
120 void BaseParticleRenderer::
121 enable_alpha() {
122  _render_state = RenderState::make(TransparencyAttrib::make(TransparencyAttrib::M_alpha),
123  ColorAttrib::make_vertex());
124 }
125 
126 /**
127  * kills the intermediate alpha node/arc
128  */
129 void BaseParticleRenderer::
130 disable_alpha() {
131  _render_state = RenderState::make(TransparencyAttrib::make(TransparencyAttrib::M_none),
132  ColorAttrib::make_vertex());
133 }
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual ~BaseParticleRenderer()
Destructor.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Pure virtual particle renderer base class.
void set_ignore_scale(bool ignore_scale)
Sets the "ignore scale" flag.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.