Panda3D
Loading...
Searching...
No Matches
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 */
21 _radius = 1.0f;
22}
23
24/**
25 * copy constructor
26 */
30 _radius = copy._radius;
31 _particle_pos = copy._particle_pos;
32}
33
34/**
35 * destructor
36 */
40
41/**
42 * copier
43 */
48
49/**
50 * Generates a location for a new particle
51 */
52void SphereVolumeEmitter::
53assign_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 */
77void SphereVolumeEmitter::
78assign_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 */
88output(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 */
98write(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";
103 #endif //] NDEBUG
104}
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Describes a voluminous spherical region in which particles are generated.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
virtual ~SphereVolumeEmitter()
destructor
virtual BaseParticleEmitter * make_copy()
copier
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.