From 7a7ba255b7152ed5b679f6f0390d9a62eeb2df76 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Fri, 22 Dec 2000 01:17:34 +0000 Subject: [PATCH] make the duration of the lerping correctors settable --- direct/src/deadrec/correction.cxx | 30 ++++++++++++++++++++++-------- direct/src/deadrec/correction.h | 8 ++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/direct/src/deadrec/correction.cxx b/direct/src/deadrec/correction.cxx index 7a88ff2a69..fa1468f7fc 100644 --- a/direct/src/deadrec/correction.cxx +++ b/direct/src/deadrec/correction.cxx @@ -47,7 +47,7 @@ void PopCorrection::new_target(LPoint3f& target, LVector3f&) { LerpCorrection::LerpCorrection(LPoint3f& start, LVector3f& s_vel) : Correction(start, s_vel), prev_p(start), save_p(start), have_both(false), - time(0.) { + time(0.), dur(0.5) { } LerpCorrection::~LerpCorrection(void) { @@ -55,9 +55,8 @@ LerpCorrection::~LerpCorrection(void) { void LerpCorrection::step(void) { if (have_both) { - if (time < 0.5) { - // half second lerp - float tmp = time * 2.; + if (time < dur) { + float tmp = time / dur; LVector3f vtmp = save_p - prev_p; _curr_p = (tmp * vtmp) + prev_p; time += ClockObject::get_global_clock()->get_dt(); @@ -80,11 +79,19 @@ void LerpCorrection::new_target(LPoint3f& target, LVector3f&) { } } +void LerpCorrection::set_duration(float d) { + dur = d; +} + +float LerpCorrection::get_duration(void) const { + return dur; +} + ///////////////////////////////////////////////////////////////////// SplineCorrection::SplineCorrection(LPoint3f& start, LVector3f& s_vel) : Correction(start, s_vel), have_both(false), prev_p(start), save_p(start), - prev_v(s_vel), save_v(s_vel), time(0.) { + prev_v(s_vel), save_v(s_vel), time(0.), dur(0.5) { } SplineCorrection::~SplineCorrection(void) { @@ -92,9 +99,8 @@ SplineCorrection::~SplineCorrection(void) { void SplineCorrection::step(void) { if (have_both) { - if (time < 0.5) { - // half second lerp - float tmp = time * 2.; + if (time < dur) { + float tmp = time / dur; _curr_p = (tmp * tmp * tmp * A) + (tmp * tmp * B) + (tmp * C) + D; _curr_v = (3. * tmp * tmp * A) + (2. * tmp * B) + C; time += ClockObject::get_global_clock()->get_dt(); @@ -128,3 +134,11 @@ void SplineCorrection::new_target(LPoint3f& target, LVector3f& v_target) { have_both = true; } } + +void SplineCorrection::set_duration(float d) { + dur = d; +} + +float SplineCorrection::get_duration(void) const { + return dur; +} diff --git a/direct/src/deadrec/correction.h b/direct/src/deadrec/correction.h index 9e3495d451..cbe10c7177 100644 --- a/direct/src/deadrec/correction.h +++ b/direct/src/deadrec/correction.h @@ -38,12 +38,16 @@ private: LPoint3f prev_p, save_p; bool have_both; float time; + float dur; PUBLISHED: LerpCorrection(LPoint3f&, LVector3f&); virtual ~LerpCorrection(void); virtual void step(void); virtual void new_target(LPoint3f&, LVector3f&); + + void set_duration(float); + float get_duration(void) const; }; class SplineCorrection : public Correction { @@ -53,12 +57,16 @@ private: LPoint3f prev_p, save_p; LVector3f prev_v, save_v; float time; + float dur; PUBLISHED: SplineCorrection(LPoint3f&, LVector3f&); virtual ~SplineCorrection(void); virtual void step(void); virtual void new_target(LPoint3f&, LVector3f&); + + void set_duration(float); + float get_duration(void) const; }; #endif /* __CORRECTION_H__ */