make the duration of the lerping correctors settable

This commit is contained in:
Cary Sandvig 2000-12-22 01:17:34 +00:00
parent 3ac90489b0
commit 7a7ba255b7
2 changed files with 30 additions and 8 deletions

View File

@ -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;
}

View File

@ -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__ */