00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __LERPFUNCTOR_H__
00020 #define __LERPFUNCTOR_H__
00021
00022 #include <pandabase.h>
00023 #include <typedReferenceCount.h>
00024
00025 class EXPCL_PANDA LerpFunctor : public TypedReferenceCount {
00026 public:
00027 LerpFunctor(void) {}
00028 LerpFunctor(const LerpFunctor&);
00029 virtual ~LerpFunctor(void);
00030 LerpFunctor& operator=(const LerpFunctor&);
00031 virtual void operator()(float) = 0;
00032
00033 PUBLISHED:
00034 static TypeHandle get_class_type(void) {
00035 return _type_handle;
00036 }
00037
00038 public:
00039 static void init_type(void) {
00040 TypedReferenceCount::init_type();
00041 register_type(_type_handle, "LerpFunctor",
00042 TypedReferenceCount::get_class_type());
00043 }
00044 virtual TypeHandle get_type(void) const {
00045 return get_class_type();
00046 }
00047 virtual TypeHandle force_init_type(void) {
00048 init_type();
00049 return get_class_type();
00050 }
00051 private:
00052 static TypeHandle _type_handle;
00053 };
00054
00055 template <class value>
00056 class SimpleLerpFunctor : public LerpFunctor {
00057 protected:
00058 value _start;
00059 value _end;
00060 value _diff_cache;
00061
00062 SimpleLerpFunctor(value start, value end) : LerpFunctor(), _start(start),
00063 _end(end), _diff_cache(end-start)
00064 {}
00065 SimpleLerpFunctor(const SimpleLerpFunctor<value>&);
00066 public:
00067 virtual ~SimpleLerpFunctor(void);
00068 SimpleLerpFunctor<value>& operator=(const SimpleLerpFunctor<value>&);
00069 virtual void operator()(float);
00070
00071 PUBLISHED:
00072 value interpolate(float);
00073 INLINE const value &get_start() const { return _start; }
00074 INLINE const value &get_end() const { return _end; }
00075
00076 public:
00077 static TypeHandle get_class_type(void) {
00078 return _type_handle;
00079 }
00080 static void init_type(void) {
00081 LerpFunctor::init_type();
00082 do_init_type(value);
00083 ostringstream os;
00084 os << "SimpleLerpFunctor<" << get_type_handle(value).get_name() << ">";
00085 register_type(_type_handle, os.str(), LerpFunctor::get_class_type());
00086 }
00087 virtual TypeHandle get_type(void) const {
00088 return get_class_type();
00089 }
00090 virtual TypeHandle force_init_type(void) {
00091 init_type();
00092 return get_class_type();
00093 }
00094 private:
00095 static TypeHandle _type_handle;
00096 };
00097
00098 template <class value>
00099 TypeHandle SimpleLerpFunctor<value>::_type_handle;
00100
00101 template <class value>
00102 class SimpleQueryLerpFunctor : public SimpleLerpFunctor<value> {
00103 private:
00104 value _save;
00105 protected:
00106
00107
00108
00109 public:
00110 SimpleQueryLerpFunctor(value start, value end)
00111 : SimpleLerpFunctor<value>(start, end) {}
00112 virtual ~SimpleQueryLerpFunctor(void);
00113 SimpleQueryLerpFunctor<value>& operator=(const SimpleQueryLerpFunctor<value>&);
00114 virtual void operator()(float);
00115 PUBLISHED:
00116 value get_value(void);
00117
00118 static TypeHandle get_class_type(void) {
00119 return _type_handle;
00120 }
00121 public:
00122 static void init_type(void) {
00123 SimpleLerpFunctor<value>::init_type();
00124 ostringstream os;
00125 os << "SimpleQueryLerpFunctor<" << get_type_handle(value).get_name()
00126 << ">";
00127 register_type(_type_handle, os.str(),
00128 SimpleLerpFunctor<value>::get_class_type());
00129 }
00130 virtual TypeHandle get_type(void) const {
00131 return get_class_type();
00132 }
00133 virtual TypeHandle force_init_type(void) {
00134 init_type();
00135 return get_class_type();
00136 }
00137 private:
00138 static TypeHandle _type_handle;
00139 };
00140
00141 template <class value>
00142 TypeHandle SimpleQueryLerpFunctor<value>::_type_handle;
00143
00144 #include <luse.h>
00145
00146 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<int>)
00147 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<float>)
00148 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LPoint2f>)
00149 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LPoint3f>)
00150 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LPoint4f>)
00151 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LVecBase2f>)
00152 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LVecBase3f>)
00153 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LVecBase4f>)
00154 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LVector2f>)
00155 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LVector3f>)
00156 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleLerpFunctor<LVector4f>)
00157
00158 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<int>)
00159 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<float>)
00160 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LPoint2f>)
00161 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LPoint3f>)
00162 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LPoint4f>)
00163 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LVecBase2f>)
00164 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LVecBase3f>)
00165 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LVecBase4f>)
00166 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LVector2f>)
00167 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LVector3f>)
00168 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, SimpleQueryLerpFunctor<LVector4f>)
00169
00170 typedef SimpleLerpFunctor<int> IntLerpFunctor;
00171 typedef SimpleLerpFunctor<float> FloatLerpFunctor;
00172 typedef SimpleLerpFunctor<LPoint2f> LPoint2fLerpFunctor;
00173 typedef SimpleLerpFunctor<LPoint3f> LPoint3fLerpFunctor;
00174 typedef SimpleLerpFunctor<LPoint4f> LPoint4fLerpFunctor;
00175 typedef SimpleLerpFunctor<LVecBase2f> LVecBase2fLerpFunctor;
00176 typedef SimpleLerpFunctor<LVecBase3f> LVecBase3fLerpFunctor;
00177 typedef SimpleLerpFunctor<LVecBase4f> LVecBase4fLerpFunctor;
00178 typedef SimpleLerpFunctor<LVector2f> LVector2fLerpFunctor;
00179 typedef SimpleLerpFunctor<LVector3f> LVector3fLerpFunctor;
00180 typedef SimpleLerpFunctor<LVector4f> LVector4fLerpFunctor;
00181
00182 typedef SimpleQueryLerpFunctor<int> IntQueryLerpFunctor;
00183 typedef SimpleQueryLerpFunctor<float> FloatQueryLerpFunctor;
00184 typedef SimpleQueryLerpFunctor<LPoint2f> LPoint2fQueryLerpFunctor;
00185 typedef SimpleQueryLerpFunctor<LPoint3f> LPoint3fQueryLerpFunctor;
00186 typedef SimpleQueryLerpFunctor<LPoint4f> LPoint4fQueryLerpFunctor;
00187 typedef SimpleQueryLerpFunctor<LVecBase2f> LVecBase2fQueryLerpFunctor;
00188 typedef SimpleQueryLerpFunctor<LVecBase3f> LVecBase3fQueryLerpFunctor;
00189 typedef SimpleQueryLerpFunctor<LVecBase4f> LVecBase4fQueryLerpFunctor;
00190 typedef SimpleQueryLerpFunctor<LVector2f> LVector2fQueryLerpFunctor;
00191 typedef SimpleQueryLerpFunctor<LVector3f> LVector3fQueryLerpFunctor;
00192 typedef SimpleQueryLerpFunctor<LVector4f> LVector4fQueryLerpFunctor;
00193
00194 #include "pset.h"
00195 #include <pointerTo.h>
00196
00197 class EXPCL_PANDA MultiLerpFunctor : public LerpFunctor {
00198 private:
00199 typedef pset< PT(LerpFunctor) > Functors;
00200 Functors _funcs;
00201 public:
00202 MultiLerpFunctor(void) {}
00203 MultiLerpFunctor(const MultiLerpFunctor&);
00204 virtual ~MultiLerpFunctor(void);
00205 MultiLerpFunctor& operator=(const MultiLerpFunctor&);
00206 virtual void operator()(float);
00207 void add_functor(LerpFunctor*);
00208 void remove_functor(LerpFunctor*);
00209
00210 PUBLISHED:
00211 static TypeHandle get_class_type(void) {
00212 return _type_handle;
00213 }
00214
00215 public:
00216 static void init_type(void) {
00217 LerpFunctor::init_type();
00218 register_type(_type_handle, "MultiLerpFunctor",
00219 LerpFunctor::get_class_type());
00220 }
00221 virtual TypeHandle get_type(void) const {
00222 return get_class_type();
00223 }
00224 virtual TypeHandle force_init_type(void) {
00225 init_type();
00226 return get_class_type();
00227 }
00228 private:
00229 static TypeHandle _type_handle;
00230 };
00231
00232
00233
00234
00235
00236 template <class value>
00237 SimpleLerpFunctor<value>::SimpleLerpFunctor(const SimpleLerpFunctor<value>& c)
00238 : LerpFunctor(c), _start(c._start), _end(c._end), _diff_cache(c._diff_cache)
00239 {}
00240
00241 template <class value>
00242 SimpleLerpFunctor<value>::~SimpleLerpFunctor(void)
00243 {
00244 }
00245
00246 template <class value>
00247 SimpleLerpFunctor<value>&
00248 SimpleLerpFunctor<value>::operator=(const SimpleLerpFunctor& c) {
00249 _start = c._start;
00250 _end = c._end;
00251 _diff_cache = c._diff_cache;
00252 LerpFunctor::operator=(c);
00253 return *this;
00254 }
00255
00256 template <class value>
00257 void SimpleLerpFunctor<value>::operator()(float) {
00258
00259 }
00260
00261 template <class value>
00262 value SimpleLerpFunctor<value>::interpolate(float t) {
00263 return ((t * _diff_cache) + _start);
00264 }
00265
00266
00267
00268
00269
00270
00271 template <class value>
00272 SimpleQueryLerpFunctor<value>::~SimpleQueryLerpFunctor(void)
00273 {
00274 }
00275
00276 template <class value>
00277 SimpleQueryLerpFunctor<value>&
00278 SimpleQueryLerpFunctor<value>::operator=(const SimpleQueryLerpFunctor& c) {
00279 _save = c._save;
00280 SimpleLerpFunctor<value>::operator=(c);
00281 return *this;
00282 }
00283
00284 template <class value>
00285 void SimpleQueryLerpFunctor<value>::operator()(float t) {
00286 _save = interpolate(t);
00287 }
00288
00289 template <class value>
00290 value SimpleQueryLerpFunctor<value>::get_value(void) {
00291 return _save;
00292 }
00293
00294 #endif