Panda3D
 All Classes Functions Variables Enumerations
animChannelScalarDynamic.cxx
1 // Filename: animChannelScalarDynamic.cxx
2 // Created by: drose (20Oct03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "animChannelScalarDynamic.h"
16 #include "animBundle.h"
17 #include "config_chan.h"
18 #include "transformState.h"
19 #include "pandaNode.h"
20 #include "indent.h"
21 #include "datagram.h"
22 #include "datagramIterator.h"
23 #include "bamReader.h"
24 #include "bamWriter.h"
25 
26 TypeHandle AnimChannelScalarDynamic::_type_handle;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: AnimChannelScalarDynamic::Constructor
30 // Access: Protected
31 // Description: For use only with the bam reader.
32 ////////////////////////////////////////////////////////////////////
33 AnimChannelScalarDynamic::
34 AnimChannelScalarDynamic() {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: AnimChannelScalarDynamic::Copy Constructor
39 // Access: Protected
40 // Description: Creates a new AnimChannelScalarDynamic, just like
41 // this one, without copying any children. The new copy
42 // is added to the indicated parent. Intended to be
43 // called by make_copy() only.
44 ////////////////////////////////////////////////////////////////////
45 AnimChannelScalarDynamic::
46 AnimChannelScalarDynamic(AnimGroup *parent, const AnimChannelScalarDynamic &copy) :
47  AnimChannelScalar(parent, copy),
48  _value_node(copy._value_node),
49  _value(copy._value),
50  _last_value(NULL),
51  _value_changed(true),
52  _float_value(copy._float_value)
53 {
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: AnimChannelScalarDynamic::Constructor
58 // Access: Public
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 AnimChannelScalarDynamic::
62 AnimChannelScalarDynamic(const string &name)
63  : AnimChannelScalar(name)
64 {
65  _last_value = _value = TransformState::make_identity();
66  _value_changed = true;
67  _float_value = 0.0;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: AnimChannelScalarDynamic::has_changed
72 // Access: Public, Virtual
73 // Description: Returns true if the value has changed since the last
74 // call to has_changed(). last_frame is the frame
75 // number of the last call; this_frame is the current
76 // frame number.
77 ////////////////////////////////////////////////////////////////////
79 has_changed(int, double, int, double) {
80  if (_value_node != (PandaNode *)NULL) {
81  _value = _value_node->get_transform();
82  bool has_changed = (_value != _last_value);
83  _last_value = _value;
84  return has_changed;
85 
86  } else {
87  bool has_changed = _value_changed;
88  _value_changed = false;
89  return has_changed;
90  }
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: AnimChannelScalarDynamic::get_value
95 // Access: Public, Virtual
96 // Description: Gets the value of the channel at the indicated frame.
97 ////////////////////////////////////////////////////////////////////
99 get_value(int, PN_stdfloat &value) {
100  if (_value_node != (PandaNode *)NULL) {
101  value = _value->get_pos()[0];
102 
103  } else {
104  value = _float_value;
105  }
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: AnimChannelScalarDynamic::set_value
110 // Access: Published
111 // Description: Explicitly sets the value.
112 ////////////////////////////////////////////////////////////////////
114 set_value(PN_stdfloat value) {
115  _float_value = value;
116  _value_node.clear();
117  _value_changed = true;
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: AnimChannelScalarDynamic::set_value_node
122 // Access: Published
123 // Description: Specifies a node whose transform will be queried each
124 // frame to implicitly specify the transform of this
125 // joint.
126 ////////////////////////////////////////////////////////////////////
128 set_value_node(PandaNode *value_node) {
129  if (_value_node == (PandaNode *)NULL) {
130  _last_value = TransformState::make_pos(LVecBase3(_float_value, 0.0f, 0.0f));
131  }
132 
133  _value_node = value_node;
134 
135  if (_value_node != (PandaNode *)NULL) {
136  _value = _value_node->get_transform();
137  }
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: AnimChannelScalarDynamic::make_copy
142 // Access: Protected, Virtual
143 // Description: Returns a copy of this object, and attaches it to the
144 // indicated parent (which may be NULL only if this is
145 // an AnimBundle). Intended to be called by
146 // copy_subtree() only.
147 ////////////////////////////////////////////////////////////////////
148 AnimGroup *AnimChannelScalarDynamic::
149 make_copy(AnimGroup *parent) const {
150  return new AnimChannelScalarDynamic(parent, *this);
151 }
152 
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: AnimChannelScalarDynamic::write_datagram
156 // Access: Public
157 // Description: Function to write the important information in
158 // the particular object to a Datagram
159 ////////////////////////////////////////////////////////////////////
163  manager->write_pointer(dg, _value_node);
164  manager->write_pointer(dg, _value);
165  dg.add_stdfloat(_float_value);
166 }
167 
168 ////////////////////////////////////////////////////////////////////
169 // Function: AnimChannelScalarDynamic::complete_pointers
170 // Access: Public, Virtual
171 // Description: Receives an array of pointers, one for each time
172 // manager->read_pointer() was called in fillin().
173 // Returns the number of pointers processed.
174 ////////////////////////////////////////////////////////////////////
177  int pi = AnimChannelScalar::complete_pointers(p_list, manager);
178 
179  // Get the _value_node and _value pointers.
180  _value_node = DCAST(PandaNode, p_list[pi++]);
181  _value = DCAST(TransformState, p_list[pi++]);
182 
183  return pi;
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: AnimChannelScalarDynamic::fillin
188 // Access: Public
189 // Description: Function that reads out of the datagram (or asks
190 // manager to read) all of the data that is needed to
191 // re-create this object and stores it in the appropiate
192 // place
193 ////////////////////////////////////////////////////////////////////
196  AnimChannelScalar::fillin(scan, manager);
197 
198  // Read the _value_node and _value pointers.
199  manager->read_pointer(scan);
200  manager->read_pointer(scan);
201 
202  _float_value = scan.get_stdfloat();
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: AnimChannelScalarDynamic::make_AnimChannelScalarDynamic
207 // Access: Public
208 // Description: Factory method to generate a AnimChannelScalarDynamic object
209 ////////////////////////////////////////////////////////////////////
213  DatagramIterator scan;
214  BamReader *manager;
215 
216  parse_params(params, scan, manager);
217  me->fillin(scan, manager);
218  return me;
219 }
220 
221 ////////////////////////////////////////////////////////////////////
222 // Function: AnimChannelScalarDynamic::register_with_factory
223 // Access: Public, Static
224 // Description: Factory method to generate a AnimChannelScalarDynamic object
225 ////////////////////////////////////////////////////////////////////
229 }
230 
231 
232 
233 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
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:327
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
void set_value(PN_stdfloat 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:37
void set_value_node(PandaNode *node)
Specifies a node whose transform will be queried each frame to implicitly specify the transform of th...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This template class is the parent class for all kinds of AnimChannels that return different values...
Definition: animChannel.h:30
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:240
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:36
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
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:213
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:85
virtual void get_value(int frame, PN_stdfloat &value)
Gets the value of the channel at the indicated frame.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
static TypedWritable * make_AnimChannelScalarDynamic(const FactoryParams &params)
Factory method to generate a AnimChannelScalarDynamic object.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:279
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:652