Panda3D
Loading...
Searching...
No Matches
cConstrainPosHprInterval.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 cConstrainPosHprInterval.cxx
10 * @author pratt
11 * @date 2008-03-10
12 */
13
15#include "config_interval.h"
16#include "lvecBase3.h"
17
18TypeHandle CConstrainPosHprInterval::_type_handle;
19
20/**
21 * Constructs a constraint interval that will constrain the position and
22 * orientation of one node to the position and orientation of another.
23 *
24 * If wrt is true, the node's position and orientation will be transformed
25 * into the target node's parent's space before being copied. If wrt is
26 * false, the target node's local position and orientation will be copied
27 * unaltered.
28 */
30CConstrainPosHprInterval(const std::string &name, double duration,
31 const NodePath &node, const NodePath &target,
32 bool wrt, const LVecBase3 posOffset,
33 const LVecBase3 hprOffset) :
34 CConstraintInterval(name, duration),
35 _node(node),
36 _target(target),
37 _wrt(wrt),
38 _posOffset(posOffset)
39{
40 _quatOffset.set_hpr(hprOffset);
41}
42
43/**
44 * Advances the time on the interval. The time may either increase (the
45 * normal case) or decrease (e.g. if the interval is being played by a
46 * slider).
47 */
49priv_step(double t) {
50 check_started(get_class_type(), "priv_step");
51 _state = S_started;
52 _curr_t = t;
53
54 if(! _target.is_empty()) {
55 if(_wrt) {
56 if(! _node.is_same_graph(_target)){
57 interval_cat.warning()
58 << "Unable to copy position and orientation in CConstrainPosHprInterval::priv_step;\n"
59 << "node (" << _node.get_name()
60 << ") and target (" << _target.get_name()
61 << ") are not in the same graph.\n";
62 return;
63 }
64 _target.set_pos_quat(_node, _posOffset, _quatOffset);
65 } else {
66 _target.set_pos_quat(_node.get_pos() + _posOffset, _quatOffset*_node.get_quat());
67 }
68 }
69}
70
71/**
72 *
73 */
74void CConstrainPosHprInterval::
75output(std::ostream &out) const {
76 out << get_name() << ":";
77 out << " dur " << get_duration();
78}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CConstrainPosHprInterval(const std::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 ...
virtual void priv_step(double t)
Advances the time on the interval.
The base class for a family of intervals that constrain some property to a value over time.
get_name
Returns the interval's name.
Definition cInterval.h:126
get_duration
Returns the duration of the interval in seconds.
Definition cInterval.h:127
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
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
LPoint3 get_pos() const
Retrieves the translation component of the transform.
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition nodePath.I:188
void set_pos_quat(const LVecBase3 &pos, const LQuaternion &quat)
Sets the translation and rotation component of the transform, leaving scale untouched.
LQuaternion get_quat() const
Retrieves the rotation component of the transform.
get_name
Returns the name of the referenced node.
Definition nodePath.h:951
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.