00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "cConstrainPosInterval.h"
00016 #include "config_interval.h"
00017 #include "lvecBase3.h"
00018
00019 TypeHandle CConstrainPosInterval::_type_handle;
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 CConstrainPosInterval::
00033 CConstrainPosInterval(const string &name, double duration,
00034 const NodePath &node, const NodePath &target,
00035 bool wrt, const LVecBase3 posOffset) :
00036 CConstraintInterval(name, duration),
00037 _node(node),
00038 _target(target),
00039 _wrt(wrt),
00040 _posOffset(posOffset)
00041 {
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051 void CConstrainPosInterval::
00052 priv_step(double t) {
00053 check_started(get_class_type(), "priv_step");
00054 _state = S_started;
00055 _curr_t = t;
00056
00057 if(! _target.is_empty()) {
00058 if(_wrt) {
00059 if(! _node.is_same_graph(_target)){
00060 interval_cat.warning()
00061 << "Unable to copy position in CConstrainPosInterval::priv_step;\n"
00062 << "node (" << _node.get_name()
00063 << ") and target (" << _target.get_name()
00064 << ") are not in the same graph.\n";
00065 return;
00066 }
00067 _target.set_pos(_node, _posOffset);
00068 } else {
00069 if(_posOffset == LVector3::zero()) {
00070 _target.set_pos(_node.get_pos());
00071 } else {
00072 _target.set_pos(_node.get_pos() + _posOffset);
00073 }
00074 }
00075 }
00076 }
00077
00078
00079
00080
00081
00082
00083 void CConstrainPosInterval::
00084 output(ostream &out) const {
00085 out << get_name() << ":";
00086 out << " dur " << get_duration();
00087 }