Panda3D
 All Classes Functions Variables Enumerations
vertexTransform.cxx
1 // Filename: vertexTransform.cxx
2 // Created by: drose (23Mar05)
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 "vertexTransform.h"
16 #include "bamReader.h"
17 #include "bamWriter.h"
18 #include "indent.h"
19 #include "transformTable.h"
20 
21 PipelineCycler<VertexTransform::CData> VertexTransform::_global_cycler;
22 UpdateSeq VertexTransform::_next_modified;
23 
24 TypeHandle VertexTransform::_type_handle;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: VertexTransform::Constructor
28 // Access: Published
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 VertexTransform::
32 VertexTransform() {
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: VertexTransform::Destructor
37 // Access: Published, Virtual
38 // Description:
39 ////////////////////////////////////////////////////////////////////
40 VertexTransform::
41 ~VertexTransform() {
42  // We shouldn't destruct while any TransformTables are holding our
43  // pointer.
44  nassertv(_tables.empty());
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: VertexTransform::mult_matrix
49 // Access: Published, Virtual
50 // Description: Premultiplies this transform's matrix with the
51 // indicated previous matrix, so that the result is the
52 // net composition of the given transform with this
53 // transform. The result is stored in the parameter
54 // "result", which should not be the same matrix as
55 // previous.
56 ////////////////////////////////////////////////////////////////////
58 mult_matrix(LMatrix4 &result, const LMatrix4 &previous) const {
59  nassertv(&result != &previous);
60  LMatrix4 me;
61  get_matrix(me);
62  result.multiply(me, previous);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: VertexTransform::accumulate_matrix
67 // Access: Published, Virtual
68 // Description: Adds the value of this transform's matrix, modified
69 // by the indicated weight, into the indicated
70 // accumulation matrix. This is used to compute the
71 // result of several blended transforms.
72 ////////////////////////////////////////////////////////////////////
74 accumulate_matrix(LMatrix4 &accum, PN_stdfloat weight) const {
75  LMatrix4 me;
76  get_matrix(me);
77  accum.accumulate(me, weight);
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: VertexTransform::output
82 // Access: Published, Virtual
83 // Description:
84 ////////////////////////////////////////////////////////////////////
85 void VertexTransform::
86 output(ostream &out) const {
87  out << get_type();
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: VertexTransform::write
92 // Access: Published, Virtual
93 // Description:
94 ////////////////////////////////////////////////////////////////////
95 void VertexTransform::
96 write(ostream &out, int indent_level) const {
97  indent(out, indent_level)
98  << *this << ":\n";
99  LMatrix4 mat;
100  get_matrix(mat);
101  mat.write(out, indent_level + 2);
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: VertexTransform::get_next_modified
106 // Access: Public, Static
107 // Description: Returns a monotonically increasing sequence. Each
108 // time this is called, a new sequence number is
109 // returned, higher than the previous value.
110 //
111 // This is used to ensure that all
112 // VertexTransform::get_modified() calls return an
113 // increasing number in the same space, so that
114 // TransformBlend::get_modified() is easy to determine.
115 // It is similar to Geom::get_modified(), but it is in a
116 // different space.
117 ////////////////////////////////////////////////////////////////////
119 get_next_modified(Thread *current_thread) {
120  CDWriter cdatag(_global_cycler, true, current_thread);
121  ++_next_modified;
122  cdatag->_modified = _next_modified;
123 
124  return _next_modified;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: VertexTransform::mark_modified
129 // Access: Protected
130 // Description: Intended to be called by a derived class whenever the
131 // reported transform might have changed. Without
132 // calling this method, changes to get_matrix() may not
133 // be propagated through the system.
134 ////////////////////////////////////////////////////////////////////
135 void VertexTransform::
136 mark_modified(Thread *current_thread) {
137  CDWriter cdata(_cycler, true, current_thread);
138  cdata->_modified = get_next_modified(current_thread);
139 
140  Palettes::iterator pi;
141  for (pi = _tables.begin(); pi != _tables.end(); ++pi) {
142  (*pi)->update_modified(cdata->_modified, current_thread);
143  }
144 }
145 
146 ////////////////////////////////////////////////////////////////////
147 // Function: VertexTransform::write_datagram
148 // Access: Public, Virtual
149 // Description: Writes the contents of this object to the datagram
150 // for shipping out to a Bam file.
151 ////////////////////////////////////////////////////////////////////
154  TypedWritable::write_datagram(manager, dg);
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: VertexTransform::fillin
159 // Access: Protected
160 // Description: This internal function is called by make_from_bam to
161 // read in all of the relevant data from the BamFile for
162 // the new VertexTransform.
163 ////////////////////////////////////////////////////////////////////
164 void VertexTransform::
165 fillin(DatagramIterator &scan, BamReader *manager) {
166  TypedWritable::fillin(scan, manager);
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: VertexTransform::CData::make_copy
171 // Access: Public, Virtual
172 // Description:
173 ////////////////////////////////////////////////////////////////////
174 CycleData *VertexTransform::CData::
175 make_copy() const {
176  return new CData(*this);
177 }
178 
179 ////////////////////////////////////////////////////////////////////
180 // Function: VertexTransform::CData::write_datagram
181 // Access: Public, Virtual
182 // Description: Writes the contents of this object to the datagram
183 // for shipping out to a Bam file.
184 ////////////////////////////////////////////////////////////////////
185 void VertexTransform::CData::
186 write_datagram(BamWriter *manager, Datagram &dg) const {
187 }
188 
189 ////////////////////////////////////////////////////////////////////
190 // Function: VertexTransform::CData::complete_pointers
191 // Access: Public, Virtual
192 // Description: Receives an array of pointers, one for each time
193 // manager->read_pointer() was called in fillin().
194 // Returns the number of pointers processed.
195 ////////////////////////////////////////////////////////////////////
196 int VertexTransform::CData::
197 complete_pointers(TypedWritable **p_list, BamReader *manager) {
198  int pi = CycleData::complete_pointers(p_list, manager);
199 
200  return pi;
201 }
202 
203 ////////////////////////////////////////////////////////////////////
204 // Function: VertexTransform::CData::fillin
205 // Access: Public, Virtual
206 // Description: This internal function is called by make_from_bam to
207 // read in all of the relevant data from the BamFile for
208 // the new VertexTransform.
209 ////////////////////////////////////////////////////////////////////
210 void VertexTransform::CData::
211 fillin(DatagramIterator &scan, BamReader *manager) {
212 }
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
virtual void accumulate_matrix(LMatrix4 &accum, PN_stdfloat weight) const
Adds the value of this transform&#39;s matrix, modified by the indicated weight, into the indicated accum...
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
static UpdateSeq get_next_modified(Thread *current_thread)
Returns a monotonically increasing sequence.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
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 int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager-&gt;read_pointer() was called in fillin()...
Definition: cycleData.cxx:55
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
void accumulate(const LMatrix4f &other, float weight)
Computes (*this) += other * weight.
Definition: lmatrix.h:2300
A thread; that is, a lightweight process.
Definition: thread.h:51
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
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual void mult_matrix(LMatrix4 &result, const LMatrix4 &previous) const
Premultiplies this transform&#39;s matrix with the indicated previous matrix, so that the result is the n...