Panda3D
uvScrollNode.cxx
1 // Filename: modelNode.cxx
2 // Created by: drose (16Mar02)
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 "uvScrollNode.h"
16 
17 #include "bamReader.h"
18 #include "cullTraverserData.h"
19 #include "datagram.h"
20 #include "datagramIterator.h"
21 #include "luse.h"
22 #include "renderState.h"
23 #include "texMatrixAttrib.h"
24 #include "textureStage.h"
25 #include "transformState.h"
26 
27 TypeHandle UvScrollNode::_type_handle;
28 
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: UvScrollNode::make_copy
32 // Access: Public, Virtual
33 // Description: Returns a newly-allocated Node that is a shallow copy
34 // of this one. It will be a different Node pointer,
35 // but its internal data may or may not be shared with
36 // that of the original Node.
37 ////////////////////////////////////////////////////////////////////
39 make_copy() const {
40  return new UvScrollNode(*this);
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: UvSctrollNode::register_with_read_factory
45 // Access: Public, Static
46 // Description: Tells the BamReader how to create objects of type
47 // UvScrollNode.
48 ////////////////////////////////////////////////////////////////////
49 void UvScrollNode::
51  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: UvSctrollNode::write_datagram
56 // Access: Public, Virtual
57 // Description: Writes the contents of this object to the datagram
58 // for shipping out to a Bam file.
59 ////////////////////////////////////////////////////////////////////
60 void UvScrollNode::
62  PandaNode::write_datagram(manager, dg);
63  dg.add_stdfloat(_u_speed);
64  dg.add_stdfloat(_v_speed);
65  dg.add_stdfloat(_w_speed);
66  dg.add_stdfloat(_r_speed);
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: ModelNode::make_from_bam
71 // Access: Protected, Static
72 // Description: This function is called by the BamReader's factory
73 // when a new object of type ModelNode is encountered
74 // in the Bam file. It should create the ModelNode
75 // and extract its information from the file.
76 ////////////////////////////////////////////////////////////////////
77 TypedWritable *UvScrollNode::
78 make_from_bam(const FactoryParams &params) {
79  UvScrollNode *node = new UvScrollNode("");
80  DatagramIterator scan;
81  BamReader *manager;
82 
83  parse_params(params, scan, manager);
84  node->fillin(scan, manager);
85 
86  return node;
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: ModelNode::fillin
91 // Access: Protected
92 // Description: This internal function is called by make_from_bam to
93 // read in all of the relevant data from the BamFile for
94 // the new ModelNode.
95 ////////////////////////////////////////////////////////////////////
96 void UvScrollNode::
97 fillin(DatagramIterator &scan, BamReader *manager) {
98  PandaNode::fillin(scan, manager);
99 
100  _u_speed = scan.get_stdfloat();
101  _v_speed = scan.get_stdfloat();
102  if (manager->get_file_minor_ver() >= 33) {
103  _w_speed = scan.get_stdfloat();
104  }
105  if (manager->get_file_minor_ver() >= 22) {
106  _r_speed = scan.get_stdfloat();
107  }
108 
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: SequenceNode::cull_callback
113 // Access: Public, Virtual
114 // Description: This function will be called during the cull
115 // traversal to perform any additional operations that
116 // should be performed at cull time. This may include
117 // additional manipulation of render state or additional
118 // visible/invisible decisions, or any other arbitrary
119 // operation.
120 //
121 // Note that this function will *not* be called unless
122 // set_cull_callback() is called in the constructor of
123 // the derived class. It is necessary to call
124 // set_cull_callback() to indicated that we require
125 // cull_callback() to be called.
126 //
127 // By the time this function is called, the node has
128 // already passed the bounding-volume test for the
129 // viewing frustum, and the node's transform and state
130 // have already been applied to the indicated
131 // CullTraverserData object.
132 //
133 // The return value is \true if this node should be
134 // visible, or false if it should be culled.
135 ////////////////////////////////////////////////////////////////////
136 bool UvScrollNode::
138  double elapsed = ClockObject::get_global_clock()->get_frame_time() - _start_time;
139  CPT(TransformState) ts = TransformState::make_pos_hpr(
140  LVecBase3(cmod(elapsed * _u_speed, 1.0) / 1.0,
141  cmod(elapsed * _v_speed, 1.0) / 1.0,
142  cmod(elapsed * _w_speed, 1.0) / 1.0),
143  LVecBase3((cmod(elapsed * _r_speed, 1.0) / 1.0) * 360, 0, 0));
144 
145  CPT(RenderAttrib) tm = TexMatrixAttrib::make(TextureStage::get_default(), ts);
146  CPT(RenderState) rs = RenderState::make_empty()->set_attrib(tm);
147  data._state = data._state->compose(rs);
148 
149  return true;
150 }
151 
152 ////////////////////////////////////////////////////////////////////
153 // Function: UvScrollNode::safe_to_flatten
154 // Access: Public, Virtual
155 // Description: Returns true if it is generally safe to flatten out
156 // this particular kind of PandaNode by duplicating
157 // instances (by calling dupe_for_flatten()), false
158 // otherwise (for instance, a Camera cannot be safely
159 // flattened, because the Camera pointer itself is
160 // meaningful).
161 ////////////////////////////////////////////////////////////////////
162 bool UvScrollNode::
164  return false;
165 }
166 
167 ////////////////////////////////////////////////////////////////////
168 // Function: UvScrollNode::safe_to_combine
169 // Access: Public, Virtual
170 // Description: Returns true if it is generally safe to combine this
171 // with other nodes, which it isn't, so don't. Ever.
172 ////////////////////////////////////////////////////////////////////
173 bool UvScrollNode::
175  return false;
176 }
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
Definition: clockObject.I:271
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
static void register_with_read_factory()
Tells the BamReader how to create objects of type UvScrollNode.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
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:4164
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating ...
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
Definition: clockObject.I:48
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
Definition: bamReader.I:105
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
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 bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This node is placed at key points within the scene graph to animate uvs.
Definition: uvScrollNode.h:29
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
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
static TextureStage * get_default()
Returns the default TextureStage that will be used for all texturing that does not name a particular ...
Definition: textureStage.I:766
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this with other nodes, which it isn't, so don't.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.