Panda3D
ringEmitter.cxx
1 // Filename: ringEmitter.cxx
2 // Created by: charles (22Jun00)
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 "ringEmitter.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function : RingEmitter
19 // Access : Public
20 // Description : constructor
21 ////////////////////////////////////////////////////////////////////
24  _radius(1.0f), _radius_spread(0.0f), _aoe(0.0f), _uniform_emission(0), _theta(0.0f)
25 {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function : RingEmitter
30 // Access : Public
31 // Description : copy constructor
32 ////////////////////////////////////////////////////////////////////
34 RingEmitter(const RingEmitter &copy) :
35  BaseParticleEmitter(copy) {
36  _radius = copy._radius;
37  _aoe = copy._aoe;
38  _radius_spread = copy._radius_spread;
39  _uniform_emission = copy._uniform_emission;
40 
41  _theta = copy._theta;
42  _sin_theta = copy._sin_theta;
43  _cos_theta = copy._cos_theta;
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function : ~RingEmitter
48 // Access : Public
49 // Description : destructor
50 ////////////////////////////////////////////////////////////////////
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function : make_copy
57 // Access : Public
58 // Description : copier
59 ////////////////////////////////////////////////////////////////////
62  return new RingEmitter(*this);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function : RingEmitter::assign_initial_position
67 // Access : Public
68 // Description : Generates a location for a new particle
69 ////////////////////////////////////////////////////////////////////
70 void RingEmitter::
71 assign_initial_position(LPoint3& pos) {
72  if (_uniform_emission > 0)
73  {
74  _theta = _theta + 1.0/_uniform_emission;
75  if (_theta > 1.0)
76  _theta = _theta - 1.0;
77  }
78  else
79  {
80  _theta = NORMALIZED_RAND();
81  }
82 
83  _cos_theta = cosf(_theta * 2.0f * MathNumbers::pi_f);
84  _sin_theta = sinf(_theta * 2.0f * MathNumbers::pi_f);
85 
86  PN_stdfloat new_radius_spread = SPREAD(_radius_spread);
87  PN_stdfloat new_x = _cos_theta * (_radius + new_radius_spread);
88  PN_stdfloat new_y = _sin_theta * (_radius + new_radius_spread);
89 
90  pos.set(new_x, new_y, 0.0f);
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function : RingEmitter::assign_initial_velocity
95 // Access : Public
96 // Description : Generates a velocity for a new particle
97 ////////////////////////////////////////////////////////////////////
98 void RingEmitter::
99 assign_initial_velocity(LVector3& vel) {
100  PN_stdfloat vel_z = sinf(deg_2_rad(_aoe));
101  PN_stdfloat abs_diff = fabs(1.0f - (vel_z * vel_z));
102  PN_stdfloat root_mag_minus_z_squared = sqrtf(abs_diff);
103 
104  PN_stdfloat vel_x = _cos_theta * root_mag_minus_z_squared;
105  PN_stdfloat vel_y = _sin_theta * root_mag_minus_z_squared;
106 
107  // quick and dirty
108  if((_aoe > 90.0f) && (_aoe < 270.0f))
109  {
110  vel_x = -vel_x;
111  vel_y = -vel_y;
112  }
113 
114  vel.set(vel_x, vel_y, vel_z);
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function : output
119 // Access : Public
120 // Description : Write a string representation of this instance to
121 // <out>.
122 ////////////////////////////////////////////////////////////////////
123 void RingEmitter::
124 output(ostream &out) const {
125  #ifndef NDEBUG //[
126  out<<"RingEmitter";
127  #endif //] NDEBUG
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function : write
132 // Access : Public
133 // Description : Write a string representation of this instance to
134 // <out>.
135 ////////////////////////////////////////////////////////////////////
136 void RingEmitter::
137 write(ostream &out, int indent) const {
138  #ifndef NDEBUG //[
139  out.width(indent); out<<""; out<<"RingEmitter:\n";
140  out.width(indent+2); out<<""; out<<"_radius "<<_radius<<"\n";
141  out.width(indent+2); out<<""; out<<"_radius_spread "<<_radius_spread<<"\n";
142  out.width(indent+2); out<<""; out<<"_aoe "<<_aoe<<"\n";
143  out.width(indent+2); out<<""; out<<"_sin_theta "<<_sin_theta<<"\n";
144  out.width(indent+2); out<<""; out<<"_cos_theta "<<_cos_theta<<"\n";
145  BaseParticleEmitter::write(out, indent+2);
146  #endif //] NDEBUG
147 }
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
RingEmitter()
constructor
Definition: ringEmitter.cxx:23
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
Describes a planar ring region in which particles are generated.
Definition: ringEmitter.h:25
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual ~RingEmitter()
destructor
Definition: ringEmitter.cxx:52
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Describes a physical region in space in which particles are randomly generated.
virtual BaseParticleEmitter * make_copy()
copier
Definition: ringEmitter.cxx:61