Panda3D
 All Classes Functions Variables Enumerations
zSpinParticle.cxx
00001 // Filename: zSpinParticle.cxx
00002 // Created by:  charles (16Aug00)
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 "zSpinParticle.h"
00016 #include "cmath.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //    Function : ZSpinParticle
00020 //      Access : public
00021 // Description : constructor
00022 ////////////////////////////////////////////////////////////////////
00023 ZSpinParticle::
00024 ZSpinParticle() :
00025   BaseParticle() {
00026   _initial_angle = 0.0f;
00027   _final_angle = 0.0f;
00028   _cur_angle = 0.0f;
00029   _angular_velocity = 0.0f;
00030   _bUseAngularVelocity = false;
00031 }
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //    Function : ZSpinParticle
00035 //      Access : public
00036 // Description : copy constructor
00037 ////////////////////////////////////////////////////////////////////
00038 ZSpinParticle::
00039 ZSpinParticle(const ZSpinParticle &copy) :
00040   BaseParticle(copy) {
00041   _initial_angle = copy._initial_angle;
00042   _final_angle = copy._final_angle;
00043   _cur_angle = copy._cur_angle;
00044   _angular_velocity = copy._angular_velocity;
00045   _bUseAngularVelocity = copy._bUseAngularVelocity;
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //    Function : ~ZSpinParticle
00050 //      Access : public, virtual
00051 // Description : destructor
00052 ////////////////////////////////////////////////////////////////////
00053 ZSpinParticle::
00054 ~ZSpinParticle() {
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //    Function : make_copy
00059 //      Access : public, virtual
00060 // Description : dynamic copier
00061 ////////////////////////////////////////////////////////////////////
00062 PhysicsObject *ZSpinParticle::
00063 make_copy() const {
00064   return new ZSpinParticle(*this);
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //    Function : init
00069 //      Access : public, virtual
00070 // Description :
00071 ////////////////////////////////////////////////////////////////////
00072 void ZSpinParticle::
00073 init() {
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //    Function : update
00078 //      Access : public, virtual
00079 // Description :
00080 ////////////////////////////////////////////////////////////////////
00081 void ZSpinParticle::
00082 update() {
00083   // if using final_angle, want age to range from [0,1] over lifespan, so use parameterized_age
00084   // for angular velocity, should be allowed to range freely upward, use regular age
00085 
00086   if(_bUseAngularVelocity) {
00087    // interpolate the current orientation
00088       _cur_angle = _initial_angle + (get_age() * _angular_velocity);
00089   } else {
00090       _cur_angle = _initial_angle + (get_parameterized_age() * (_final_angle - _initial_angle));
00091   }
00092 
00093   // normalize the result to [0..360)
00094   _cur_angle = cmod(_cur_angle, (PN_stdfloat)360.0);
00095 
00096   // if _cur_angle was negative, it is still negative after cmod,
00097   // wrap it around by adding 360
00098 
00099   // is this really necessary?  should be in range of sin/cos
00100   if(_cur_angle < 0.0f)
00101     _cur_angle += 360.0f;
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //    Function : die
00106 //      Access : public, virtual
00107 // Description :
00108 ////////////////////////////////////////////////////////////////////
00109 void ZSpinParticle::
00110 die() {
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //    Function : get_theta
00115 //      Access : public, virtual
00116 // Description :
00117 ////////////////////////////////////////////////////////////////////
00118 PN_stdfloat ZSpinParticle::
00119 get_theta() const {
00120   return _cur_angle;
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function : output
00125 //       Access : Public
00126 //  Description : Write a string representation of this instance to
00127 //                <out>.
00128 ////////////////////////////////////////////////////////////////////
00129 void ZSpinParticle::
00130 output(ostream &out) const {
00131   #ifndef NDEBUG //[
00132   out<<"ZSpinParticle";
00133   #endif //] NDEBUG
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function : write
00138 //       Access : Public
00139 //  Description : Write a string representation of this instance to
00140 //                <out>.
00141 ////////////////////////////////////////////////////////////////////
00142 void ZSpinParticle::
00143 write(ostream &out, int indent) const {
00144   #ifndef NDEBUG //[
00145   out.width(indent); out<<""; out<<"ZSpinParticle:\n";
00146   out.width(indent+2); out<<""; out<<"_initial_angle "<<_initial_angle<<"\n";
00147   out.width(indent+2); out<<""; out<<"_final_angle "<<_final_angle<<"\n";
00148   out.width(indent+2); out<<""; out<<"_cur_angle "<<_cur_angle<<"\n";
00149   out.width(indent+2); out<<""; out<<"_angular_velocity "<<_angular_velocity<<"\n";
00150   out.width(indent+2); out<<""; out<<"_bUseAngularVelocity "<<_bUseAngularVelocity<<"\n";
00151   BaseParticle::write(out, indent+2);
00152   #endif //] NDEBUG
00153 }
 All Classes Functions Variables Enumerations