Panda3D

sphereVolumeEmitter.cxx

00001 // Filename: sphereVolumeEmitter.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 "sphereVolumeEmitter.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //    Function : SphereVolumeEmitter
00019 //      Access : Public
00020 // Description : constructor
00021 ////////////////////////////////////////////////////////////////////
00022 SphereVolumeEmitter::
00023 SphereVolumeEmitter() {
00024   _radius = 1.0f;
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //    Function : SphereVolumeEmitter
00029 //      Access : Public
00030 // Description : copy constructor
00031 ////////////////////////////////////////////////////////////////////
00032 SphereVolumeEmitter::
00033 SphereVolumeEmitter(const SphereVolumeEmitter &copy) :
00034   BaseParticleEmitter(copy) {
00035   _radius = copy._radius;
00036   _particle_pos = copy._particle_pos;
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //    Function : ~SphereVolumeEmitter
00041 //      Access : Public
00042 // Description : destructor
00043 ////////////////////////////////////////////////////////////////////
00044 SphereVolumeEmitter::
00045 ~SphereVolumeEmitter() {
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //    Function : make_copy
00050 //      Access : Public
00051 // Description : copier
00052 ////////////////////////////////////////////////////////////////////
00053 BaseParticleEmitter *SphereVolumeEmitter::
00054 make_copy() {
00055   return new SphereVolumeEmitter(*this);
00056 }
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //    Function : SphereVolumeEmitter::assign_initial_position
00060 //      Access : Public
00061 // Description : Generates a location for a new particle
00062 ////////////////////////////////////////////////////////////////////
00063 void SphereVolumeEmitter::
00064 assign_initial_position(LPoint3& pos) {
00065   PN_stdfloat z, theta, r;
00066   PN_stdfloat t;
00067 
00068   z = SPREAD(_radius);
00069   r = sqrtf((_radius * _radius) - (z * z));
00070   theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
00071 
00072   t = NORMALIZED_RAND();
00073 
00074   while (t == 0.0f)
00075     t = NORMALIZED_RAND();
00076 
00077   PN_stdfloat pos_x = r * cosf(theta) * t;
00078   PN_stdfloat pos_y = r * sinf(theta) * t;
00079   PN_stdfloat pos_z = z * t;
00080 
00081   _particle_pos.set(pos_x, pos_y, pos_z);
00082   pos = _particle_pos;
00083 }
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //    Function : SphereVolumeEmitter::assign_initial_velocity
00087 //      Access : Public
00088 // Description : Generates a velocity for a new particle
00089 ////////////////////////////////////////////////////////////////////
00090 void SphereVolumeEmitter::
00091 assign_initial_velocity(LVector3& vel) {
00092   // set velocity to [0..1] according to distance from center,
00093   // along vector from center to position
00094   vel = _particle_pos / _radius;
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function : output
00099 //       Access : Public
00100 //  Description : Write a string representation of this instance to
00101 //                <out>.
00102 ////////////////////////////////////////////////////////////////////
00103 void SphereVolumeEmitter::
00104 output(ostream &out) const {
00105   #ifndef NDEBUG //[
00106   out<<"SphereVolumeEmitter";
00107   #endif //] NDEBUG
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function : write
00112 //       Access : Public
00113 //  Description : Write a string representation of this instance to
00114 //                <out>.
00115 ////////////////////////////////////////////////////////////////////
00116 void SphereVolumeEmitter::
00117 write(ostream &out, int indent) const {
00118   #ifndef NDEBUG //[
00119   out.width(indent); out<<""; out<<"SphereVolumeEmitter:\n";
00120   out.width(indent+2); out<<""; out<<"_radius "<<_radius<<"\n";
00121   BaseParticleEmitter::write(out, indent+2);
00122   #endif //] NDEBUG
00123 }
 All Classes Functions Variables Enumerations