00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "correction.h"
00020 #include <clockObject.h>
00021
00022 #include <notifyCategoryProxy.h>
00023 NotifyCategoryDeclNoExport(correction);
00024 NotifyCategoryDef(correction, "");
00025
00026 Correction::Correction(LPoint3f& start, LVector3f& s_vel) : _curr_p(start),
00027 _curr_v(s_vel) {
00028 if(correction_cat.is_debug())
00029 correction_cat->debug() << "construction with:" << endl << "start = "
00030 << start << endl << "vel = " << s_vel << endl;
00031 }
00032
00033 Correction::~Correction(void) {
00034 }
00035
00036 void Correction::step(void) {
00037 }
00038
00039 void Correction::new_target(LPoint3f&, LVector3f&) {
00040 }
00041
00042 void Correction::force_target(LPoint3f&, LVector3f&) {
00043 }
00044
00045 LPoint3f Correction::get_pos(void) const {
00046 return _curr_p;
00047 }
00048
00049 LVector3f Correction::get_vel(void) const {
00050 return _curr_v;
00051 }
00052
00053
00054
00055 PopCorrection::PopCorrection(LPoint3f& start, LVector3f& s_vel)
00056 : Correction(start, s_vel) {
00057 }
00058
00059 PopCorrection::~PopCorrection(void) {
00060 }
00061
00062 void PopCorrection::step(void) {
00063 }
00064
00065 void PopCorrection::new_target(LPoint3f& target, LVector3f&) {
00066 _curr_p = target;
00067 }
00068
00069 void PopCorrection::force_target(LPoint3f& target, LVector3f&) {
00070 _curr_p = target;
00071 }
00072
00073
00074
00075 LerpCorrection::LerpCorrection(LPoint3f& start, LVector3f& s_vel)
00076 : Correction(start, s_vel), prev_p(start), save_p(start), have_both(false),
00077 time(0.0f), dur(0.5f) {
00078 }
00079
00080 LerpCorrection::~LerpCorrection(void) {
00081 }
00082
00083 void LerpCorrection::step(void) {
00084 if (have_both) {
00085 if (time < dur) {
00086 float tmp = time / dur;
00087 LVector3f vtmp = save_p - prev_p;
00088 _curr_p = (tmp * vtmp) + prev_p;
00089 time += ClockObject::get_global_clock()->get_dt();
00090 }
00091 }
00092 }
00093
00094 void LerpCorrection::new_target(LPoint3f& target, LVector3f&) {
00095 if (target == save_p)
00096 return;
00097 if (have_both) {
00098 time = 0.0f;
00099 prev_p = _curr_p;
00100 save_p = target;
00101 } else {
00102 save_p = target;
00103 _curr_p = prev_p;
00104 time = 0.0f;
00105 have_both = true;
00106 }
00107 }
00108
00109 void LerpCorrection::force_target(LPoint3f& target, LVector3f&) {
00110 if (target == save_p)
00111 return;
00112 _curr_p = prev_p = save_p = target;
00113 have_both = false;
00114 time = 0.0f;
00115 }
00116
00117 void LerpCorrection::set_duration(float d) {
00118 dur = d;
00119 }
00120
00121 float LerpCorrection::get_duration(void) const {
00122 return dur;
00123 }
00124
00125
00126
00127 SplineCorrection::SplineCorrection(LPoint3f& start, LVector3f& s_vel)
00128 : Correction(start, s_vel), have_both(false), prev_p(start), save_p(start),
00129 prev_v(s_vel), save_v(s_vel), time(0.0f), dur(0.5f) {
00130 }
00131
00132 SplineCorrection::~SplineCorrection(void) {
00133 }
00134
00135 void SplineCorrection::step(void) {
00136 if (have_both) {
00137 if (time < dur) {
00138 float tmp = time / dur;
00139 _curr_p = (tmp * tmp * tmp * A) + (tmp * tmp * B) + (tmp * C) + D;
00140 _curr_v = (3.0f * tmp * tmp * A) + (2.0f * tmp * B) + C;
00141 time += ClockObject::get_global_clock()->get_dt();
00142 if(correction_cat.is_spam()) {
00143 correction_cat->spam() << "new position = " << _curr_p << endl;
00144 correction_cat->spam() << "new vel = " << _curr_v << endl;
00145 }
00146 } else
00147 if(correction_cat.is_spam())
00148 correction_cat->spam() << "time >= dur, holding at current pos" << endl;
00149 } else
00150 if(correction_cat.is_spam())
00151 correction_cat->spam() << "have_both is false, no point calculated" << endl;
00152 }
00153
00154 void SplineCorrection::new_target(LPoint3f& target, LVector3f& v_target) {
00155 if (target == save_p) {
00156 if(correction_cat.is_spam())
00157 correction_cat->spam() << "new target: same point, no action" << endl;
00158 return;
00159 }
00160 if (have_both) {
00161 time = 0.0f;
00162 prev_p = _curr_p;
00163 prev_v = _curr_v;
00164 save_p = target;
00165 save_v = v_target;
00166 A = (2.0f * (prev_p - save_p)) + prev_v + save_v;
00167 B = (3.0f * (save_p - prev_p)) - (2.0f * prev_v) - save_v;
00168 C = prev_v;
00169 D = prev_p;
00170 if(correction_cat.is_debug()) {
00171 correction_cat->debug() << "new target: already had 'both'." << endl;
00172 correction_cat->debug() << "target = " << target << endl;
00173 correction_cat->debug() << "vel = " << v_target << endl;
00174 correction_cat->debug() << "A = " << A << endl;
00175 correction_cat->debug() << "B = " << B << endl;
00176 correction_cat->debug() << "C = " << C << endl;
00177 correction_cat->debug() << "D = " << D << endl;
00178 }
00179 } else {
00180 save_p = target;
00181 save_v = v_target;
00182 _curr_p = prev_p;
00183 _curr_v = prev_v;
00184 time = 0.0f;
00185 A = (2.0f * (prev_p - save_p)) + prev_v + save_v;
00186 B = (3.0f * (save_p - prev_p)) - (2.0f * prev_v) - save_v;
00187 C = prev_v;
00188 D = prev_p;
00189 have_both = true;
00190 if(correction_cat.is_debug()) {
00191 correction_cat->debug() << "new target: now have 'both'." << endl;
00192 correction_cat->debug() << "target = " << target << endl;
00193 correction_cat->debug() << "vel = " << v_target << endl;
00194 correction_cat->debug() << "A = " << A << endl;
00195 correction_cat->debug() << "B = " << B << endl;
00196 correction_cat->debug() << "C = " << C << endl;
00197 correction_cat->debug() << "D = " << D << endl;
00198 }
00199 }
00200 }
00201
00202 void SplineCorrection::force_target(LPoint3f& target, LVector3f& v_target) {
00203 if (target == save_p) {
00204 if(correction_cat.is_debug())
00205 correction_cat->debug() << "force target: same point, no action" << endl;
00206 return;
00207 }
00208 _curr_p = prev_p = save_p = target;
00209 _curr_v = prev_v = save_v = v_target;
00210 have_both = false;
00211 time = 0.0f;
00212 }
00213
00214 void SplineCorrection::set_duration(float d) {
00215 dur = d;
00216 }
00217
00218 float SplineCorrection::get_duration(void) const {
00219 return dur;
00220 }