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