00001 // Filename: rectangleEmitter.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 "rectangleEmitter.h" 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function : RectangleEmitter 00019 // Access : Public 00020 // Description : constructor 00021 //////////////////////////////////////////////////////////////////// 00022 RectangleEmitter:: 00023 RectangleEmitter() : 00024 BaseParticleEmitter() { 00025 _vmin.set(-0.5f, -0.5f); 00026 _vmax.set( 0.5f, 0.5f); 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function : RectangleEmitter 00031 // Access : Public 00032 // Description : copy constructor 00033 //////////////////////////////////////////////////////////////////// 00034 RectangleEmitter:: 00035 RectangleEmitter(const RectangleEmitter ©) : 00036 BaseParticleEmitter(copy) { 00037 _vmin = copy._vmin; 00038 _vmax = copy._vmax; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function : RectangleEmitter 00043 // Access : Public 00044 // Description : destructor 00045 //////////////////////////////////////////////////////////////////// 00046 RectangleEmitter:: 00047 ~RectangleEmitter() { 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function : make_copy 00052 // Access : Public 00053 // Description : copier 00054 //////////////////////////////////////////////////////////////////// 00055 BaseParticleEmitter *RectangleEmitter:: 00056 make_copy() { 00057 return new RectangleEmitter(*this); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function : RectangleEmitter::assign_initial_position 00062 // Access : Public 00063 // Description : Generates a location for a new particle 00064 //////////////////////////////////////////////////////////////////// 00065 void RectangleEmitter:: 00066 assign_initial_position(LPoint3& pos) { 00067 PN_stdfloat t_x = NORMALIZED_RAND(); 00068 PN_stdfloat t_y = NORMALIZED_RAND(); 00069 00070 LVector2 v_diff = _vmax - _vmin; 00071 00072 PN_stdfloat lerp_x = _vmin[0] + t_x * v_diff[0]; 00073 PN_stdfloat lerp_y = _vmin[1] + t_y * v_diff[1]; 00074 00075 pos.set(lerp_x, lerp_y, 0.0f); 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function : RectangleEmitter::assign_initial_velocity 00080 // Access : Public 00081 // Description : Generates a velocity for a new particle 00082 //////////////////////////////////////////////////////////////////// 00083 void RectangleEmitter:: 00084 assign_initial_velocity(LVector3& vel) { 00085 vel.set(0.0f,0.0f,0.0f); 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function : output 00090 // Access : Public 00091 // Description : Write a string representation of this instance to 00092 // <out>. 00093 //////////////////////////////////////////////////////////////////// 00094 void RectangleEmitter:: 00095 output(ostream &out) const { 00096 #ifndef NDEBUG //[ 00097 out<<"RectangleEmitter"; 00098 #endif //] NDEBUG 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function : write 00103 // Access : Public 00104 // Description : Write a string representation of this instance to 00105 // <out>. 00106 //////////////////////////////////////////////////////////////////// 00107 void RectangleEmitter:: 00108 write(ostream &out, int indent) const { 00109 #ifndef NDEBUG //[ 00110 out.width(indent); out<<""; out<<"RectangleEmitter:\n"; 00111 out.width(indent+2); out<<""; out<<"_vmin "<<_vmin<<"\n"; 00112 out.width(indent+2); out<<""; out<<"_vmax "<<_vmax<<"\n"; 00113 BaseParticleEmitter::write(out, indent+2); 00114 #endif //] NDEBUG 00115 }