Panda3D
|
00001 // Filename: arcEmitter.cxx 00002 // Created by: charles (22Jun00) 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 "arcEmitter.h" 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function : ArcEmitter 00019 // Access : Public 00020 // Description : constructor 00021 //////////////////////////////////////////////////////////////////// 00022 ArcEmitter:: 00023 ArcEmitter() : 00024 RingEmitter(), _start_theta(0.0f), _end_theta(MathNumbers::pi_f) 00025 { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function : ArcEmitter 00030 // Access : Public 00031 // Description : copy constructor 00032 //////////////////////////////////////////////////////////////////// 00033 ArcEmitter:: 00034 ArcEmitter(const ArcEmitter ©) : 00035 RingEmitter(copy) { 00036 _start_theta = copy._start_theta; 00037 _end_theta = copy._end_theta; 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function : ~ArcEmitter 00042 // Access : Public 00043 // Description : destructor 00044 //////////////////////////////////////////////////////////////////// 00045 ArcEmitter:: 00046 ~ArcEmitter() { 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function : make_copy 00051 // Access : Public 00052 // Description : copier 00053 //////////////////////////////////////////////////////////////////// 00054 BaseParticleEmitter *ArcEmitter:: 00055 make_copy() { 00056 return new ArcEmitter(*this); 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function : ArcEmitter::assign_initial_position 00061 // Access : Public 00062 // Description : Generates a location for a new particle 00063 //////////////////////////////////////////////////////////////////// 00064 void ArcEmitter:: 00065 assign_initial_position(LPoint3& pos) { 00066 PN_stdfloat theta; 00067 if ( _start_theta < _end_theta ) { 00068 theta = LERP(NORMALIZED_RAND(), _start_theta, _end_theta); 00069 } else { 00070 theta = LERP(NORMALIZED_RAND(), _start_theta, _end_theta + 2.0f * MathNumbers::pi_f); 00071 } 00072 00073 theta += (MathNumbers::pi_f / 2.0); 00074 this->_cos_theta = cosf(theta); 00075 this->_sin_theta = sinf(theta); 00076 00077 PN_stdfloat new_radius_spread = SPREAD(_radius_spread); 00078 PN_stdfloat new_x = _cos_theta * (_radius + new_radius_spread); 00079 PN_stdfloat new_y = _sin_theta * (_radius + new_radius_spread); 00080 00081 pos.set(new_x, new_y, 0.0f); 00082 } 00083 00084 //////////////////////////////////////////////////////////////////// 00085 // Function : output 00086 // Access : Public 00087 // Description : Write a starc representation of this instance to 00088 // <out>. 00089 //////////////////////////////////////////////////////////////////// 00090 void ArcEmitter:: 00091 output(ostream &out) const { 00092 #ifndef NDEBUG //[ 00093 out<<"ArcEmitter"; 00094 #endif //] NDEBUG 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function : write 00099 // Access : Public 00100 // Description : Write a starc representation of this instance to 00101 // <out>. 00102 //////////////////////////////////////////////////////////////////// 00103 void ArcEmitter:: 00104 write(ostream &out, int indent) const { 00105 #ifndef NDEBUG //[ 00106 out.width(indent); out<<""; out<<"ArcEmitter:\n"; 00107 out.width(indent+2); out<<""; out<<"_start_angle "<<rad_2_deg(_start_theta)<<"\n"; 00108 out.width(indent+2); out<<""; out<<"_end_angle "<<rad_2_deg(_end_theta)<<"\n"; 00109 RingEmitter::write(out, indent+2); 00110 #endif //] NDEBUG 00111 }