diff --git a/direct/src/deadrec/Sources.pp b/direct/src/deadrec/Sources.pp new file mode 100644 index 0000000000..1ab8b4b866 --- /dev/null +++ b/direct/src/deadrec/Sources.pp @@ -0,0 +1,15 @@ +#begin lib_target + #define TARGET deadrec + + #define SOURCES \ + correction.cxx prediction.cxx + + #define INSTALL_HEADERS \ + correction.h prediction.h + + #define IGATESCAN \ + correction.h prediction.h + + #define LOCAL_LIBS \ + directbase +#end lib_target diff --git a/direct/src/deadrec/correction.cxx b/direct/src/deadrec/correction.cxx new file mode 100644 index 0000000000..d7488250b2 --- /dev/null +++ b/direct/src/deadrec/correction.cxx @@ -0,0 +1,126 @@ +// Filename: correction.cxx +// Created by: cary (20Dec00) +// +//////////////////////////////////////////////////////////////////// + +#include "correction.h" +#include + +Correction::Correction(LPoint3f& start, LVector3f& s_vel) : _curr_p(start), + _curr_v(s_vel) { +} + +Correction::~Correction(void) { +} + +void Correction::step(void) { +} + +void Correction::new_target(LPoint3f&, LVector3f&) { +} + +LPoint3f Correction::get_pos(void) const { + return _curr_p; +} + +LVector3f Correction::get_vel(void) const { + return _curr_v; +} + +//////////////////////////////////////////////////////////////////// + +PopCorrection::PopCorrection(LPoint3f& start, LVector3f& s_vel) + : Correction(start, s_vel) { +} + +PopCorrection::~PopCorrection(void) { +} + +void PopCorrection::step(void) { +} + +void PopCorrection::new_target(LPoint3f& target, LVector3f&) { + _curr_p = target; +} + +///////////////////////////////////////////////////////////////////// + +LerpCorrection::LerpCorrection(LPoint3f& start, LVector3f& s_vel) + : Correction(start, s_vel), prev_p(start), save_p(start), have_both(false), + time(0.) { +} + +LerpCorrection::~LerpCorrection(void) { +} + +void LerpCorrection::step(void) { + if (have_both) { + if (time < 0.5) { + // half second lerp + float tmp = time * 2.; + LVector3f vtmp = save_p - prev_p; + _curr_p = (tmp * vtmp) + prev_p; + time += ClockObject::get_global_clock()->get_dt(); + } + } +} + +void LerpCorrection::new_target(LPoint3f& target, LVector3f&) { + if (have_both) { + time = 0.; + prev_p = _curr_p; + save_p = target; + } else { + save_p = target; + _curr_p = prev_p; + time = 0.; + have_both = true; + } +} + +///////////////////////////////////////////////////////////////////// + +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.) { +} + +SplineCorrection::~SplineCorrection(void) { +} + +void SplineCorrection::step(void) { + if (have_both) { + if (time < 0.5) { + // half second lerp + float tmp = time * 2.; + _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(); + } + } +} + +void SplineCorrection::new_target(LPoint3f& target, LVector3f& v_target) { + if (have_both) { + time = 0.; + prev_p = _curr_p; + prev_v = _curr_v; + save_p = target; + save_v = v_target; + A = (2. * (prev_p - save_p)) + prev_v + save_v; + B = (3. * (save_p - prev_p)) - (2. * prev_v) - save_v; + C = prev_v; + D = prev_p; + } else { + save_p = target; + save_v = v_target; + _curr_p = prev_p; + _curr_v = prev_v; + time = 0.; + A = (2. * (prev_p - save_p)) + prev_v + save_v; + B = (3. * (save_p - prev_p)) - (2. * prev_v) - save_v; + C = prev_v; + D = prev_p; + have_both = true; + } +} diff --git a/direct/src/deadrec/correction.h b/direct/src/deadrec/correction.h new file mode 100644 index 0000000000..9e3495d451 --- /dev/null +++ b/direct/src/deadrec/correction.h @@ -0,0 +1,64 @@ +// Filename: correction.h +// Created by: cary (20Dec00) +// +//////////////////////////////////////////////////////////////////// + +#ifndef __CORRECTION_H__ +#define __CORRECTION_H__ + +#include +#include + +class Correction { +protected: + LPoint3f _curr_p; + LVector3f _curr_v; +PUBLISHED: + Correction(LPoint3f&, LVector3f&); + virtual ~Correction(void); + + virtual void step(void); + virtual void new_target(LPoint3f&, LVector3f&); + + LPoint3f get_pos(void) const; + LVector3f get_vel(void) const; +}; + +class PopCorrection : public Correction { +PUBLISHED: + PopCorrection(LPoint3f&, LVector3f&); + virtual ~PopCorrection(void); + + virtual void step(void); + virtual void new_target(LPoint3f&, LVector3f&); +}; + +class LerpCorrection : public Correction { +private: + LPoint3f prev_p, save_p; + bool have_both; + float time; +PUBLISHED: + LerpCorrection(LPoint3f&, LVector3f&); + virtual ~LerpCorrection(void); + + virtual void step(void); + virtual void new_target(LPoint3f&, LVector3f&); +}; + +class SplineCorrection : public Correction { +private: + LPoint3f A, B, C, D; + bool have_both; + LPoint3f prev_p, save_p; + LVector3f prev_v, save_v; + float time; +PUBLISHED: + SplineCorrection(LPoint3f&, LVector3f&); + virtual ~SplineCorrection(void); + + virtual void step(void); + virtual void new_target(LPoint3f&, LVector3f&); +}; + +#endif /* __CORRECTION_H__ */ diff --git a/direct/src/deadrec/prediction.cxx b/direct/src/deadrec/prediction.cxx new file mode 100644 index 0000000000..6b56626575 --- /dev/null +++ b/direct/src/deadrec/prediction.cxx @@ -0,0 +1,57 @@ +// Filename: prediction.cxx +// Created by: cary (20Dec00) +// +//////////////////////////////////////////////////////////////////// + +#include "prediction.h" + +Prediction::Prediction(LPoint3f& start) : _curr_p(start), _curr_v(0., 0., 0.) { +} + +Prediction::~Prediction(void) { +} + +void Prediction::step(void) { +} + +void Prediction::new_telemetry(LPoint3f& t_pos) { +} + +LPoint3f Prediction::get_pos(void) const { + return _curr_p; +} + +LVector3f Prediction::get_vel(void) const { + return _curr_v; +} + +////////////////////////////////////////////////////////////////////// + +NullPrediction::NullPrediction(LPoint3f& start) : Prediction(start) { +} + +NullPrediction::~NullPrediction(void) { +} + +void NullPrediction::step(void) { +} + +void NullPrediction::new_telemetry(LPoint3f& t_pos) { + // _curr_v = _curr_p - t_pos; + _curr_v = t_pos - _curr_p; + _curr_p = t_pos; +} + +////////////////////////////////////////////////////////////////////// + +LinearPrediction::LinearPrediction(LPoint3f& start) : Prediction(start) { +} + +LinearPrediction::~LinearPrediction(void) { +} + +void LinearPrediction::step(void) { +} + +void LinearPrediction::new_telemetry(LPoint3f& t_pos) { +} diff --git a/direct/src/deadrec/prediction.h b/direct/src/deadrec/prediction.h new file mode 100644 index 0000000000..06f972631f --- /dev/null +++ b/direct/src/deadrec/prediction.h @@ -0,0 +1,45 @@ +// Filename: prediction.h +// Created by: cary (20Dec00) +// +//////////////////////////////////////////////////////////////////// + +#ifndef __PREDICTION_H__ +#define __PREDICTION_H__ + +#include +#include + +class Prediction { +protected: + LPoint3f _curr_p; + LVector3f _curr_v; +PUBLISHED: + Prediction(LPoint3f&); + virtual ~Prediction(void); + + virtual void step(void); + virtual void new_telemetry(LPoint3f&); + + LPoint3f get_pos(void) const; + LVector3f get_vel(void) const; +}; + +class NullPrediction : public Prediction { +PUBLISHED: + NullPrediction(LPoint3f&); + virtual ~NullPrediction(void); + + virtual void step(void); + virtual void new_telemetry(LPoint3f&); +}; + +class LinearPrediction : public Prediction { +PUBLISHED: + LinearPrediction(LPoint3f&); + virtual ~LinearPrediction(void); + + virtual void step(void); + virtual void new_telemetry(LPoint3f&); +}; + +#endif /* __PREDICTION_H__ */