00001 // Filename: cConstrainPosHprInterval.cxx 00002 // Created by: pratt (10Mar08) 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 "cConstrainPosHprInterval.h" 00016 #include "config_interval.h" 00017 #include "lvecBase3.h" 00018 00019 TypeHandle CConstrainPosHprInterval::_type_handle; 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: CConstrainPosHprInterval::Constructor 00023 // Access: Published 00024 // Description: Constructs a constraint interval that will constrain 00025 // the position and orientation of one node to the 00026 // position and orientation of another. 00027 // 00028 // If wrt is true, the node's position and orientation 00029 // will be transformed into the target node's parent's 00030 // space before being copied. If wrt is false, the 00031 // target node's local position and orientation will be 00032 // copied unaltered. 00033 //////////////////////////////////////////////////////////////////// 00034 CConstrainPosHprInterval:: 00035 CConstrainPosHprInterval(const string &name, double duration, 00036 const NodePath &node, const NodePath &target, 00037 bool wrt, const LVecBase3 posOffset, 00038 const LVecBase3 hprOffset) : 00039 CConstraintInterval(name, duration), 00040 _node(node), 00041 _target(target), 00042 _wrt(wrt), 00043 _posOffset(posOffset) 00044 { 00045 _quatOffset.set_hpr(hprOffset); 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: CConstrainPosHprInterval::step 00050 // Access: Published, Virtual 00051 // Description: Advances the time on the interval. The time may 00052 // either increase (the normal case) or decrease 00053 // (e.g. if the interval is being played by a slider). 00054 //////////////////////////////////////////////////////////////////// 00055 void CConstrainPosHprInterval:: 00056 priv_step(double t) { 00057 check_started(get_class_type(), "priv_step"); 00058 _state = S_started; 00059 _curr_t = t; 00060 00061 if(! _target.is_empty()) { 00062 if(_wrt) { 00063 if(! _node.is_same_graph(_target)){ 00064 interval_cat.warning() 00065 << "Unable to copy position and orientation in CConstrainPosHprInterval::priv_step;\n" 00066 << "node (" << _node.get_name() 00067 << ") and target (" << _target.get_name() 00068 << ") are not in the same graph.\n"; 00069 return; 00070 } 00071 _target.set_pos_quat(_node, _posOffset, _quatOffset); 00072 } else { 00073 _target.set_pos_quat(_node.get_pos() + _posOffset, _quatOffset*_node.get_quat()); 00074 } 00075 } 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: CConstrainPosHprInterval::output 00080 // Access: Published, Virtual 00081 // Description: 00082 //////////////////////////////////////////////////////////////////// 00083 void CConstrainPosHprInterval:: 00084 output(ostream &out) const { 00085 out << get_name() << ":"; 00086 out << " dur " << get_duration(); 00087 }