Panda3D
 All Classes Functions Variables Enumerations
sphereVolumeEmitter.cxx
1 // Filename: sphereVolumeEmitter.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 "sphereVolumeEmitter.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function : SphereVolumeEmitter
19 // Access : Public
20 // Description : constructor
21 ////////////////////////////////////////////////////////////////////
24  _radius = 1.0f;
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function : SphereVolumeEmitter
29 // Access : Public
30 // Description : copy constructor
31 ////////////////////////////////////////////////////////////////////
34  BaseParticleEmitter(copy) {
35  _radius = copy._radius;
36  _particle_pos = copy._particle_pos;
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function : ~SphereVolumeEmitter
41 // Access : Public
42 // Description : destructor
43 ////////////////////////////////////////////////////////////////////
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function : make_copy
50 // Access : Public
51 // Description : copier
52 ////////////////////////////////////////////////////////////////////
55  return new SphereVolumeEmitter(*this);
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function : SphereVolumeEmitter::assign_initial_position
60 // Access : Public
61 // Description : Generates a location for a new particle
62 ////////////////////////////////////////////////////////////////////
63 void SphereVolumeEmitter::
64 assign_initial_position(LPoint3& pos) {
65  PN_stdfloat z, theta, r;
66  PN_stdfloat t;
67 
68  z = SPREAD(_radius);
69  r = sqrtf((_radius * _radius) - (z * z));
70  theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
71 
72  t = NORMALIZED_RAND();
73 
74  while (t == 0.0f)
75  t = NORMALIZED_RAND();
76 
77  PN_stdfloat pos_x = r * cosf(theta) * t;
78  PN_stdfloat pos_y = r * sinf(theta) * t;
79  PN_stdfloat pos_z = z * t;
80 
81  _particle_pos.set(pos_x, pos_y, pos_z);
82  pos = _particle_pos;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function : SphereVolumeEmitter::assign_initial_velocity
87 // Access : Public
88 // Description : Generates a velocity for a new particle
89 ////////////////////////////////////////////////////////////////////
90 void SphereVolumeEmitter::
91 assign_initial_velocity(LVector3& vel) {
92  // set velocity to [0..1] according to distance from center,
93  // along vector from center to position
94  vel = _particle_pos / _radius;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function : output
99 // Access : Public
100 // Description : Write a string representation of this instance to
101 // <out>.
102 ////////////////////////////////////////////////////////////////////
104 output(ostream &out) const {
105  #ifndef NDEBUG //[
106  out<<"SphereVolumeEmitter";
107  #endif //] NDEBUG
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function : write
112 // Access : Public
113 // Description : Write a string representation of this instance to
114 // <out>.
115 ////////////////////////////////////////////////////////////////////
117 write(ostream &out, int indent) const {
118  #ifndef NDEBUG //[
119  out.width(indent); out<<""; out<<"SphereVolumeEmitter:\n";
120  out.width(indent+2); out<<""; out<<"_radius "<<_radius<<"\n";
121  BaseParticleEmitter::write(out, indent+2);
122  #endif //] NDEBUG
123 }
SphereVolumeEmitter()
constructor
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
virtual void output(ostream &out) const
Write a string representation of this instance to &lt;out&gt;.
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to &lt;out&gt;.
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to &lt;out&gt;.
Describes a voluminous spherical region in which particles are generated.
virtual BaseParticleEmitter * make_copy()
copier
Describes a physical region in space in which particles are randomly generated.
virtual ~SphereVolumeEmitter()
destructor