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

panda/src/particlesystem/ringEmitter.cxx

Go to the documentation of this file.
00001 // Filename: ringEmitter.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 "ringEmitter.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //    Function : RingEmitter
00023 //      Access : Public
00024 // Description : constructor
00025 ////////////////////////////////////////////////////////////////////
00026 RingEmitter::
00027 RingEmitter(void) :
00028   _radius(1.0f), _aoe(0.0f) {
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //    Function : RingEmitter
00033 //      Access : Public
00034 // Description : copy constructor
00035 ////////////////////////////////////////////////////////////////////
00036 RingEmitter::
00037 RingEmitter(const RingEmitter &copy) :
00038   BaseParticleEmitter(copy) {
00039   _radius = copy._radius;
00040   _aoe = copy._aoe;
00041 
00042   _sin_theta = copy._sin_theta;
00043   _cos_theta = copy._cos_theta;
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //    Function : ~RingEmitter
00048 //      Access : Public
00049 // Description : destructor
00050 ////////////////////////////////////////////////////////////////////
00051 RingEmitter::
00052 ~RingEmitter(void) {
00053 }
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //    Function : make_copy
00057 //      Access : Public
00058 // Description : copier
00059 ////////////////////////////////////////////////////////////////////
00060 BaseParticleEmitter *RingEmitter::
00061 make_copy(void) {
00062   return new RingEmitter(*this);
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //    Function : RingEmitter::assign_initial_position
00067 //      Access : Public
00068 // Description : Generates a location for a new particle
00069 ////////////////////////////////////////////////////////////////////
00070 void RingEmitter::
00071 assign_initial_position(LPoint3f& pos) {
00072   float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
00073   _cos_theta = cosf(theta);
00074   _sin_theta = sinf(theta);
00075 
00076   float new_x = _cos_theta * _radius;
00077   float new_y = _sin_theta * _radius;
00078 
00079   pos.set(new_x, new_y, 0.0f);
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //    Function : RingEmitter::assign_initial_velocity
00084 //      Access : Public
00085 // Description : Generates a velocity for a new particle
00086 ////////////////////////////////////////////////////////////////////
00087 void RingEmitter::
00088 assign_initial_velocity(LVector3f& vel) {
00089   float vel_z = sinf(deg_2_rad(_aoe));
00090   float abs_diff = fabs(1.0f - (vel_z * vel_z));
00091   float root_mag_minus_z_squared = sqrtf(abs_diff);
00092 
00093   float vel_x = _cos_theta * root_mag_minus_z_squared;
00094   float vel_y = _sin_theta * root_mag_minus_z_squared;
00095 
00096   // quick and dirty
00097   if((_aoe > 90.0f) && (_aoe < 270.0f))
00098   {
00099     vel_x = -vel_x;
00100     vel_y = -vel_y;
00101   }
00102 
00103   vel.set(vel_x, vel_y, vel_z);
00104 }

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