Panda3D
Loading...
Searching...
No Matches
colorInterpolationManager.h
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 colorInterpolationManager.h
10 * @author joswilso
11 * @date 2005-06-02
12 */
13
14#ifndef COLORINTERPOLATIONMANAGER_H
15#define COLORINTERPOLATIONMANAGER_H
16
17#include "luse.h"
18#include "pvector.h"
19#include "typedObject.h"
20#include "typedReferenceCount.h"
21
22/**
23 * Abstract class from which all other functions should inherit. Defines the
24 * virtual interpolate() function.
25 */
26
27class EXPCL_PANDA_PARTICLESYSTEM ColorInterpolationFunction : public TypedReferenceCount {
28PUBLISHED:
29// virtual string get_type();
30
31public:
34
35 virtual LColor interpolate(const PN_stdfloat t = 0) const = 0;
36
37public:
38 static TypeHandle get_class_type() {
39 return _type_handle;
40 }
41
42 static void init_type() {
43 TypedReferenceCount::init_type();
44 register_type(_type_handle, "ColorInterpolationFunction",
45 TypedReferenceCount::get_class_type());
46 }
47
48 virtual TypeHandle get_type() const {
49 return get_class_type();
50 }
51 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
52private:
53 static TypeHandle _type_handle;
54};
55
56/**
57 * Defines a constant color over the lifetime of the segment.
58 */
59
60class EXPCL_PANDA_PARTICLESYSTEM ColorInterpolationFunctionConstant : public ColorInterpolationFunction {
61PUBLISHED:
62 INLINE LColor get_color_a() const;
63
64 INLINE void set_color_a(const LColor &c);
65
66public:
68 ColorInterpolationFunctionConstant(const LColor &color_a);
69
70protected:
71 virtual LColor interpolate(const PN_stdfloat t = 0) const;
72 // virtual string get_type();
73
74 LColor _c_a;
75
76public:
77 static TypeHandle get_class_type() {
78 return _type_handle;
79 }
80
81 static void init_type() {
82 ColorInterpolationFunction::init_type();
83 register_type(_type_handle, "ColorInterpolationFunctionConstant",
84 ColorInterpolationFunction::get_class_type());
85 }
86
87 virtual TypeHandle get_type() const {
88 return get_class_type();
89 }
90 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
91private:
92 static TypeHandle _type_handle;
93};
94
95/**
96 * Defines a linear interpolation over the lifetime of the segment.
97 */
98
100PUBLISHED:
101 INLINE LColor get_color_b() const;
102
103 INLINE void set_color_b(const LColor &c);
104
105public:
107 ColorInterpolationFunctionLinear(const LColor &color_a, const LColor &color_b);
108
109protected:
110 LColor interpolate(const PN_stdfloat t = 0) const;
111 // virtual string get_type();
112
113 LColor _c_b;
114
115public:
116 static TypeHandle get_class_type() {
117 return _type_handle;
118 }
119
120 static void init_type() {
121 ColorInterpolationFunctionConstant::init_type();
122 register_type(_type_handle, "ColorInterpolationFunctionLinear",
123 ColorInterpolationFunctionConstant::get_class_type());
124 }
125
126 virtual TypeHandle get_type() const {
127 return get_class_type();
128 }
129 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
130private:
131 static TypeHandle _type_handle;
132};
133
134/**
135 * Defines a discrete cyclical transition between two colors. The widths
136 * describe a portion of the segment's lifetime for which the corresponding
137 * color should be selected. If their sum is less than 1, the function
138 * repeats until the end of the segment.
139 */
140
142PUBLISHED:
143 INLINE PN_stdfloat get_width_a() const;
144 INLINE PN_stdfloat get_width_b() const;
145
146 INLINE void set_width_a(const PN_stdfloat w);
147 INLINE void set_width_b(const PN_stdfloat w);
148
149public:
151 ColorInterpolationFunctionStepwave(const LColor &color_a, const LColor &color_b, const PN_stdfloat width_a, const PN_stdfloat width_b);
152
153protected:
154 LColor interpolate(const PN_stdfloat t = 0) const;
155 // virtual string get_type();
156
157 PN_stdfloat _w_a;
158 PN_stdfloat _w_b;
159
160public:
161 static TypeHandle get_class_type() {
162 return _type_handle;
163 }
164
165 static void init_type() {
166 ColorInterpolationFunctionLinear::init_type();
167 register_type(_type_handle, "ColorInterpolationFunctionStepwave",
168 ColorInterpolationFunctionLinear::get_class_type());
169 }
170
171 virtual TypeHandle get_type() const {
172 return get_class_type();
173 }
174 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
175private:
176 static TypeHandle _type_handle;
177};
178
179/**
180 * Defines a sinusoidal blending between two colors. A period of "1"
181 * corresponds to a single transition from color_a to color_b and then back to
182 * color_a over the course of the segment's lifetime. A shorter period will
183 * result in a higher frequency cycle.
184 */
185
187PUBLISHED:
188 INLINE PN_stdfloat get_period() const;
189
190 INLINE void set_period(const PN_stdfloat p);
191
192public:
194 ColorInterpolationFunctionSinusoid(const LColor &color_a, const LColor &color_b, const PN_stdfloat period);
195
196protected:
197 LColor interpolate(const PN_stdfloat t = 0) const;
198 // virtual string get_type();
199
200 PN_stdfloat _period;
201
202public:
203 static TypeHandle get_class_type() {
204 return _type_handle;
205 }
206
207 static void init_type() {
208 ColorInterpolationFunctionLinear::init_type();
209 register_type(_type_handle, "ColorInterpolationFunctionSinusoid",
210 ColorInterpolationFunctionLinear::get_class_type());
211 }
212
213 virtual TypeHandle get_type() const {
214 return get_class_type();
215 }
216 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
217private:
218 static TypeHandle _type_handle;
219};
220
221/**
222 * A single unit of interpolation. The begin and end times are interpolated
223 * over the lifetime of the particle, thus have the range of [0,1]. Each
224 * segment also has a function associated with it.
225 */
226
227class EXPCL_PANDA_PARTICLESYSTEM ColorInterpolationSegment : public ReferenceCount {
228public:
229 ColorInterpolationSegment(ColorInterpolationFunction* function, const PN_stdfloat &time_begin, const PN_stdfloat &time_end, const bool is_modulated, const int id);
230
231PUBLISHED:
233
235
236 // INLINE ColorInterpolationFunction* get_function() const;
237 INLINE TypedReferenceCount* get_function() const;
238 INLINE PN_stdfloat get_time_begin() const;
239 INLINE PN_stdfloat get_time_end() const;
240 INLINE bool is_modulated() const;
241 INLINE int get_id() const;
242 INLINE bool is_enabled() const;
243
244 INLINE void set_function(ColorInterpolationFunction* function);
245 INLINE void set_time_begin(const PN_stdfloat time);
246 INLINE void set_time_end(const PN_stdfloat time);
247 INLINE void set_is_modulated(const bool flag);
248 INLINE void set_enabled(const bool enabled);
249
250public:
251 LColor interpolateColor(const PN_stdfloat t) const;
252
253protected:
254 PT(ColorInterpolationFunction) _color_inter_func;
255 PN_stdfloat _t_begin;
256 PN_stdfloat _t_end;
257 PN_stdfloat _t_total;
258 bool _is_modulated;
259 bool _enabled;
260 const int _id;
261};
262
263/**
264 * High level class for color interpolation. Segments must be added to the
265 * manager in order to achieve results using the "add_*****()" functions.
266 * Access to these segments is provided but not necessary general use.
267 */
268
269class EXPCL_PANDA_PARTICLESYSTEM ColorInterpolationManager : public ReferenceCount {
270PUBLISHED:
272 ColorInterpolationManager(const LColor &c);
275
276 int add_constant(const PN_stdfloat time_begin = 0.0f, const PN_stdfloat time_end = 1.0f, const LColor &color = LColor(1.0f,1.0f,1.0f,1.0f), const bool is_modulated = true);
277 int add_linear(const PN_stdfloat time_begin = 0.0f, const PN_stdfloat time_end = 1.0f, const LColor &color_a = LColor(1.0f,0.0f,0.0f,1.0f), const LColor &color_b = LColor(0.0f,1.0f,0.0f,1.0f), const bool is_modulated = true);
278 int add_stepwave(const PN_stdfloat time_begin = 0.0f, const PN_stdfloat time_end = 1.0f, const LColor &color_a = LColor(1.0f,0.0f,0.0f,1.0f), const LColor &color_b = LColor(0.0f,1.0f,0.0f,1.0f), const PN_stdfloat width_a = 0.5f, const PN_stdfloat width_b = 0.5f, const bool is_modulated = true);
279 int add_sinusoid(const PN_stdfloat time_begin = 0.0f, const PN_stdfloat time_end = 1.0f, const LColor &color_a = LColor(1.0f,0.0f,0.0f,1.0f), const LColor &color_b = LColor(0.0f,1.0f,0.0f,1.0f), const PN_stdfloat period = 1.0f, const bool is_modulated = true);
280
281 INLINE void set_default_color(const LColor &c);
282 INLINE ColorInterpolationSegment* get_segment(const int seg_id);
283 INLINE std::string get_segment_id_list();
284 void clear_segment(const int seg_id);
285 void clear_to_initial();
286
287public:
288 LColor generateColor(const PN_stdfloat interpolated_time);
289
290private:
291 LColor _default_color;
293 int _id_generator;
294};
295
297
298#endif //COLORINTERPOLATIONMANAGER_H
Defines a constant color over the lifetime of the segment.
Defines a linear interpolation over the lifetime of the segment.
Defines a sinusoidal blending between two colors.
Defines a discrete cyclical transition between two colors.
Abstract class from which all other functions should inherit.
High level class for color interpolation.
A single unit of interpolation.
A base class for all things that want to be reference-counted.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.