Panda3D
vertexTransform.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 vertexTransform.cxx
10  * @author drose
11  * @date 2005-03-23
12  */
13 
14 #include "vertexTransform.h"
15 #include "bamReader.h"
16 #include "bamWriter.h"
17 #include "indent.h"
18 #include "transformTable.h"
19 
20 PipelineCycler<VertexTransform::CData> VertexTransform::_global_cycler;
21 UpdateSeq VertexTransform::_next_modified;
22 
23 TypeHandle VertexTransform::_type_handle;
24 
25 /**
26  *
27  */
28 VertexTransform::
29 VertexTransform() {
30 }
31 
32 /**
33  *
34  */
35 VertexTransform::
36 ~VertexTransform() {
37  // We shouldn't destruct while any TransformTables are holding our pointer.
38  nassertv(_tables.empty());
39 }
40 
41 /**
42  * Premultiplies this transform's matrix with the indicated previous matrix,
43  * so that the result is the net composition of the given transform with this
44  * transform. The result is stored in the parameter "result", which should
45  * not be the same matrix as previous.
46  */
48 mult_matrix(LMatrix4 &result, const LMatrix4 &previous) const {
49  nassertv(&result != &previous);
50  LMatrix4 me;
51  get_matrix(me);
52  result.multiply(me, previous);
53 }
54 
55 /**
56  * Adds the value of this transform's matrix, modified by the indicated
57  * weight, into the indicated accumulation matrix. This is used to compute
58  * the result of several blended transforms.
59  */
61 accumulate_matrix(LMatrix4 &accum, PN_stdfloat weight) const {
62  LMatrix4 me;
63  get_matrix(me);
64  accum.accumulate(me, weight);
65 }
66 
67 /**
68  *
69  */
70 void VertexTransform::
71 output(std::ostream &out) const {
72  out << get_type();
73 }
74 
75 /**
76  *
77  */
78 void VertexTransform::
79 write(std::ostream &out, int indent_level) const {
80  indent(out, indent_level)
81  << *this << ":\n";
82  LMatrix4 mat;
83  get_matrix(mat);
84  mat.write(out, indent_level + 2);
85 }
86 
87 /**
88  * Returns a monotonically increasing sequence. Each time this is called, a
89  * new sequence number is returned, higher than the previous value.
90  *
91  * This is used to ensure that all VertexTransform::get_modified() calls
92  * return an increasing number in the same space, so that
93  * TransformBlend::get_modified() is easy to determine. It is similar to
94  * Geom::get_modified(), but it is in a different space.
95  */
97 get_next_modified(Thread *current_thread) {
98  CDWriter cdatag(_global_cycler, true, current_thread);
99  ++_next_modified;
100  cdatag->_modified = _next_modified;
101 
102  return _next_modified;
103 }
104 
105 /**
106  * Intended to be called by a derived class whenever the reported transform
107  * might have changed. Without calling this method, changes to get_matrix()
108  * may not be propagated through the system.
109  */
110 void VertexTransform::
111 mark_modified(Thread *current_thread) {
112  CDWriter cdata(_cycler, true, current_thread);
113  cdata->_modified = get_next_modified(current_thread);
114 
115  Palettes::iterator pi;
116  for (pi = _tables.begin(); pi != _tables.end(); ++pi) {
117  (*pi)->update_modified(cdata->_modified, current_thread);
118  }
119 }
120 
121 /**
122  * Writes the contents of this object to the datagram for shipping out to a
123  * Bam file.
124  */
127  TypedWritable::write_datagram(manager, dg);
128 }
129 
130 /**
131  * This internal function is called by make_from_bam to read in all of the
132  * relevant data from the BamFile for the new VertexTransform.
133  */
134 void VertexTransform::
135 fillin(DatagramIterator &scan, BamReader *manager) {
136  TypedWritable::fillin(scan, manager);
137 }
138 
139 /**
140  *
141  */
142 CycleData *VertexTransform::CData::
143 make_copy() const {
144  return new CData(*this);
145 }
146 
147 /**
148  * Writes the contents of this object to the datagram for shipping out to a
149  * Bam file.
150  */
151 void VertexTransform::CData::
152 write_datagram(BamWriter *manager, Datagram &dg) const {
153 }
154 
155 /**
156  * Receives an array of pointers, one for each time manager->read_pointer()
157  * was called in fillin(). Returns the number of pointers processed.
158  */
159 int VertexTransform::CData::
160 complete_pointers(TypedWritable **p_list, BamReader *manager) {
161  int pi = CycleData::complete_pointers(p_list, manager);
162 
163  return pi;
164 }
165 
166 /**
167  * This internal function is called by make_from_bam to read in all of the
168  * relevant data from the BamFile for the new VertexTransform.
169  */
170 void VertexTransform::CData::
171 fillin(DatagramIterator &scan, BamReader *manager) {
172 }
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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:63
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class'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.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
virtual void mult_matrix(LMatrix4 &result, const LMatrix4 &previous) const
Premultiplies this transform's matrix with the indicated previous matrix, so that the result is the n...
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->read_pointer() was called in fillin().
Definition: cycleData.cxx:48
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void accumulate_matrix(LMatrix4 &accum, PN_stdfloat weight) const
Adds the value of this transform's matrix, modified by the indicated weight, into the indicated accum...
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:81
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.