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

panda/src/particlesystem/discEmitter.cxx

Go to the documentation of this file.
00001 // Filename: discEmitter.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 "discEmitter.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //    Function : DiscEmitter::DiscEmitter
00023 //      Access : Public
00024 // Description : constructor
00025 ////////////////////////////////////////////////////////////////////
00026 DiscEmitter::
00027 DiscEmitter(void) {
00028   _radius = 1.0f;
00029   _inner_aoe = _outer_aoe = 0.0f;
00030   _inner_magnitude = _outer_magnitude = 1.0f;
00031   _cubic_lerping = false;
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //    Function : DiscEmitter::DiscEmitter
00036 //      Access : Public
00037 // Description : copy constructor
00038 ////////////////////////////////////////////////////////////////////
00039 DiscEmitter::
00040 DiscEmitter(const DiscEmitter &copy) :
00041   BaseParticleEmitter(copy) {
00042   _radius = copy._radius;
00043   _inner_aoe = copy._inner_aoe;
00044   _outer_aoe = copy._outer_aoe;
00045   _inner_magnitude = copy._inner_magnitude;
00046   _outer_magnitude = copy._outer_magnitude;
00047   _cubic_lerping = copy._cubic_lerping;
00048 
00049   _distance_from_center = copy._distance_from_center;
00050   _sinf_theta = copy._sinf_theta;
00051   _cosf_theta = copy._cosf_theta;
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //    Function : DiscEmitter::~DiscEmitter
00056 //      Access : Public
00057 // Description : destructor
00058 ////////////////////////////////////////////////////////////////////
00059 DiscEmitter::
00060 ~DiscEmitter(void) {
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //    Function : make_copy
00065 //      Access : Public
00066 // Description : copier
00067 ////////////////////////////////////////////////////////////////////
00068 BaseParticleEmitter *DiscEmitter::
00069 make_copy(void) {
00070   return new DiscEmitter(*this);
00071 }
00072 
00073 ////////////////////////////////////////////////////////////////////
00074 //    Function : DiscEmitter::assign_initial_position
00075 //      Access : Public
00076 // Description : Generates a location for a new particle
00077 ////////////////////////////////////////////////////////////////////
00078 void DiscEmitter::
00079 assign_initial_position(LPoint3f& pos) {
00080   // position
00081   float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
00082 
00083   _distance_from_center = NORMALIZED_RAND();
00084   float r_scalar = _distance_from_center * _radius;
00085 
00086   _sinf_theta = sinf(theta);
00087   _cosf_theta = cosf(theta);
00088 
00089   float new_x = _cosf_theta * r_scalar;
00090   float new_y = _sinf_theta * r_scalar;
00091 
00092   pos.set(new_x, new_y, 0.0f);
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //    Function : DiscEmitter::assign_initial_velocity
00097 //      Access : Public
00098 // Description : Generates a velocity for a new particle
00099 ////////////////////////////////////////////////////////////////////
00100 void DiscEmitter::
00101 assign_initial_velocity(LVector3f& vel) {
00102   float aoe, mag;
00103 
00104   // lerp type
00105   if (_cubic_lerping == true) {
00106     aoe = CLERP(_distance_from_center, _inner_aoe, _outer_aoe);
00107     mag = CLERP(_distance_from_center, _inner_magnitude, _outer_magnitude);
00108   }
00109   else {
00110     aoe = LERP(_distance_from_center, _inner_aoe, _outer_aoe);
00111     mag = LERP(_distance_from_center, _inner_magnitude, _outer_magnitude);
00112   }
00113 
00114   // velocity
00115   float vel_z = mag * sinf(deg_2_rad(aoe));
00116   float abs_diff = fabs((mag * mag) - (vel_z * vel_z));
00117   float root_mag_minus_z_squared = sqrtf(abs_diff);
00118   float vel_x = _cosf_theta * root_mag_minus_z_squared;
00119   float vel_y = _sinf_theta * root_mag_minus_z_squared;
00120 
00121   // quick and dirty
00122   if((aoe > 90.0f) && (aoe < 270.0f))
00123   {
00124     vel_x = -vel_x;
00125     vel_y = -vel_y;
00126   }
00127 
00128   vel.set(vel_x, vel_y, vel_z);
00129 }

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