Panda3D
 All Classes Functions Variables Enumerations
zSpinParticle.cxx
1 // Filename: zSpinParticle.cxx
2 // Created by: charles (16Aug00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "zSpinParticle.h"
16 #include "cmath.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function : ZSpinParticle
20 // Access : public
21 // Description : constructor
22 ////////////////////////////////////////////////////////////////////
25  BaseParticle() {
26  _initial_angle = 0.0f;
27  _final_angle = 0.0f;
28  _cur_angle = 0.0f;
29  _angular_velocity = 0.0f;
30  _bUseAngularVelocity = false;
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function : ZSpinParticle
35 // Access : public
36 // Description : copy constructor
37 ////////////////////////////////////////////////////////////////////
40  BaseParticle(copy) {
41  _initial_angle = copy._initial_angle;
42  _final_angle = copy._final_angle;
43  _cur_angle = copy._cur_angle;
44  _angular_velocity = copy._angular_velocity;
45  _bUseAngularVelocity = copy._bUseAngularVelocity;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function : ~ZSpinParticle
50 // Access : public, virtual
51 // Description : destructor
52 ////////////////////////////////////////////////////////////////////
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function : make_copy
59 // Access : public, virtual
60 // Description : dynamic copier
61 ////////////////////////////////////////////////////////////////////
63 make_copy() const {
64  return new ZSpinParticle(*this);
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function : init
69 // Access : public, virtual
70 // Description :
71 ////////////////////////////////////////////////////////////////////
72 void ZSpinParticle::
73 init() {
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function : update
78 // Access : public, virtual
79 // Description :
80 ////////////////////////////////////////////////////////////////////
81 void ZSpinParticle::
82 update() {
83  // if using final_angle, want age to range from [0,1] over lifespan, so use parameterized_age
84  // for angular velocity, should be allowed to range freely upward, use regular age
85 
86  if(_bUseAngularVelocity) {
87  // interpolate the current orientation
88  _cur_angle = _initial_angle + (get_age() * _angular_velocity);
89  } else {
90  _cur_angle = _initial_angle + (get_parameterized_age() * (_final_angle - _initial_angle));
91  }
92 
93  // normalize the result to [0..360)
94  _cur_angle = cmod(_cur_angle, (PN_stdfloat)360.0);
95 
96  // if _cur_angle was negative, it is still negative after cmod,
97  // wrap it around by adding 360
98 
99  // is this really necessary? should be in range of sin/cos
100  if(_cur_angle < 0.0f)
101  _cur_angle += 360.0f;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function : die
106 // Access : public, virtual
107 // Description :
108 ////////////////////////////////////////////////////////////////////
109 void ZSpinParticle::
110 die() {
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function : get_theta
115 // Access : public, virtual
116 // Description :
117 ////////////////////////////////////////////////////////////////////
118 PN_stdfloat ZSpinParticle::
119 get_theta() const {
120  return _cur_angle;
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function : output
125 // Access : Public
126 // Description : Write a string representation of this instance to
127 // <out>.
128 ////////////////////////////////////////////////////////////////////
129 void ZSpinParticle::
130 output(ostream &out) const {
131  #ifndef NDEBUG //[
132  out<<"ZSpinParticle";
133  #endif //] NDEBUG
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function : write
138 // Access : Public
139 // Description : Write a string representation of this instance to
140 // <out>.
141 ////////////////////////////////////////////////////////////////////
142 void ZSpinParticle::
143 write(ostream &out, int indent) const {
144  #ifndef NDEBUG //[
145  out.width(indent); out<<""; out<<"ZSpinParticle:\n";
146  out.width(indent+2); out<<""; out<<"_initial_angle "<<_initial_angle<<"\n";
147  out.width(indent+2); out<<""; out<<"_final_angle "<<_final_angle<<"\n";
148  out.width(indent+2); out<<""; out<<"_cur_angle "<<_cur_angle<<"\n";
149  out.width(indent+2); out<<""; out<<"_angular_velocity "<<_angular_velocity<<"\n";
150  out.width(indent+2); out<<""; out<<"_bUseAngularVelocity "<<_bUseAngularVelocity<<"\n";
151  BaseParticle::write(out, indent+2);
152  #endif //] NDEBUG
153 }
A body on which physics will be applied.
Definition: physicsObject.h:29
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to &lt;out&gt;.
ZSpinParticle()
constructor
virtual PhysicsObject * make_copy() const
dynamic copier
virtual void output(ostream &out) const
Write a string representation of this instance to &lt;out&gt;.
describes a particle that spins along its z axis.
Definition: zSpinParticle.h:28
virtual PN_stdfloat get_theta() const
for spriteParticleRenderer
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to &lt;out&gt;.
An individual, physically-modelable particle abstract base class.
Definition: baseParticle.h:26
virtual ~ZSpinParticle()
destructor