Panda3D
cConstrainPosHprInterval.cxx
1 // Filename: cConstrainPosHprInterval.cxx
2 // Created by: pratt (10Mar08)
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 "cConstrainPosHprInterval.h"
16 #include "config_interval.h"
17 #include "lvecBase3.h"
18 
19 TypeHandle CConstrainPosHprInterval::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: CConstrainPosHprInterval::Constructor
23 // Access: Published
24 // Description: Constructs a constraint interval that will constrain
25 // the position and orientation of one node to the
26 // position and orientation of another.
27 //
28 // If wrt is true, the node's position and orientation
29 // will be transformed into the target node's parent's
30 // space before being copied. If wrt is false, the
31 // target node's local position and orientation will be
32 // copied unaltered.
33 ////////////////////////////////////////////////////////////////////
35 CConstrainPosHprInterval(const string &name, double duration,
36  const NodePath &node, const NodePath &target,
37  bool wrt, const LVecBase3 posOffset,
38  const LVecBase3 hprOffset) :
39  CConstraintInterval(name, duration),
40  _node(node),
41  _target(target),
42  _wrt(wrt),
43  _posOffset(posOffset)
44 {
45  _quatOffset.set_hpr(hprOffset);
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: CConstrainPosHprInterval::step
50 // Access: Published, Virtual
51 // Description: Advances the time on the interval. The time may
52 // either increase (the normal case) or decrease
53 // (e.g. if the interval is being played by a slider).
54 ////////////////////////////////////////////////////////////////////
56 priv_step(double t) {
57  check_started(get_class_type(), "priv_step");
58  _state = S_started;
59  _curr_t = t;
60 
61  if(! _target.is_empty()) {
62  if(_wrt) {
63  if(! _node.is_same_graph(_target)){
64  interval_cat.warning()
65  << "Unable to copy position and orientation in CConstrainPosHprInterval::priv_step;\n"
66  << "node (" << _node.get_name()
67  << ") and target (" << _target.get_name()
68  << ") are not in the same graph.\n";
69  return;
70  }
71  _target.set_pos_quat(_node, _posOffset, _quatOffset);
72  } else {
73  _target.set_pos_quat(_node.get_pos() + _posOffset, _quatOffset*_node.get_quat());
74  }
75  }
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: CConstrainPosHprInterval::output
80 // Access: Published, Virtual
81 // Description:
82 ////////////////////////////////////////////////////////////////////
83 void CConstrainPosHprInterval::
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
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:236
virtual void priv_step(double t)
Advances the time on the interval.
void set_pos_quat(const LVecBase3 &pos, const LQuaternion &quat)
Sets the translation and rotation component of the transform, leaving scale untouched.
Definition: nodePath.cxx:1412
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...
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
double get_duration() const
Returns the duration of the interval in seconds.
Definition: cInterval.I:32
LQuaternion get_quat() const
Retrieves the rotation component of the transform.
Definition: nodePath.cxx:1279
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
CConstrainPosHprInterval(const string &name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 posOffset=LVector3::zero(), const LVecBase3 hprOffset=LVector3::zero())
Constructs a constraint interval that will constrain the position and orientation of one node to the ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165