Panda3D
cConstrainPosInterval.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file cConstrainPosInterval.cxx
10  * @author pratt
11  * @date 2006-09-29
12  */
13 
14 #include "cConstrainPosInterval.h"
15 #include "config_interval.h"
16 #include "lvecBase3.h"
17 
18 TypeHandle CConstrainPosInterval::_type_handle;
19 
20 /**
21  * Constructs a constraint interval that will constrain the position of one
22  * node to the position of another.
23  *
24  * If wrt is true, the node's position will be transformed into the target
25  * node's parent's space before being copied. If wrt is false, the target
26  * node's local position will be copied unaltered.
27  */
29 CConstrainPosInterval(const std::string &name, double duration,
30  const NodePath &node, const NodePath &target,
31  bool wrt, const LVecBase3 posOffset) :
32  CConstraintInterval(name, duration),
33  _node(node),
34  _target(target),
35  _wrt(wrt),
36  _posOffset(posOffset)
37 {
38 }
39 
40 /**
41  * Advances the time on the interval. The time may either increase (the
42  * normal case) or decrease (e.g. if the interval is being played by a
43  * slider).
44  */
46 priv_step(double t) {
47  check_started(get_class_type(), "priv_step");
48  _state = S_started;
49  _curr_t = t;
50 
51  if(! _target.is_empty()) {
52  if(_wrt) {
53  if(! _node.is_same_graph(_target)){
54  interval_cat.warning()
55  << "Unable to copy position in CConstrainPosInterval::priv_step;\n"
56  << "node (" << _node.get_name()
57  << ") and target (" << _target.get_name()
58  << ") are not in the same graph.\n";
59  return;
60  }
61  _target.set_pos(_node, _posOffset);
62  } else {
63  if(_posOffset == LVector3::zero()) {
64  _target.set_pos(_node.get_pos());
65  } else {
66  _target.set_pos(_node.get_pos() + _posOffset);
67  }
68  }
69  }
70 }
71 
72 /**
73  *
74  */
75 void CConstrainPosInterval::
76 output(std::ostream &out) const {
77  out << get_name() << ":";
78  out << " dur " << get_duration();
79 }
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:188
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CConstrainPosInterval(const std::string &name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 posOffset=LVector3::zero())
Constructs a constraint interval that will constrain the position of one node to the position of anot...
get_name
Returns the name of the referenced node.
Definition: nodePath.h:946
The base class for a family of intervals that constrain some property to a value over time.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
Definition: nodePath.cxx:992
bool is_same_graph(const NodePath &other, Thread *current_thread=Thread::get_current_thread()) const
Returns true if the node represented by this NodePath is parented within the same graph as that of th...
Definition: nodePath.I:275
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
virtual void priv_step(double t)
Advances the time on the interval.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161