Panda3D
fltLightSourceDefinition.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 fltLightSourceDefinition.cxx
10  * @author drose
11  * @date 2000-08-26
12  */
13 
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17 
18 TypeHandle FltLightSourceDefinition::_type_handle;
19 
20 /**
21  *
22  */
23 FltLightSourceDefinition::
24 FltLightSourceDefinition(FltHeader *header) : FltRecord(header) {
25  _light_index = 0;
26  _ambient.set(0.0, 0.0, 0.0, 1.0);
27  _diffuse.set(1.0, 1.0, 1.0, 1.0);
28  _specular.set(0.0, 0.0, 0.0, 1.0);
29  _light_type = LT_infinite;
30  _exponential_dropoff = 1.0;
31  _cutoff_angle = 180.0;
32  _yaw = 0.0;
33  _pitch = 0.0;
34  _constant_coefficient = 0.0;
35  _linear_coefficient = 0.0;
36  _quadratic_coefficient = 1.0;
37  _modeling_light = false;
38 }
39 
40 /**
41  * Fills in the information in this record based on the information given in
42  * the indicated datagram, whose opcode has already been read. Returns true
43  * on success, false if the datagram is invalid.
44  */
45 bool FltLightSourceDefinition::
46 extract_record(FltRecordReader &reader) {
47  if (!FltRecord::extract_record(reader)) {
48  return false;
49  }
50 
51  nassertr(reader.get_opcode() == FO_light_definition, false);
52  DatagramIterator &iterator = reader.get_iterator();
53 
54  _light_index = iterator.get_be_int32();
55  iterator.skip_bytes(2*4);
56  _light_name = iterator.get_fixed_string(20);
57  iterator.skip_bytes(4);
58  _ambient[0] = iterator.get_be_float32();
59  _ambient[1] = iterator.get_be_float32();
60  _ambient[2] = iterator.get_be_float32();
61  _ambient[3] = iterator.get_be_float32();
62  _diffuse[0] = iterator.get_be_float32();
63  _diffuse[1] = iterator.get_be_float32();
64  _diffuse[2] = iterator.get_be_float32();
65  _diffuse[3] = iterator.get_be_float32();
66  _specular[0] = iterator.get_be_float32();
67  _specular[1] = iterator.get_be_float32();
68  _specular[2] = iterator.get_be_float32();
69  _specular[3] = iterator.get_be_float32();
70  _light_type = (LightType)iterator.get_be_int32();
71  iterator.skip_bytes(4*10);
72  _exponential_dropoff = iterator.get_be_float32();
73  _cutoff_angle = iterator.get_be_float32();
74  _yaw = iterator.get_be_float32();
75  _pitch = iterator.get_be_float32();
76  _constant_coefficient = iterator.get_be_float32();
77  _linear_coefficient = iterator.get_be_float32();
78  _quadratic_coefficient = iterator.get_be_float32();
79  _modeling_light = (iterator.get_be_int32() != 0);
80  iterator.skip_bytes(4*19);
81 
82  check_remaining_size(iterator);
83  return true;
84 }
85 
86 /**
87  * Fills up the current record on the FltRecordWriter with data for this
88  * record, but does not advance the writer. Returns true on success, false if
89  * there is some error.
90  */
91 bool FltLightSourceDefinition::
92 build_record(FltRecordWriter &writer) const {
93  if (!FltRecord::build_record(writer)) {
94  return false;
95  }
96 
97  writer.set_opcode(FO_light_definition);
98  Datagram &datagram = writer.update_datagram();
99 
100  datagram.add_be_int32(_light_index);
101  datagram.pad_bytes(2*4);
102  datagram.add_fixed_string(_light_name, 20);
103  datagram.pad_bytes(4);
104  datagram.add_be_float32(_ambient[0]);
105  datagram.add_be_float32(_ambient[1]);
106  datagram.add_be_float32(_ambient[2]);
107  datagram.add_be_float32(_ambient[3]);
108  datagram.add_be_float32(_diffuse[0]);
109  datagram.add_be_float32(_diffuse[1]);
110  datagram.add_be_float32(_diffuse[2]);
111  datagram.add_be_float32(_diffuse[3]);
112  datagram.add_be_float32(_specular[0]);
113  datagram.add_be_float32(_specular[1]);
114  datagram.add_be_float32(_specular[2]);
115  datagram.add_be_float32(_specular[3]);
116  datagram.add_be_int32(_light_type);
117  datagram.pad_bytes(4*10);
118  datagram.add_be_float32(_exponential_dropoff);
119  datagram.add_be_float32(_cutoff_angle);
120  datagram.add_be_float32(_yaw);
121  datagram.add_be_float32(_pitch);
122  datagram.add_be_float32(_constant_coefficient);
123  datagram.add_be_float32(_linear_coefficient);
124  datagram.add_be_float32(_quadratic_coefficient);
125  datagram.add_be_int32(_modeling_light);
126  datagram.pad_bytes(4*19);
127 
128  return true;
129 }
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly.
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void check_remaining_size(const DatagramIterator &di, const std::string &name=std::string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record.
Definition: fltRecord.cxx:254
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:99
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
Definition: datagram.I:200
The base class for all kinds of records in a MultiGen OpenFlight file.
Definition: fltRecord.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram.
void add_fixed_string(const std::string &str, size_t size)
Adds a fixed-length string to the datagram.
Definition: datagram.I:263
void add_be_int32(int32_t value)
Adds a signed 32-bit big-endian integer to the datagram.
Definition: datagram.I:154
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38