Panda3D
Loading...
Searching...
No Matches
discEmitter.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 discEmitter.cxx
10 * @author charles
11 * @date 2000-06-22
12 */
13
14#include "discEmitter.h"
15
16/**
17 * constructor
18 */
21 _radius = 1.0f;
22 _inner_aoe = _outer_aoe = 0.0f;
23 _inner_magnitude = _outer_magnitude = 1.0f;
24 _cubic_lerping = false;
25}
26
27/**
28 * copy constructor
29 */
31DiscEmitter(const DiscEmitter &copy) :
33 _radius = copy._radius;
34 _inner_aoe = copy._inner_aoe;
35 _outer_aoe = copy._outer_aoe;
36 _inner_magnitude = copy._inner_magnitude;
37 _outer_magnitude = copy._outer_magnitude;
38 _cubic_lerping = copy._cubic_lerping;
39
40 _distance_from_center = copy._distance_from_center;
41 _sinf_theta = copy._sinf_theta;
42 _cosf_theta = copy._cosf_theta;
43}
44
45/**
46 * destructor
47 */
51
52/**
53 * copier
54 */
56make_copy() {
57 return new DiscEmitter(*this);
58}
59
60/**
61 * Generates a location for a new particle
62 */
63void DiscEmitter::
64assign_initial_position(LPoint3& pos) {
65 // position
66 PN_stdfloat theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
67
68 _distance_from_center = NORMALIZED_RAND();
69 PN_stdfloat r_scalar = _distance_from_center * _radius;
70
71 _sinf_theta = sinf(theta);
72 _cosf_theta = cosf(theta);
73
74 PN_stdfloat new_x = _cosf_theta * r_scalar;
75 PN_stdfloat new_y = _sinf_theta * r_scalar;
76
77 pos.set(new_x, new_y, 0.0f);
78}
79
80/**
81 * Generates a velocity for a new particle
82 */
83void DiscEmitter::
84assign_initial_velocity(LVector3& vel) {
85 PN_stdfloat aoe, mag;
86
87 // lerp type
88 if (_cubic_lerping == true) {
89 aoe = CLERP(_distance_from_center, _inner_aoe, _outer_aoe);
90 mag = CLERP(_distance_from_center, _inner_magnitude, _outer_magnitude);
91 }
92 else {
93 aoe = LERP(_distance_from_center, _inner_aoe, _outer_aoe);
94 mag = LERP(_distance_from_center, _inner_magnitude, _outer_magnitude);
95 }
96
97 // velocity
98 PN_stdfloat vel_z = mag * sinf(deg_2_rad(aoe));
99 PN_stdfloat abs_diff = fabs((mag * mag) - (vel_z * vel_z));
100 PN_stdfloat root_mag_minus_z_squared = sqrtf(abs_diff);
101 PN_stdfloat vel_x = _cosf_theta * root_mag_minus_z_squared;
102 PN_stdfloat vel_y = _sinf_theta * root_mag_minus_z_squared;
103
104 // quick and dirty
105 if((aoe > 90.0f) && (aoe < 270.0f))
106 {
107 vel_x = -vel_x;
108 vel_y = -vel_y;
109 }
110
111 vel.set(vel_x, vel_y, vel_z);
112}
113
114/**
115 * Write a string representation of this instance to <out>.
116 */
118output(std::ostream &out) const {
119 #ifndef NDEBUG //[
120 out<<"DiscEmitter";
121 #endif //] NDEBUG
122}
123
124/**
125 * Write a string representation of this instance to <out>.
126 */
128write(std::ostream &out, int indent) const {
129 #ifndef NDEBUG //[
130 out.width(indent); out<<""; out<<"DiscEmitter:\n";
131 out.width(indent+2); out<<""; out<<"_radius "<<_radius<<"\n";
132 out.width(indent+2); out<<""; out<<"_outer_aoe "<<_outer_aoe<<"\n";
133 out.width(indent+2); out<<""; out<<"_inner_aoe "<<_inner_aoe<<"\n";
134 out.width(indent+2); out<<""; out<<"_outer_magnitude "<<_outer_magnitude<<"\n";
135 out.width(indent+2); out<<""; out<<"_inner_magnitude "<<_inner_magnitude<<"\n";
136 out.width(indent+2); out<<""; out<<"_cubic_lerping "<<_cubic_lerping<<"\n";
137 out.width(indent+2); out<<""; out<<"_distance_from_center "<<_distance_from_center<<"\n";
138 out.width(indent+2); out<<""; out<<"_sinf_theta "<<_sinf_theta<<"\n";
139 out.width(indent+2); out<<""; out<<"_cosf_theta "<<_cosf_theta<<"\n";
141 #endif //] NDEBUG
142}
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Describes a planar disc region from which particles are generated.
Definition discEmitter.h:22
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
virtual ~DiscEmitter()
destructor
DiscEmitter()
constructor
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
virtual BaseParticleEmitter * make_copy()
copier
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20