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