Panda3D
|
00001 // Filename: baseParticleEmitter.cxx 00002 // Created by: charles (14Jun00) 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 "baseParticleEmitter.h" 00016 00017 #include <stdlib.h> 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function : BaseParticleEmitter 00021 // Access : Protected 00022 // Description : constructor 00023 //////////////////////////////////////////////////////////////////// 00024 BaseParticleEmitter:: 00025 BaseParticleEmitter() { 00026 _emission_type = ET_RADIATE; 00027 _explicit_launch_vector.set(1,0,0); 00028 _radiate_origin.set(0,0,0); 00029 _amplitude = 1.0f; 00030 _amplitude_spread = 0.0f; 00031 _offset_force.set(0,0,0); 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function : BaseParticleEmitter 00036 // Access : Protected 00037 // Description : copy constructor 00038 //////////////////////////////////////////////////////////////////// 00039 BaseParticleEmitter:: 00040 BaseParticleEmitter(const BaseParticleEmitter ©) { 00041 _emission_type = copy._emission_type; 00042 _explicit_launch_vector = copy._explicit_launch_vector; 00043 _radiate_origin = copy._radiate_origin; 00044 _amplitude = copy._amplitude; 00045 _amplitude_spread = copy._amplitude_spread; 00046 _offset_force = copy._offset_force; 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function : BaseParticleEmitter 00051 // Access : Protected 00052 // Description : destructor 00053 //////////////////////////////////////////////////////////////////// 00054 BaseParticleEmitter:: 00055 ~BaseParticleEmitter() { 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function : generate 00060 // Access : Public 00061 // Description : parent generation function 00062 //////////////////////////////////////////////////////////////////// 00063 void BaseParticleEmitter:: 00064 generate(LPoint3& pos, LVector3& vel) { 00065 assign_initial_position(pos); 00066 00067 switch(_emission_type) 00068 { 00069 case ET_EXPLICIT: 00070 vel = _explicit_launch_vector; 00071 break; 00072 00073 case ET_RADIATE: 00074 vel = pos - _radiate_origin; 00075 vel.normalize(); 00076 break; 00077 00078 case ET_CUSTOM: 00079 assign_initial_velocity(vel); 00080 break; 00081 } 00082 00083 vel *= _amplitude + SPREAD(_amplitude_spread); 00084 vel += _offset_force; 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function : output 00089 // Access : Public 00090 // Description : Write a string representation of this instance to 00091 // <out>. 00092 //////////////////////////////////////////////////////////////////// 00093 void BaseParticleEmitter:: 00094 output(ostream &out) const { 00095 #ifndef NDEBUG //[ 00096 out<<"BaseParticleEmitter"; 00097 #endif //] NDEBUG 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function : write 00102 // Access : Public 00103 // Description : Write a string representation of this instance to 00104 // <out>. 00105 //////////////////////////////////////////////////////////////////// 00106 void BaseParticleEmitter:: 00107 write(ostream &out, int indent) const { 00108 #ifndef NDEBUG //[ 00109 out.width(indent); out<<""; out<<"BaseParticleEmitter:\n"; 00110 out.width(indent+2); out<<""; out<<"_emission_type "<<_emission_type<<"\n"; 00111 out.width(indent+2); out<<""; out<<"_amplitude "<<_amplitude<<"\n"; 00112 out.width(indent+2); out<<""; out<<"_amplitude_spread "<<_amplitude_spread<<"\n"; 00113 out.width(indent+2); out<<""; out<<"_offset_force "<<_offset_force<<"\n"; 00114 //ReferenceCount::write(out, indent+2); 00115 #endif //] NDEBUG 00116 }