Panda3D
zSpinParticle.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file zSpinParticle.cxx
10  * @author charles
11  * @date 2000-08-16
12  */
13 
14 #include "zSpinParticle.h"
15 #include "cmath.h"
16 
17 /**
18  * constructor
19  */
22  BaseParticle() {
23  _initial_angle = 0.0f;
24  _final_angle = 0.0f;
25  _cur_angle = 0.0f;
26  _angular_velocity = 0.0f;
27  _bUseAngularVelocity = false;
28 }
29 
30 /**
31  * copy constructor
32  */
35  BaseParticle(copy) {
36  _initial_angle = copy._initial_angle;
37  _final_angle = copy._final_angle;
38  _cur_angle = copy._cur_angle;
39  _angular_velocity = copy._angular_velocity;
40  _bUseAngularVelocity = copy._bUseAngularVelocity;
41 }
42 
43 /**
44  * destructor
45  */
48 }
49 
50 /**
51  * dynamic copier
52  */
54 make_copy() const {
55  return new ZSpinParticle(*this);
56 }
57 
58 /**
59  *
60  */
61 void ZSpinParticle::
62 init() {
63 }
64 
65 /**
66  *
67  */
68 void ZSpinParticle::
69 update() {
70  // if using final_angle, want age to range from [0,1] over lifespan, so use
71  // parameterized_age for angular velocity, should be allowed to range freely
72  // upward, use regular age
73 
74  if(_bUseAngularVelocity) {
75  // interpolate the current orientation
76  _cur_angle = _initial_angle + (get_age() * _angular_velocity);
77  } else {
78  _cur_angle = _initial_angle + (get_parameterized_age() * (_final_angle - _initial_angle));
79  }
80 
81  // normalize the result to [0..360)
82  _cur_angle = cmod(_cur_angle, (PN_stdfloat)360.0);
83 
84  // if _cur_angle was negative, it is still negative after cmod, wrap it
85  // around by adding 360
86 
87  // is this really necessary? should be in range of sincos
88  if(_cur_angle < 0.0f)
89  _cur_angle += 360.0f;
90 }
91 
92 /**
93  *
94  */
95 void ZSpinParticle::
96 die() {
97 }
98 
99 /**
100  *
101  */
102 PN_stdfloat ZSpinParticle::
103 get_theta() const {
104  return _cur_angle;
105 }
106 
107 /**
108  * Write a string representation of this instance to <out>.
109  */
110 void ZSpinParticle::
111 output(std::ostream &out) const {
112  #ifndef NDEBUG //[
113  out<<"ZSpinParticle";
114  #endif //] NDEBUG
115 }
116 
117 /**
118  * Write a string representation of this instance to <out>.
119  */
120 void ZSpinParticle::
121 write(std::ostream &out, int indent) const {
122  #ifndef NDEBUG //[
123  out.width(indent); out<<""; out<<"ZSpinParticle:\n";
124  out.width(indent+2); out<<""; out<<"_initial_angle "<<_initial_angle<<"\n";
125  out.width(indent+2); out<<""; out<<"_final_angle "<<_final_angle<<"\n";
126  out.width(indent+2); out<<""; out<<"_cur_angle "<<_cur_angle<<"\n";
127  out.width(indent+2); out<<""; out<<"_angular_velocity "<<_angular_velocity<<"\n";
128  out.width(indent+2); out<<""; out<<"_bUseAngularVelocity "<<_bUseAngularVelocity<<"\n";
129  BaseParticle::write(out, indent+2);
130  #endif //] NDEBUG
131 }
float cmod(float x, float y)
This is similar to fmod(), but it behaves properly when x is negative: that is, it always returns a v...
Definition: cmath.I:130
virtual PhysicsObject * make_copy() const
dynamic copier
A body on which physics will be applied.
Definition: physicsObject.h:27
ZSpinParticle()
constructor
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
describes a particle that spins along its z axis.
Definition: zSpinParticle.h:25
virtual PN_stdfloat get_theta() const
for spriteParticleRenderer
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An individual, physically-modelable particle abstract base class.
Definition: baseParticle.h:23
virtual ~ZSpinParticle()
destructor