Panda3D
animChannelScalarDynamic.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 animChannelScalarDynamic.cxx
10  * @author drose
11  * @date 2003-10-20
12  */
13 
15 #include "animBundle.h"
16 #include "config_chan.h"
17 #include "transformState.h"
18 #include "pandaNode.h"
19 #include "indent.h"
20 #include "datagram.h"
21 #include "datagramIterator.h"
22 #include "bamReader.h"
23 #include "bamWriter.h"
24 
25 TypeHandle AnimChannelScalarDynamic::_type_handle;
26 
27 /**
28  * For use only with the bam reader.
29  */
30 AnimChannelScalarDynamic::
31 AnimChannelScalarDynamic() {
32 }
33 
34 /**
35  * Creates a new AnimChannelScalarDynamic, just like this one, without copying
36  * any children. The new copy is added to the indicated parent. Intended to
37  * be called by make_copy() only.
38  */
39 AnimChannelScalarDynamic::
40 AnimChannelScalarDynamic(AnimGroup *parent, const AnimChannelScalarDynamic &copy) :
41  AnimChannelScalar(parent, copy),
42  _value_node(copy._value_node),
43  _value(copy._value),
44  _last_value(nullptr),
45  _value_changed(true),
46  _float_value(copy._float_value)
47 {
48 }
49 
50 /**
51  *
52  */
53 AnimChannelScalarDynamic::
54 AnimChannelScalarDynamic(const std::string &name)
55  : AnimChannelScalar(name)
56 {
57  _last_value = _value = TransformState::make_identity();
58  _value_changed = true;
59  _float_value = 0.0;
60 }
61 
62 /**
63  * Returns true if the value has changed since the last call to has_changed().
64  * last_frame is the frame number of the last call; this_frame is the current
65  * frame number.
66  */
68 has_changed(int, double, int, double) {
69  if (_value_node != nullptr) {
70  _value = _value_node->get_transform();
71  bool has_changed = (_value != _last_value);
72  _last_value = _value;
73  return has_changed;
74 
75  } else {
76  bool has_changed = _value_changed;
77  _value_changed = false;
78  return has_changed;
79  }
80 }
81 
82 /**
83  * Gets the value of the channel at the indicated frame.
84  */
85 void AnimChannelScalarDynamic::
86 get_value(int, PN_stdfloat &value) {
87  value = get_value();
88 }
89 
90 /**
91  * Explicitly sets the value. This will remove any node assigned via
92  * set_value_node().
93  */
95 set_value(PN_stdfloat value) {
96  _float_value = value;
97  _value_node.clear();
98  _value_changed = true;
99 }
100 
101 /**
102  * Specifies a node whose transform will be queried each frame to implicitly
103  * specify the transform of this joint. This will override the values set by
104  * set_value().
105  */
107 set_value_node(PandaNode *value_node) {
108  if (_value_node == nullptr) {
109  _last_value = TransformState::make_pos(LVecBase3(_float_value, 0.0f, 0.0f));
110  }
111 
112  _value_node = value_node;
113 
114  if (_value_node != nullptr) {
115  _value = _value_node->get_transform();
116  }
117 }
118 
119 /**
120  * Returns a copy of this object, and attaches it to the indicated parent
121  * (which may be NULL only if this is an AnimBundle). Intended to be called
122  * by copy_subtree() only.
123  */
124 AnimGroup *AnimChannelScalarDynamic::
125 make_copy(AnimGroup *parent) const {
126  return new AnimChannelScalarDynamic(parent, *this);
127 }
128 
129 
130 /**
131  * Function to write the important information in the particular object to a
132  * Datagram
133  */
137  manager->write_pointer(dg, _value_node);
138  manager->write_pointer(dg, _value);
139  dg.add_stdfloat(_float_value);
140 }
141 
142 /**
143  * Receives an array of pointers, one for each time manager->read_pointer()
144  * was called in fillin(). Returns the number of pointers processed.
145  */
148  int pi = AnimChannelScalar::complete_pointers(p_list, manager);
149 
150  // Get the _value_node and _value pointers.
151  _value_node = DCAST(PandaNode, p_list[pi++]);
152  _value = DCAST(TransformState, p_list[pi++]);
153 
154  return pi;
155 }
156 
157 /**
158  * Function that reads out of the datagram (or asks manager to read) all of
159  * the data that is needed to re-create this object and stores it in the
160  * appropiate place
161  */
164  AnimChannelScalar::fillin(scan, manager);
165 
166  // Read the _value_node and _value pointers.
167  manager->read_pointer(scan);
168  manager->read_pointer(scan);
169 
170  _float_value = scan.get_stdfloat();
171 }
172 
173 /**
174  * Factory method to generate a AnimChannelScalarDynamic object
175  */
179  DatagramIterator scan;
180  BamReader *manager;
181 
182  parse_params(params, scan, manager);
183  me->fillin(scan, manager);
184  return me;
185 }
186 
187 /**
188  * Factory method to generate a AnimChannelScalarDynamic object
189  */
193 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Indicates a coordinate-system transform on vertices.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Takes in a vector of pointes to TypedWritable objects that correspond to all the requests for pointer...
Definition: animGroup.cxx:277
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
set_value
Explicitly sets the value.
virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac)
Returns true if the value has changed since the last call to has_changed().
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This template class is the parent class for all kinds of AnimChannels that return different values.
Definition: animChannel.h:28
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Function to write the important information in the particular object to a Datagram.
static void register_with_read_factory()
Factory method to generate a AnimChannelScalarDynamic object.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
Definition: datagram.I:133
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
void fillin(DatagramIterator &scan, BamReader *manager)
Function that reads out of the datagram (or asks manager to read) all of the data that is needed to r...
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:33
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
set_value_node
Specifies a node whose transform will be queried each frame to implicitly specify the transform of th...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
An animation channel that accepts a scalar each frame from some dynamic input provided by code.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
static TypedWritable * make_AnimChannelScalarDynamic(const FactoryParams &params)
Factory method to generate a AnimChannelScalarDynamic object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:317
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.