Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/particlesystem/sphereVolumeEmitter.cxx

Go to the documentation of this file.
00001 // Filename: sphereVolumeEmitter.cxx
00002 // Created by:  charles (22Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "sphereVolumeEmitter.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //    Function : SphereVolumeEmitter
00023 //      Access : Public
00024 // Description : constructor
00025 ////////////////////////////////////////////////////////////////////
00026 SphereVolumeEmitter::
00027 SphereVolumeEmitter(void) {
00028   _radius = 1.0f;
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //    Function : SphereVolumeEmitter
00033 //      Access : Public
00034 // Description : copy constructor
00035 ////////////////////////////////////////////////////////////////////
00036 SphereVolumeEmitter::
00037 SphereVolumeEmitter(const SphereVolumeEmitter &copy) :
00038   BaseParticleEmitter(copy) {
00039   _radius = copy._radius;
00040   _particle_pos = copy._particle_pos;
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //    Function : ~SphereVolumeEmitter
00045 //      Access : Public
00046 // Description : destructor
00047 ////////////////////////////////////////////////////////////////////
00048 SphereVolumeEmitter::
00049 ~SphereVolumeEmitter(void) {
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //    Function : make_copy
00054 //      Access : Public
00055 // Description : copier
00056 ////////////////////////////////////////////////////////////////////
00057 BaseParticleEmitter *SphereVolumeEmitter::
00058 make_copy(void) {
00059   return new SphereVolumeEmitter(*this);
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //    Function : SphereVolumeEmitter::assign_initial_position
00064 //      Access : Public
00065 // Description : Generates a location for a new particle
00066 ////////////////////////////////////////////////////////////////////
00067 void SphereVolumeEmitter::
00068 assign_initial_position(LPoint3f& pos) {
00069   float z, theta, r;
00070   float t;
00071 
00072   z = SPREAD(_radius);
00073   r = sqrtf((_radius * _radius) - (z * z));
00074   theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
00075 
00076   t = NORMALIZED_RAND();
00077 
00078   while (t == 0.0f)
00079     t = NORMALIZED_RAND();
00080 
00081   float pos_x = r * cosf(theta) * t;
00082   float pos_y = r * sinf(theta) * t;
00083   float pos_z = z * t;
00084 
00085   _particle_pos.set(pos_x, pos_y, pos_z);
00086   pos = _particle_pos;
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //    Function : SphereVolumeEmitter::assign_initial_velocity
00091 //      Access : Public
00092 // Description : Generates a velocity for a new particle
00093 ////////////////////////////////////////////////////////////////////
00094 void SphereVolumeEmitter::
00095 assign_initial_velocity(LVector3f& vel) {
00096   // set velocity to [0..1] according to distance from center,
00097   // along vector from center to position
00098   vel = _particle_pos / _radius;
00099 }

Generated on Fri May 2 00:41:01 2003 for Panda by doxygen1.3