Panda3D
ringEmitter.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 ringEmitter.cxx
10  * @author charles
11  * @date 2000-06-22
12  */
13 
14 #include "ringEmitter.h"
15 
16 /**
17  * constructor
18  */
21  _radius(1.0f), _radius_spread(0.0f), _aoe(0.0f), _uniform_emission(0), _theta(0.0f)
22 {
23 }
24 
25 /**
26  * copy constructor
27  */
29 RingEmitter(const RingEmitter &copy) :
30  BaseParticleEmitter(copy) {
31  _radius = copy._radius;
32  _aoe = copy._aoe;
33  _radius_spread = copy._radius_spread;
34  _uniform_emission = copy._uniform_emission;
35 
36  _theta = copy._theta;
37  _sin_theta = copy._sin_theta;
38  _cos_theta = copy._cos_theta;
39 }
40 
41 /**
42  * destructor
43  */
46 }
47 
48 /**
49  * copier
50  */
53  return new RingEmitter(*this);
54 }
55 
56 /**
57  * Generates a location for a new particle
58  */
59 void RingEmitter::
60 assign_initial_position(LPoint3& pos) {
61  if (_uniform_emission > 0)
62  {
63  _theta = _theta + 1.0/_uniform_emission;
64  if (_theta > 1.0)
65  _theta = _theta - 1.0;
66  }
67  else
68  {
69  _theta = NORMALIZED_RAND();
70  }
71 
72  _cos_theta = cosf(_theta * 2.0f * MathNumbers::pi_f);
73  _sin_theta = sinf(_theta * 2.0f * MathNumbers::pi_f);
74 
75  PN_stdfloat new_radius_spread = SPREAD(_radius_spread);
76  PN_stdfloat new_x = _cos_theta * (_radius + new_radius_spread);
77  PN_stdfloat new_y = _sin_theta * (_radius + new_radius_spread);
78 
79  pos.set(new_x, new_y, 0.0f);
80 }
81 
82 /**
83  * Generates a velocity for a new particle
84  */
85 void RingEmitter::
86 assign_initial_velocity(LVector3& vel) {
87  PN_stdfloat vel_z = sinf(deg_2_rad(_aoe));
88  PN_stdfloat abs_diff = fabs(1.0f - (vel_z * vel_z));
89  PN_stdfloat root_mag_minus_z_squared = sqrtf(abs_diff);
90 
91  PN_stdfloat vel_x = _cos_theta * root_mag_minus_z_squared;
92  PN_stdfloat vel_y = _sin_theta * root_mag_minus_z_squared;
93 
94  // quick and dirty
95  if((_aoe > 90.0f) && (_aoe < 270.0f))
96  {
97  vel_x = -vel_x;
98  vel_y = -vel_y;
99  }
100 
101  vel.set(vel_x, vel_y, vel_z);
102 }
103 
104 /**
105  * Write a string representation of this instance to <out>.
106  */
107 void RingEmitter::
108 output(std::ostream &out) const {
109  #ifndef NDEBUG //[
110  out<<"RingEmitter";
111  #endif //] NDEBUG
112 }
113 
114 /**
115  * Write a string representation of this instance to <out>.
116  */
117 void RingEmitter::
118 write(std::ostream &out, int indent) const {
119  #ifndef NDEBUG //[
120  out.width(indent); out<<""; out<<"RingEmitter:\n";
121  out.width(indent+2); out<<""; out<<"_radius "<<_radius<<"\n";
122  out.width(indent+2); out<<""; out<<"_radius_spread "<<_radius_spread<<"\n";
123  out.width(indent+2); out<<""; out<<"_aoe "<<_aoe<<"\n";
124  out.width(indent+2); out<<""; out<<"_sin_theta "<<_sin_theta<<"\n";
125  out.width(indent+2); out<<""; out<<"_cos_theta "<<_cos_theta<<"\n";
127  #endif //] NDEBUG
128 }
RingEmitter()
constructor
Definition: ringEmitter.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>.
Describes a planar ring region in which particles are generated.
Definition: ringEmitter.h:22
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
virtual ~RingEmitter()
destructor
Definition: ringEmitter.cxx:45
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual BaseParticleEmitter * make_copy()
copier
Definition: ringEmitter.cxx:52