Panda3D
 All Classes Functions Variables Enumerations
cConstrainHprInterval.cxx
1 // Filename: cConstrainHprInterval.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 "cConstrainHprInterval.h"
16 #include "config_interval.h"
17 #include "lvecBase3.h"
18 
19 TypeHandle CConstrainHprInterval::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: CConstrainHprInterval::Constructor
23 // Access: Published
24 // Description: Constructs a constraint interval that will constrain
25 // the orientation of one node to the orientation of
26 // another, possibly with an added rotation.
27 //
28 // If wrt is true, the node's orientation will be
29 // transformed into the target node's parent's space
30 // before being copied. If wrt is false, the target
31 // node's local orientation will be copied unaltered.
32 ////////////////////////////////////////////////////////////////////
34 CConstrainHprInterval(const string &name, double duration,
35  const NodePath &node, const NodePath &target,
36  bool wrt, const LVecBase3 hprOffset) :
37  CConstraintInterval(name, duration),
38  _node(node),
39  _target(target),
40  _wrt(wrt)
41 {
42  _quatOffset.set_hpr(hprOffset);
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: CConstrainHprInterval::step
47 // Access: Published, Virtual
48 // Description: Advances the time on the interval. The time may
49 // either increase (the normal case) or decrease
50 // (e.g. if the interval is being played by a slider).
51 ////////////////////////////////////////////////////////////////////
53 priv_step(double t) {
54  check_started(get_class_type(), "priv_step");
55  _state = S_started;
56  _curr_t = t;
57 
58  if(! _target.is_empty()) {
59  if(_wrt) {
60  if(! _node.is_same_graph(_target)){
61  interval_cat.warning()
62  << "Unable to copy orientation in CConstrainHprInterval::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  _target.set_quat(_node, _quatOffset);
69  } else {
70  _target.set_quat(_quatOffset*_node.get_quat());
71  }
72  }
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: CConstrainHprInterval::output
77 // Access: Published, Virtual
78 // Description:
79 ////////////////////////////////////////////////////////////////////
80 void CConstrainHprInterval::
81 output(ostream &out) const {
82  out << get_name() << ":";
83  out << " dur " << get_duration();
84 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
const string & get_name() const
Returns the interval&#39;s name.
Definition: cInterval.I:22
LQuaternion get_quat() const
Retrieves the rotation component of the transform.
Definition: nodePath.cxx:1279
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
void set_quat(const LQuaternion &quat)
Sets the rotation component of the transform, leaving translation and scale untouched.
Definition: nodePath.cxx:1267
CConstrainHprInterval(const string &name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 hprOffset=LVector3::zero())
Constructs a constraint interval that will constrain the orientation of one node to the orientation o...
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.
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.
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