Panda3D
 All Classes Functions Variables Enumerations
cConstrainPosInterval.cxx
00001 // Filename: cConstrainPosInterval.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 "cConstrainPosInterval.h"
00016 #include "config_interval.h"
00017 #include "lvecBase3.h"
00018 
00019 TypeHandle CConstrainPosInterval::_type_handle;
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: CConstrainPosInterval::Constructor
00023 //       Access: Published
00024 //  Description: Constructs a constraint interval that will constrain
00025 //               the position of one node to the position of another.
00026 //
00027 //               If wrt is true, the node's position will be
00028 //               transformed into the target node's parent's  space
00029 //               before being copied.  If wrt is false, the target
00030 //               node's local position will be copied unaltered.
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 //     Function: CConstrainPosInterval::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 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 //     Function: CConstrainPosInterval::output
00080 //       Access: Published, Virtual
00081 //  Description: 
00082 ////////////////////////////////////////////////////////////////////
00083 void CConstrainPosInterval::
00084 output(ostream &out) const {
00085   out << get_name() << ":";
00086   out << " dur " << get_duration();
00087 }
 All Classes Functions Variables Enumerations