Pie Noon
An open source project by FPL.
 All Classes Pages
particles.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef PARTICLES_H
16 #define PARTICLES_H
17 
18 #include <list>
19 #include "common.h"
20 #include "scene_description.h"
21 
22 namespace fpl {
23 namespace pie_noon {
24 
25 typedef float TimeStep;
26 
27 class Particle {
28  public:
29  Particle() { reset(); }
30 
31  void reset();
32 
33  mathfu::vec3 CurrentPosition() const;
34  mathfu::vec3 CurrentVelocity() const;
35  Quat CurrentOrientation() const;
36  mathfu::vec4 CurrentTint() const;
37  mathfu::vec3 CurrentScale() const;
38  TimeStep DurationRemaining() const;
39 
40  void SetDurationRemaining(TimeStep duration);
41 
42  mathfu::vec3 base_position() const { return base_position_; }
43 
44  void set_base_position(const mathfu::vec3& base_position) {
45  base_position_ = base_position;
46  }
47 
48  mathfu::vec3 base_velocity() const { return base_velocity_; }
49  void set_base_velocity(const mathfu::vec3& base_velocity) {
50  base_velocity_ = base_velocity;
51  }
52 
53  mathfu::vec3 acceleration() const { return acceleration_; }
54  void set_acceleration(const mathfu::vec3& acceleration) {
55  acceleration_ = acceleration;
56  }
57 
58  mathfu::vec3 base_orientation() const { return base_orientation_; }
59  void set_base_orientation(const mathfu::vec3& base_orientation) {
60  base_orientation_ = base_orientation;
61  }
62 
63  mathfu::vec3 rotational_velocity() const { return rotational_velocity_; }
64  void set_rotational_velocity(const mathfu::vec3& rotational_velocity) {
65  rotational_velocity_ = rotational_velocity;
66  }
67 
68  mathfu::vec4 base_tint() const { return base_tint_; }
69  void set_base_tint(const mathfu::vec4& base_tint) { base_tint_ = base_tint; }
70 
71  mathfu::vec3 base_scale() const { return base_scale_; }
72  void set_base_scale(const mathfu::vec3& base_scale) {
73  base_scale_ = base_scale;
74  }
75 
76  TimeStep duration_of_fade_out() const { return duration_of_fade_out_; }
77  void set_duration_of_fade_out(TimeStep duration_of_fade_out) {
78  duration_of_fade_out_ = duration_of_fade_out;
79  }
80 
81  TimeStep duration_of_shrink_out() const { return duration_of_shrink_out_; }
82  void set_duration_of_shrink_out(TimeStep duration_of_shrink_out) {
83  duration_of_shrink_out_ = duration_of_shrink_out;
84  }
85 
86  uint16_t renderable_id() const { return renderable_id_; }
87  void set_renderable_id(uint16_t renderable_id) {
88  renderable_id_ = renderable_id;
89  }
90 
91  TimeStep duration() const { return duration_; }
92  void set_duration(TimeStep duration) { duration_ = duration; }
93 
94  TimeStep age() const { return age_; }
95  void set_age(TimeStep age) { age_ = age; }
96 
97  // Generate the matrix we'll need to draw it:
98  mathfu::mat4 CalculateMatrix() const;
99 
100  void AdvanceFrame(TimeStep delta_time);
101  bool IsFinished() const;
102 
103  private:
104  mathfu::vec3 base_position_;
105  mathfu::vec3 base_velocity_;
106  mathfu::vec3 acceleration_;
107 
108  // Expressed in Euler angles:
109  mathfu::vec3 base_orientation_;
110  mathfu::vec3 rotational_velocity_;
111 
112  mathfu::vec3 base_scale_;
113  mathfu::vec4 base_tint_;
114 
115  // How long the particle will last, in milliseconds.
116  TimeStep duration_;
117 
118  // How long the particle has been alive so far, in milliseconds
119  TimeStep age_;
120 
121  // How long it will take the particle to fade or shrink away, when it reaches
122  // the end of its life span. (In milliseconds)
123  TimeStep duration_of_fade_out_;
124  TimeStep duration_of_shrink_out_;
125 
126  // the renderable ID we should use when drawing this particle.
127  uint16_t renderable_id_;
128 };
129 
131  public:
132  void AdvanceFrame(TimeStep delta_time);
133 
134  const std::list<Particle*>& get_particle_list() const {
135  return particle_list_;
136  }
137 
138  // Returns a pointer to a new particle, ready to be populated.
139  // Note that this pointer is not guaranteed to be valid indefinitely!
140  // Also note that the initial state of the particle is undetermined, so
141  // users should either populate every field explicitly, or call
142  // Particle::reset().
143  Particle* CreateParticle();
144 
145  // Removes all active particles.
146  void RemoveAllParticles();
147 
148  private:
149  std::list<Particle*> particle_list_;
150  std::list<Particle*> inactive_particle_list_;
151 };
152 
153 } // pie_noon
154 } // fpl
155 #endif // PARTICLES_H
Definition: particles.h:27
Definition: particles.h:130