Panda3D
 All Classes Functions Variables Enumerations
cConstrainTransformInterval.cxx
1 // Filename: cConstrainTransformInterval.cxx
2 // Created by: pratt (29Sep06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "cConstrainTransformInterval.h"
16 #include "transformState.h"
17 #include "config_interval.h"
18 
19 TypeHandle CConstrainTransformInterval::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: CConstrainTransformInterval::Constructor
23 // Access: Published
24 // Description: Constructs a constraint interval that will constrain
25 // the transform of one node to the transform of another.
26 // To clarify, the transform of node will be copied to target.
27 //
28 // If wrt is true, the node's transform will be
29 // transformed into the target node's parent's space
30 // before being copied. If wrt is false, the node's
31 // local transform will be copied unaltered.
32 ////////////////////////////////////////////////////////////////////
34 CConstrainTransformInterval(const string &name, double duration,
35  const NodePath &node, const NodePath &target,
36  bool wrt) :
37  CConstraintInterval(name, duration),
38  _node(node),
39  _target(target),
40  _wrt(wrt)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: CConstrainTransformInterval::step
46 // Access: Published, Virtual
47 // Description: Advances the time on the interval. The time may
48 // either increase (the normal case) or decrease
49 // (e.g. if the interval is being played by a slider).
50 ////////////////////////////////////////////////////////////////////
52 priv_step(double t) {
53  check_started(get_class_type(), "priv_step");
54  _state = S_started;
55  _curr_t = t;
56 
57  if(! _target.is_empty()) {
58  CPT(TransformState) transform;
59  if(_wrt) {
60  if(! _node.is_same_graph(_target)){
61  interval_cat.warning()
62  << "Unable to copy transform in CConstrainTransformInterval::priv_step;\n"
63  << "node (" << _node.get_name()
64  << ") and target (" << _target.get_name()
65  << ") are not in the same graph.\n";
66  return;
67  }
68  transform = _node.get_transform(_target.get_parent());
69  } else {
70  transform = _node.get_transform();
71  }
72 
73  _target.set_transform(transform);
74  }
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: CConstrainTransformInterval::output
79 // Access: Published, Virtual
80 // Description:
81 ////////////////////////////////////////////////////////////////////
82 void CConstrainTransformInterval::
83 output(ostream &out) const {
84  out << get_name() << ":";
85  out << " dur " << get_duration();
86 }
NodePath get_parent(Thread *current_thread=Thread::get_current_thread()) const
Returns the NodePath to the parent of the referenced node: that is, this NodePath, shortened by one node.
Definition: nodePath.I:460
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
Definition: nodePath.cxx:925
const string & get_name() const
Returns the interval&#39;s name.
Definition: cInterval.I:22
CConstrainTransformInterval(const string &name, double duration, const NodePath &node, const NodePath &target, bool wrt)
Constructs a constraint interval that will constrain the transform of one node to the transform of an...
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Changes the complete transform object on this node.
Definition: nodePath.I:718
double get_duration() const
Returns the duration of the interval in seconds.
Definition: cInterval.I:32
string get_name() const
Returns the name of the referenced node.
Definition: nodePath.I:2580
The base class for a family of intervals that constrain some property to a value over time...
virtual void priv_step(double t)
Advances the time on the interval.
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:236
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
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:344
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165