Panda3D
|
00001 // Filename: baseParticleRenderer.cxx 00002 // Created by: charles (20Jun00) 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 #include "pandabase.h" 00016 00017 #include "baseParticleRenderer.h" 00018 #include "transparencyAttrib.h" 00019 #include "colorAttrib.h" 00020 #include "compassEffect.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function : BaseParticleRender::BaseParticleRenderer 00024 // Access : Published 00025 // Description : Default Constructor 00026 //////////////////////////////////////////////////////////////////// 00027 BaseParticleRenderer:: 00028 BaseParticleRenderer(ParticleRendererAlphaMode alpha_mode) : 00029 _alpha_mode(PR_NOT_INITIALIZED_YET) { 00030 _render_node = new GeomNode("BaseParticleRenderer render node"); 00031 _render_node_path = NodePath(_render_node); 00032 00033 _user_alpha = 1.0f; 00034 _ignore_scale = false; 00035 00036 update_alpha_mode(alpha_mode); 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function : BaseParticleRender::BaseParticleRenderer 00041 // Access : Published 00042 // Description : Copy Constructor 00043 //////////////////////////////////////////////////////////////////// 00044 BaseParticleRenderer:: 00045 BaseParticleRenderer(const BaseParticleRenderer& copy) : 00046 _alpha_mode(PR_ALPHA_NONE) { 00047 _render_node = new GeomNode("BaseParticleRenderer render node"); 00048 _render_node_path = NodePath(_render_node); 00049 00050 _user_alpha = copy._user_alpha; 00051 set_ignore_scale(copy._ignore_scale); 00052 00053 update_alpha_mode(copy._alpha_mode); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function : BaseParticleRender::~BaseParticleRenderer 00058 // Access : Published 00059 // Description : Destructor 00060 //////////////////////////////////////////////////////////////////// 00061 BaseParticleRenderer:: 00062 ~BaseParticleRenderer() { 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function : BaseParticleRender::set_ignore_scale 00067 // Access : Published 00068 // Description : Sets the "ignore scale" flag. When this is true, 00069 // particles will be drawn as if they had no scale, 00070 // regardless of whatever scale might be inherited from 00071 // above the render node in the scene graph. 00072 // 00073 // This flag is mainly useful to support legacy code 00074 // that was written for a very early version of Panda, 00075 // whose sprite particle renderer had a bug that 00076 // incorrectly ignored the inherited scale. 00077 //////////////////////////////////////////////////////////////////// 00078 void BaseParticleRenderer:: 00079 set_ignore_scale(bool ignore_scale) { 00080 _ignore_scale = ignore_scale; 00081 00082 if (_ignore_scale) { 00083 _render_node->set_effect(CompassEffect::make(NodePath(), CompassEffect::P_scale)); 00084 } else { 00085 _render_node->clear_effect(CompassEffect::get_class_type()); 00086 } 00087 } 00088 00089 //////////////////////////////////////////////////////////////////// 00090 // Function : BaseParticleRender::output 00091 // Access : Published 00092 // Description : Write a string representation of this instance to 00093 // <out>. 00094 //////////////////////////////////////////////////////////////////// 00095 void BaseParticleRenderer:: 00096 output(ostream &out) const { 00097 #ifndef NDEBUG //[ 00098 out<<"BaseParticleRenderer"; 00099 #endif //] NDEBUG 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function : BaseParticleRender::write 00104 // Access : Published 00105 // Description : Write a string representation of this instance to 00106 // <out>. 00107 //////////////////////////////////////////////////////////////////// 00108 void BaseParticleRenderer:: 00109 write(ostream &out, int indent) const { 00110 #ifndef NDEBUG //[ 00111 out.width(indent); out<<""; out<<"BaseParticleRenderer:\n"; 00112 out.width(indent+2); out<<""; out<<"_render_node "<<_render_node_path<<"\n"; 00113 out.width(indent+2); out<<""; out<<"_user_alpha "<<_user_alpha<<"\n"; 00114 //ReferenceCount::write(out, indent+2); 00115 #endif //] NDEBUG 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function : BaseParticleRender::update_alpha_state 00120 // Access : Private 00121 // Description : handles the base class part of alpha updating. 00122 //////////////////////////////////////////////////////////////////// 00123 void BaseParticleRenderer:: 00124 update_alpha_mode(ParticleRendererAlphaMode am) { 00125 if (_alpha_mode == am) 00126 return; 00127 00128 if ((am == PR_ALPHA_NONE) && (_alpha_mode != PR_ALPHA_NONE)) 00129 disable_alpha(); 00130 else if ((am != PR_ALPHA_NONE) && (_alpha_mode == PR_ALPHA_NONE)) 00131 enable_alpha(); 00132 00133 _alpha_mode = am; 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function : BaseParticleRender::enable_alpha 00138 // Access : Private 00139 // Description : Builds an intermediate node and transition that 00140 // enables alpha channeling. 00141 //////////////////////////////////////////////////////////////////// 00142 void BaseParticleRenderer:: 00143 enable_alpha() { 00144 _render_state = RenderState::make(TransparencyAttrib::make(TransparencyAttrib::M_alpha), 00145 ColorAttrib::make_vertex()); 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function : BaseParticleRender::disable_alpha 00150 // Access : Private 00151 // Description : kills the intermediate alpha node/arc 00152 //////////////////////////////////////////////////////////////////// 00153 void BaseParticleRenderer:: 00154 disable_alpha() { 00155 _render_state = RenderState::make(TransparencyAttrib::make(TransparencyAttrib::M_none), 00156 ColorAttrib::make_vertex()); 00157 }