Panda3D

cConstrainTransformInterval.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 cConstrainTransformInterval.cxx
10 * @author pratt
11 * @date 2006-09-29
12 */
13
14 #include "cConstrainTransformInterval.h"
15 #include "transformState.h"
16 #include "config_interval.h"
17
18 TypeHandle CConstrainTransformInterval::_type_handle;
19
20 /**
21 * Constructs a constraint interval that will constrain the transform of one
22 * node to the transform of another. To clarify, the transform of node will
23 * be copied to target.
24 *
25 * If wrt is true, the node's transform will be transformed into the target
26 * node's parent's space before being copied. If wrt is false, the node's
27 * local transform will be copied unaltered.
28 */
29 CConstrainTransformInterval::
30 CConstrainTransformInterval(const std::string &name, double duration,
31 const NodePath &node, const NodePath &target,
32 bool wrt) :
33 CConstraintInterval(name, duration),
34 _node(node),
35 _target(target),
36 _wrt(wrt)
37 {
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 CConstrainTransformInterval::
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 CPT(TransformState) transform;
53 if(_wrt) {
54 if(! _node.is_same_graph(_target)){
55 interval_cat.warning()
56 << "Unable to copy transform in CConstrainTransformInterval::priv_step;\n"
57 << "node (" << _node.get_name()
58 << ") and target (" << _target.get_name()
59 << ") are not in the same graph.\n";
60 return;
61 }
62 transform = _node.get_transform(_target.get_parent());
63 } else {
64 transform = _node.get_transform();
65 }
66
67 _target.set_transform(transform);
68 }
69 }
70
71 /**
72 *
73 */
74 void CConstrainTransformInterval::
75 output(std::ostream &out) const {
76 out << get_name() << ":";
77 out << " dur " << get_duration();
78 }
cConstrainTransformInterval.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CConstrainTransformInterval::CConstrainTransformInterval
CConstrainTransformInterval(const std::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...
Definition: cConstrainTransformInterval.cxx:30
CConstrainTransformInterval::priv_step
virtual void priv_step(double t)
Advances the time on the interval.
Definition: cConstrainTransformInterval.cxx:46
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::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_parent
get_parent
Returns the NodePath to the parent of the referenced node: that is, this NodePath,...
Definition: nodePath.h:242
NodePath::get_transform
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
Definition: nodePath.cxx:791
NodePath::get_name
get_name
Returns the name of the referenced node.
Definition: nodePath.h:945
NodePath::set_transform
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Changes the complete transform object on this node.
Definition: nodePath.I:565
TransformState
Indicates a coordinate-system transform on vertices.
Definition: transformState.h:54
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.
transformState.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.