Panda3D
panda
src
particlesystem
sphereVolumeEmitter.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 sphereVolumeEmitter.cxx
10
* @author charles
11
* @date 2000-06-22
12
*/
13
14
#include "
sphereVolumeEmitter.h
"
15
16
/**
17
* constructor
18
*/
19
SphereVolumeEmitter::
20
SphereVolumeEmitter
() {
21
_radius = 1.0f;
22
}
23
24
/**
25
* copy constructor
26
*/
27
SphereVolumeEmitter::
28
SphereVolumeEmitter
(
const
SphereVolumeEmitter
©) :
29
BaseParticleEmitter
(copy) {
30
_radius = copy._radius;
31
_particle_pos = copy._particle_pos;
32
}
33
34
/**
35
* destructor
36
*/
37
SphereVolumeEmitter::
38
~SphereVolumeEmitter
() {
39
}
40
41
/**
42
* copier
43
*/
44
BaseParticleEmitter
*
SphereVolumeEmitter::
45
make_copy
() {
46
return
new
SphereVolumeEmitter
(*
this
);
47
}
48
49
/**
50
* Generates a location for a new particle
51
*/
52
void
SphereVolumeEmitter::
53
assign_initial_position(LPoint3& pos) {
54
PN_stdfloat z, theta, r;
55
PN_stdfloat t;
56
57
z = SPREAD(_radius);
58
r = sqrtf((_radius * _radius) - (z * z));
59
theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
60
61
t = NORMALIZED_RAND();
62
63
while
(t == 0.0f)
64
t = NORMALIZED_RAND();
65
66
PN_stdfloat pos_x = r * cosf(theta) * t;
67
PN_stdfloat pos_y = r * sinf(theta) * t;
68
PN_stdfloat pos_z = z * t;
69
70
_particle_pos.set(pos_x, pos_y, pos_z);
71
pos = _particle_pos;
72
}
73
74
/**
75
* Generates a velocity for a new particle
76
*/
77
void
SphereVolumeEmitter::
78
assign_initial_velocity(LVector3& vel) {
79
// set velocity to [0..1] according to distance from center, along vector
80
// from center to position
81
vel = _particle_pos / _radius;
82
}
83
84
/**
85
* Write a string representation of this instance to <out>.
86
*/
87
void
SphereVolumeEmitter::
88
output
(std::ostream &out)
const
{
89
#ifndef NDEBUG //[
90
out<<
"SphereVolumeEmitter"
;
91
#endif //] NDEBUG
92
}
93
94
/**
95
* Write a string representation of this instance to <out>.
96
*/
97
void
SphereVolumeEmitter::
98
write
(std::ostream &out,
int
indent
)
const
{
99
#ifndef NDEBUG //[
100
out.width(
indent
); out<<
""
; out<<
"SphereVolumeEmitter:\n"
;
101
out.width(
indent
+2); out<<
""
; out<<
"_radius "
<<_radius<<
"\n"
;
102
BaseParticleEmitter::write
(out,
indent
+2);
103
#endif //] NDEBUG
104
}
SphereVolumeEmitter::SphereVolumeEmitter
SphereVolumeEmitter()
constructor
Definition:
sphereVolumeEmitter.cxx:20
BaseParticleEmitter::write
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition:
baseParticleEmitter.cxx:92
SphereVolumeEmitter::write
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition:
sphereVolumeEmitter.cxx:98
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition:
indent.cxx:20
sphereVolumeEmitter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
SphereVolumeEmitter::output
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
Definition:
sphereVolumeEmitter.cxx:88
SphereVolumeEmitter
Describes a voluminous spherical region in which particles are generated.
Definition:
sphereVolumeEmitter.h:22
SphereVolumeEmitter::make_copy
virtual BaseParticleEmitter * make_copy()
copier
Definition:
sphereVolumeEmitter.cxx:45
BaseParticleEmitter
Definition:
baseParticleEmitter.h:25
SphereVolumeEmitter::~SphereVolumeEmitter
virtual ~SphereVolumeEmitter()
destructor
Definition:
sphereVolumeEmitter.cxx:38
Generated on Wed Jan 23 2019 21:40:08 for Panda3D by
1.8.15