Panda3D

cConstrainHprInterval.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 cConstrainHprInterval.cxx
10 * @author pratt
11 * @date 2008-03-10
12 */
13
14 #include "cConstrainHprInterval.h"
15 #include "config_interval.h"
16 #include "lvecBase3.h"
17
18 TypeHandle CConstrainHprInterval::_type_handle;
19
20 /**
21 * Constructs a constraint interval that will constrain the orientation of one
22 * node to the orientation of another, possibly with an added rotation.
23 *
24 * If wrt is true, the node's orientation 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 orientation will be copied unaltered.
27 */
28 CConstrainHprInterval::
29 CConstrainHprInterval(const std::string &name, double duration,
30 const NodePath &node, const NodePath &target,
31 bool wrt, const LVecBase3 hprOffset) :
32 CConstraintInterval(name, duration),
33 _node(node),
34 _target(target),
35 _wrt(wrt)
36 {
37 _quatOffset.set_hpr(hprOffset);
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 */
45 void CConstrainHprInterval::
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 orientation in CConstrainHprInterval::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_quat(_node, _quatOffset);
62 } else {
63 _target.set_quat(_quatOffset*_node.get_quat());
64 }
65 }
66 }
67
68 /**
69 *
70 */
71 void CConstrainHprInterval::
72 output(std::ostream &out) const {
73 out << get_name() << ":";
74 out << " dur " << get_duration();
75 }
cConstrainHprInterval.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CConstrainHprInterval::priv_step
virtual void priv_step(double t)
Advances the time on the interval.
Definition: cConstrainHprInterval.cxx:46
CConstrainHprInterval::CConstrainHprInterval
CConstrainHprInterval(const std::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...
Definition: cConstrainHprInterval.cxx:29
CConstraintInterval
The base class for a family of intervals that constrain some property to a value over time.
Definition: cConstraintInterval.h:24
CInterval::get_name
get_name
Returns the interval's name.
Definition: cInterval.h:124
CInterval::get_duration
get_duration
Returns the duration of the interval in seconds.
Definition: cInterval.h:127
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
NodePath::set_quat
void set_quat(const LQuaternion &quat)
Sets the rotation component of the transform, leaving translation and scale untouched.
Definition: nodePath.cxx:1118
NodePath::is_same_graph
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
NodePath::is_empty
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:188
NodePath::get_quat
LQuaternion get_quat() const
Retrieves the rotation component of the transform.
Definition: nodePath.cxx:1128
NodePath::get_name
get_name
Returns the name of the referenced node.
Definition: nodePath.h:945
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
config_interval.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lvecBase3.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.