Panda3D

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