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