Panda3D
uvScrollNode.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 uvScrollNode.cxx
10  * @author drose
11  * @date 2002-03-16
12  */
13 
14 #include "uvScrollNode.h"
15 
16 #include "bamReader.h"
17 #include "cullTraverserData.h"
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 #include "luse.h"
21 #include "renderState.h"
22 #include "texMatrixAttrib.h"
23 #include "textureStage.h"
24 #include "transformState.h"
25 
26 TypeHandle UvScrollNode::_type_handle;
27 
28 
29 /**
30  * Returns a newly-allocated Node that is a shallow copy of this one. It will
31  * be a different Node pointer, but its internal data may or may not be shared
32  * with that of the original Node.
33  */
35 make_copy() const {
36  return new UvScrollNode(*this);
37 }
38 
39 /**
40  * Tells the BamReader how to create objects of type UvScrollNode.
41  */
44  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
45 }
46 
47 /**
48  * Writes the contents of this object to the datagram for shipping out to a
49  * Bam file.
50  */
52 write_datagram(BamWriter *manager, Datagram &dg) {
53  PandaNode::write_datagram(manager, dg);
54  dg.add_stdfloat(_u_speed);
55  dg.add_stdfloat(_v_speed);
56  if (manager->get_file_minor_ver() >= 33) {
57  dg.add_stdfloat(_w_speed);
58  }
59  if (manager->get_file_minor_ver() >= 22) {
60  dg.add_stdfloat(_r_speed);
61  }
62 }
63 
64 /**
65  * This function is called by the BamReader's factory when a new object of
66  * type ModelNode is encountered in the Bam file. It should create the
67  * ModelNode and extract its information from the file.
68  */
69 TypedWritable *UvScrollNode::
70 make_from_bam(const FactoryParams &params) {
71  UvScrollNode *node = new UvScrollNode("");
72  DatagramIterator scan;
73  BamReader *manager;
74 
75  parse_params(params, scan, manager);
76  node->fillin(scan, manager);
77 
78  return node;
79 }
80 
81 /**
82  * This internal function is called by make_from_bam to read in all of the
83  * relevant data from the BamFile for the new ModelNode.
84  */
85 void UvScrollNode::
86 fillin(DatagramIterator &scan, BamReader *manager) {
87  PandaNode::fillin(scan, manager);
88 
89  _u_speed = scan.get_stdfloat();
90  _v_speed = scan.get_stdfloat();
91  if (manager->get_file_minor_ver() >= 33) {
92  _w_speed = scan.get_stdfloat();
93  }
94  if (manager->get_file_minor_ver() >= 22) {
95  _r_speed = scan.get_stdfloat();
96  }
97 
98 }
99 
100 /**
101  * This function will be called during the cull traversal to perform any
102  * additional operations that should be performed at cull time. This may
103  * include additional manipulation of render state or additional
104  * visible/invisible decisions, or any other arbitrary operation.
105  *
106  * Note that this function will *not* be called unless set_cull_callback() is
107  * called in the constructor of the derived class. It is necessary to call
108  * set_cull_callback() to indicated that we require cull_callback() to be
109  * called.
110  *
111  * By the time this function is called, the node has already passed the
112  * bounding-volume test for the viewing frustum, and the node's transform and
113  * state have already been applied to the indicated CullTraverserData object.
114  *
115  * The return value is \true if this node should be visible, or false if it
116  * should be culled.
117  */
120  double elapsed = ClockObject::get_global_clock()->get_frame_time() - _start_time;
121  CPT(TransformState) ts = TransformState::make_pos_hpr(
122  LVecBase3(cmod(elapsed * _u_speed, 1.0) / 1.0,
123  cmod(elapsed * _v_speed, 1.0) / 1.0,
124  cmod(elapsed * _w_speed, 1.0) / 1.0),
125  LVecBase3((cmod(elapsed * _r_speed, 1.0) / 1.0) * 360, 0, 0));
126 
127  CPT(RenderAttrib) tm = TexMatrixAttrib::make(TextureStage::get_default(), ts);
128  CPT(RenderState) rs = RenderState::make_empty()->set_attrib(tm);
129  data._state = data._state->compose(rs);
130 
131  return true;
132 }
133 
134 /**
135  * Returns true if it is generally safe to flatten out this particular kind of
136  * PandaNode by duplicating instances (by calling dupe_for_flatten()), false
137  * otherwise (for instance, a Camera cannot be safely flattened, because the
138  * Camera pointer itself is meaningful).
139  */
141 safe_to_flatten() const {
142  return false;
143 }
144 
145 /**
146  * Returns true if it is generally safe to combine this with other nodes,
147  * which it isn't, so don't. Ever.
148  */
150 safe_to_combine() const {
151  return false;
152 }
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
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
Definition: bamReader.I:83
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
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
Definition: bamWriter.I:59
get_frame_time
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
Definition: clockObject.h:91
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
Definition: clockObject.I:215
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
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...
Definition: factoryParams.h:36
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
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:3583
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
get_default
Returns the default TextureStage that will be used for all texturing that does not name a particular ...
Definition: textureStage.h:207
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.
Definition: typedWritable.h:35
This node is placed at key points within the scene graph to animate uvs.
Definition: uvScrollNode.h:26
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this with other nodes, which it isn't,...
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating ...
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
static void register_with_read_factory()
Tells the BamReader how to create objects of type UvScrollNode.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
float cmod(float x, float y)
This is similar to fmod(), but it behaves properly when x is negative: that is, it always returns a v...
Definition: cmath.I:130
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.