Panda3D
Loading...
Searching...
No Matches
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
25TypeHandle AnimChannelScalarDynamic::_type_handle;
26
27/**
28 * For use only with the bam reader.
29 */
30AnimChannelScalarDynamic::
31AnimChannelScalarDynamic() {
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 */
39AnimChannelScalarDynamic::
40AnimChannelScalarDynamic(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 */
53AnimChannelScalarDynamic::
54AnimChannelScalarDynamic(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 */
68has_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 */
86get_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 */
95set_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 */
107set_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 */
124AnimGroup *AnimChannelScalarDynamic::
125make_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 */
135write_datagram(BamWriter *manager, Datagram &dg) {
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 */
147complete_pointers(TypedWritable **p_list, BamReader *manager) {
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 */
163fillin(DatagramIterator &scan, BamReader *manager) {
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 */
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
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.
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...
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
static void register_with_read_factory()
Factory method to generate a AnimChannelScalarDynamic object.
static TypedWritable * make_AnimChannelScalarDynamic(const FactoryParams &params)
Factory method to generate a AnimChannelScalarDynamic object.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Function to write the important information in the particular object to a Datagram.
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().
get_value
Gets the value of the channel at the indicated frame.
set_value_node
Specifies a node whose transform will be queried each frame to implicitly specify the transform of th...
This template class is the parent class for all kinds of AnimChannels that return different values.
Definition animChannel.h:28
This is the base class for AnimChannel and AnimBundle.
Definition animGroup.h:33
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...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
A class to retrieve the individual data elements previously stored in a Datagram.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
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
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.