Panda3D
baseParticleEmitter.cxx
1 // Filename: baseParticleEmitter.cxx
2 // Created by: charles (14Jun00)
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 "baseParticleEmitter.h"
16 
17 #include <stdlib.h>
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function : BaseParticleEmitter
21 // Access : Protected
22 // Description : constructor
23 ////////////////////////////////////////////////////////////////////
24 BaseParticleEmitter::
25 BaseParticleEmitter() {
26  _emission_type = ET_RADIATE;
27  _explicit_launch_vector.set(1,0,0);
28  _radiate_origin.set(0,0,0);
29  _amplitude = 1.0f;
30  _amplitude_spread = 0.0f;
31  _offset_force.set(0,0,0);
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function : BaseParticleEmitter
36 // Access : Protected
37 // Description : copy constructor
38 ////////////////////////////////////////////////////////////////////
39 BaseParticleEmitter::
40 BaseParticleEmitter(const BaseParticleEmitter &copy) {
41  _emission_type = copy._emission_type;
42  _explicit_launch_vector = copy._explicit_launch_vector;
43  _radiate_origin = copy._radiate_origin;
44  _amplitude = copy._amplitude;
45  _amplitude_spread = copy._amplitude_spread;
46  _offset_force = copy._offset_force;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function : BaseParticleEmitter
51 // Access : Protected
52 // Description : destructor
53 ////////////////////////////////////////////////////////////////////
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function : generate
60 // Access : Public
61 // Description : parent generation function
62 ////////////////////////////////////////////////////////////////////
64 generate(LPoint3& pos, LVector3& vel) {
65  assign_initial_position(pos);
66 
67  switch(_emission_type)
68  {
69  case ET_EXPLICIT:
70  vel = _explicit_launch_vector;
71  break;
72 
73  case ET_RADIATE:
74  vel = pos - _radiate_origin;
75  vel.normalize();
76  break;
77 
78  case ET_CUSTOM:
79  assign_initial_velocity(vel);
80  break;
81  }
82 
83  vel *= _amplitude + SPREAD(_amplitude_spread);
84  vel += _offset_force;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function : output
89 // Access : Public
90 // Description : Write a string representation of this instance to
91 // <out>.
92 ////////////////////////////////////////////////////////////////////
94 output(ostream &out) const {
95  #ifndef NDEBUG //[
96  out<<"BaseParticleEmitter";
97  #endif //] NDEBUG
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function : write
102 // Access : Public
103 // Description : Write a string representation of this instance to
104 // <out>.
105 ////////////////////////////////////////////////////////////////////
107 write(ostream &out, int indent) const {
108  #ifndef NDEBUG //[
109  out.width(indent); out<<""; out<<"BaseParticleEmitter:\n";
110  out.width(indent+2); out<<""; out<<"_emission_type "<<_emission_type<<"\n";
111  out.width(indent+2); out<<""; out<<"_amplitude "<<_amplitude<<"\n";
112  out.width(indent+2); out<<""; out<<"_amplitude_spread "<<_amplitude_spread<<"\n";
113  out.width(indent+2); out<<""; out<<"_offset_force "<<_offset_force<<"\n";
114  //ReferenceCount::write(out, indent+2);
115  #endif //] NDEBUG
116 }
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 ~BaseParticleEmitter()
destructor
void generate(LPoint3 &pos, LVector3 &vel)
parent generation function
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual void write(ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
bool normalize()
Normalizes the vector in place.
Definition: lvecBase3.h:783
Describes a physical region in space in which particles are randomly generated.