Panda3D
Loading...
Searching...
No Matches
texturePosition.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 texturePosition.cxx
10 * @author drose
11 * @date 2000-12-04
12 */
13
14#include "texturePosition.h"
15
16#include "datagram.h"
17#include "datagramIterator.h"
18#include "bamReader.h"
19#include "bamWriter.h"
20
21TypeHandle TexturePosition::_type_handle;
22
23/**
24 *
25 */
26TexturePosition::
27TexturePosition() {
28 _margin = 0;
29 _x = 0;
30 _y = 0;
31 _x_size = 0;
32 _y_size = 0;
33 _min_uv.set(0.0, 0.0);
34 _max_uv.set(0.0, 0.0);
35 _wrap_u = EggTexture::WM_unspecified;
36 _wrap_v = EggTexture::WM_unspecified;
37}
38
39/**
40 *
41 */
42TexturePosition::
43TexturePosition(const TexturePosition &copy) :
44 _margin(copy._margin),
45 _x(copy._x),
46 _y(copy._y),
47 _x_size(copy._x_size),
48 _y_size(copy._y_size),
49 _min_uv(copy._min_uv),
50 _max_uv(copy._max_uv),
51 _wrap_u(copy._wrap_u),
52 _wrap_v(copy._wrap_v)
53{
54}
55
56/**
57 *
58 */
59void TexturePosition::
60operator = (const TexturePosition &copy) {
61 _margin = copy._margin;
62 _x = copy._x;
63 _y = copy._y;
64 _x_size = copy._x_size;
65 _y_size = copy._y_size;
66 _min_uv = copy._min_uv;
67 _max_uv = copy._max_uv;
68 _wrap_u = copy._wrap_u;
69 _wrap_v = copy._wrap_v;
70}
71
72/**
73 * Registers the current object as something that can be read from a Bam file.
74 */
78 register_factory(get_class_type(), make_TexturePosition);
79}
80
81/**
82 * Fills the indicated datagram up with a binary representation of the current
83 * object, in preparation for writing to a Bam file.
84 */
86write_datagram(BamWriter *writer, Datagram &datagram) {
87 TypedWritable::write_datagram(writer, datagram);
88 datagram.add_int32(_margin);
89 datagram.add_int32(_x);
90 datagram.add_int32(_y);
91 datagram.add_int32(_x_size);
92 datagram.add_int32(_y_size);
93 datagram.add_float64(_min_uv[0]);
94 datagram.add_float64(_min_uv[1]);
95 datagram.add_float64(_max_uv[0]);
96 datagram.add_float64(_max_uv[1]);
97 datagram.add_int32((int)_wrap_u);
98 datagram.add_int32((int)_wrap_v);
99}
100
101/**
102 * This method is called by the BamReader when an object of this type is
103 * encountered in a Bam file; it should allocate and return a new object with
104 * all the data read.
105 */
106TypedWritable* TexturePosition::
107make_TexturePosition(const FactoryParams &params) {
109 DatagramIterator scan;
110 BamReader *manager;
111
112 parse_params(params, scan, manager);
113 me->fillin(scan, manager);
114 return me;
115}
116
117/**
118 * Reads the binary data from the given datagram iterator, which was written
119 * by a previous call to write_datagram().
120 */
122fillin(DatagramIterator &scan, BamReader *manager) {
123 TypedWritable::fillin(scan, manager);
124 _margin = scan.get_int32();
125 _x = scan.get_int32();
126 _y = scan.get_int32();
127 _x_size = scan.get_int32();
128 _y_size = scan.get_int32();
129 _min_uv[0] = scan.get_float64();
130 _min_uv[1] = scan.get_float64();
131 _max_uv[0] = scan.get_float64();
132 _max_uv[1] = scan.get_float64();
133 _wrap_u = (EggTexture::WrapMode)scan.get_int32();
134 _wrap_v = (EggTexture::WrapMode)scan.get_int32();
135}
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.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
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
A class to retrieve the individual data elements previously stored in a Datagram.
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
int32_t get_int32()
Extracts a signed 32-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
Definition datagram.I:67
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
Definition datagram.I:123
An instance of this class is passed to the Factory when requesting it to do its business and construc...
This represents a particular position of a texture within a PaletteImage.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.