mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
make the duration of the lerping correctors settable
This commit is contained in:
parent
3ac90489b0
commit
7a7ba255b7
@ -47,7 +47,7 @@ void PopCorrection::new_target(LPoint3f& target, LVector3f&) {
|
|||||||
|
|
||||||
LerpCorrection::LerpCorrection(LPoint3f& start, LVector3f& s_vel)
|
LerpCorrection::LerpCorrection(LPoint3f& start, LVector3f& s_vel)
|
||||||
: Correction(start, s_vel), prev_p(start), save_p(start), have_both(false),
|
: Correction(start, s_vel), prev_p(start), save_p(start), have_both(false),
|
||||||
time(0.) {
|
time(0.), dur(0.5) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LerpCorrection::~LerpCorrection(void) {
|
LerpCorrection::~LerpCorrection(void) {
|
||||||
@ -55,9 +55,8 @@ LerpCorrection::~LerpCorrection(void) {
|
|||||||
|
|
||||||
void LerpCorrection::step(void) {
|
void LerpCorrection::step(void) {
|
||||||
if (have_both) {
|
if (have_both) {
|
||||||
if (time < 0.5) {
|
if (time < dur) {
|
||||||
// half second lerp
|
float tmp = time / dur;
|
||||||
float tmp = time * 2.;
|
|
||||||
LVector3f vtmp = save_p - prev_p;
|
LVector3f vtmp = save_p - prev_p;
|
||||||
_curr_p = (tmp * vtmp) + prev_p;
|
_curr_p = (tmp * vtmp) + prev_p;
|
||||||
time += ClockObject::get_global_clock()->get_dt();
|
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)
|
SplineCorrection::SplineCorrection(LPoint3f& start, LVector3f& s_vel)
|
||||||
: Correction(start, s_vel), have_both(false), prev_p(start), save_p(start),
|
: 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) {
|
SplineCorrection::~SplineCorrection(void) {
|
||||||
@ -92,9 +99,8 @@ SplineCorrection::~SplineCorrection(void) {
|
|||||||
|
|
||||||
void SplineCorrection::step(void) {
|
void SplineCorrection::step(void) {
|
||||||
if (have_both) {
|
if (have_both) {
|
||||||
if (time < 0.5) {
|
if (time < dur) {
|
||||||
// half second lerp
|
float tmp = time / dur;
|
||||||
float tmp = time * 2.;
|
|
||||||
_curr_p = (tmp * tmp * tmp * A) + (tmp * tmp * B) + (tmp * C) + D;
|
_curr_p = (tmp * tmp * tmp * A) + (tmp * tmp * B) + (tmp * C) + D;
|
||||||
_curr_v = (3. * tmp * tmp * A) + (2. * tmp * B) + C;
|
_curr_v = (3. * tmp * tmp * A) + (2. * tmp * B) + C;
|
||||||
time += ClockObject::get_global_clock()->get_dt();
|
time += ClockObject::get_global_clock()->get_dt();
|
||||||
@ -128,3 +134,11 @@ void SplineCorrection::new_target(LPoint3f& target, LVector3f& v_target) {
|
|||||||
have_both = true;
|
have_both = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SplineCorrection::set_duration(float d) {
|
||||||
|
dur = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
float SplineCorrection::get_duration(void) const {
|
||||||
|
return dur;
|
||||||
|
}
|
||||||
|
@ -38,12 +38,16 @@ private:
|
|||||||
LPoint3f prev_p, save_p;
|
LPoint3f prev_p, save_p;
|
||||||
bool have_both;
|
bool have_both;
|
||||||
float time;
|
float time;
|
||||||
|
float dur;
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
LerpCorrection(LPoint3f&, LVector3f&);
|
LerpCorrection(LPoint3f&, LVector3f&);
|
||||||
virtual ~LerpCorrection(void);
|
virtual ~LerpCorrection(void);
|
||||||
|
|
||||||
virtual void step(void);
|
virtual void step(void);
|
||||||
virtual void new_target(LPoint3f&, LVector3f&);
|
virtual void new_target(LPoint3f&, LVector3f&);
|
||||||
|
|
||||||
|
void set_duration(float);
|
||||||
|
float get_duration(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SplineCorrection : public Correction {
|
class SplineCorrection : public Correction {
|
||||||
@ -53,12 +57,16 @@ private:
|
|||||||
LPoint3f prev_p, save_p;
|
LPoint3f prev_p, save_p;
|
||||||
LVector3f prev_v, save_v;
|
LVector3f prev_v, save_v;
|
||||||
float time;
|
float time;
|
||||||
|
float dur;
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
SplineCorrection(LPoint3f&, LVector3f&);
|
SplineCorrection(LPoint3f&, LVector3f&);
|
||||||
virtual ~SplineCorrection(void);
|
virtual ~SplineCorrection(void);
|
||||||
|
|
||||||
virtual void step(void);
|
virtual void step(void);
|
||||||
virtual void new_target(LPoint3f&, LVector3f&);
|
virtual void new_target(LPoint3f&, LVector3f&);
|
||||||
|
|
||||||
|
void set_duration(float);
|
||||||
|
float get_duration(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __CORRECTION_H__ */
|
#endif /* __CORRECTION_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user