00001 // Filename: cConstrainTransformInterval.cxx 00002 // Created by: pratt (29Sep06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "cConstrainTransformInterval.h" 00016 #include "transformState.h" 00017 #include "config_interval.h" 00018 00019 TypeHandle CConstrainTransformInterval::_type_handle; 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: CConstrainTransformInterval::Constructor 00023 // Access: Published 00024 // Description: Constructs a constraint interval that will constrain 00025 // the transform of one node to the transform of another. 00026 // To clarify, the transform of node will be copied to target. 00027 // 00028 // If wrt is true, the node's transform will be 00029 // transformed into the target node's parent's space 00030 // before being copied. If wrt is false, the node's 00031 // local transform will be copied unaltered. 00032 //////////////////////////////////////////////////////////////////// 00033 CConstrainTransformInterval:: 00034 CConstrainTransformInterval(const string &name, double duration, 00035 const NodePath &node, const NodePath &target, 00036 bool wrt) : 00037 CConstraintInterval(name, duration), 00038 _node(node), 00039 _target(target), 00040 _wrt(wrt) 00041 { 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: CConstrainTransformInterval::step 00046 // Access: Published, Virtual 00047 // Description: Advances the time on the interval. The time may 00048 // either increase (the normal case) or decrease 00049 // (e.g. if the interval is being played by a slider). 00050 //////////////////////////////////////////////////////////////////// 00051 void CConstrainTransformInterval:: 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 CPT(TransformState) transform; 00059 if(_wrt) { 00060 if(! _node.is_same_graph(_target)){ 00061 interval_cat.warning() 00062 << "Unable to copy transform in CConstrainTransformInterval::priv_step;\n" 00063 << "node (" << _node.get_name() 00064 << ") and target (" << _target.get_name() 00065 << ") are not in the same graph.\n"; 00066 return; 00067 } 00068 transform = _node.get_transform(_target.get_parent()); 00069 } else { 00070 transform = _node.get_transform(); 00071 } 00072 00073 _target.set_transform(transform); 00074 } 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: CConstrainTransformInterval::output 00079 // Access: Published, Virtual 00080 // Description: 00081 //////////////////////////////////////////////////////////////////// 00082 void CConstrainTransformInterval:: 00083 output(ostream &out) const { 00084 out << get_name() << ":"; 00085 out << " dur " << get_duration(); 00086 }