Panda3D
cConstrainPosInterval.cxx
1 // Filename: cConstrainPosInterval.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 "cConstrainPosInterval.h"
16 #include "config_interval.h"
17 #include "lvecBase3.h"
18 
19 TypeHandle CConstrainPosInterval::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: CConstrainPosInterval::Constructor
23 // Access: Published
24 // Description: Constructs a constraint interval that will constrain
25 // the position of one node to the position of another.
26 //
27 // If wrt is true, the node's position will be
28 // transformed into the target node's parent's space
29 // before being copied. If wrt is false, the target
30 // node's local position will be copied unaltered.
31 ////////////////////////////////////////////////////////////////////
33 CConstrainPosInterval(const string &name, double duration,
34  const NodePath &node, const NodePath &target,
35  bool wrt, const LVecBase3 posOffset) :
36  CConstraintInterval(name, duration),
37  _node(node),
38  _target(target),
39  _wrt(wrt),
40  _posOffset(posOffset)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: CConstrainPosInterval::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  if(_wrt) {
59  if(! _node.is_same_graph(_target)){
60  interval_cat.warning()
61  << "Unable to copy position in CConstrainPosInterval::priv_step;\n"
62  << "node (" << _node.get_name()
63  << ") and target (" << _target.get_name()
64  << ") are not in the same graph.\n";
65  return;
66  }
67  _target.set_pos(_node, _posOffset);
68  } else {
69  if(_posOffset == LVector3::zero()) {
70  _target.set_pos(_node.get_pos());
71  } else {
72  _target.set_pos(_node.get_pos() + _posOffset);
73  }
74  }
75  }
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: CConstrainPosInterval::output
80 // Access: Published, Virtual
81 // Description:
82 ////////////////////////////////////////////////////////////////////
83 void CConstrainPosInterval::
84 output(ostream &out) const {
85  out << get_name() << ":";
86  out << " dur " << get_duration();
87 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
CConstrainPosInterval(const 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...
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:236
static const LVector3f & zero()
Returns a zero-length vector.
Definition: lvector3.h:270
const string & get_name() const
Returns the interval&#39;s name.
Definition: cInterval.I:22
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...
double get_duration() const
Returns the duration of the interval in seconds.
Definition: cInterval.I:32
LPoint3 get_pos() const
Retrieves the translation component of the transform.
Definition: nodePath.cxx:1178
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
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
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:165