Panda3D

Loading...
Searching...
No Matches
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::
75output(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
CInterval::get_name
get_name
Returns the interval's name.
Definition cInterval.h:126
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
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.