Panda3D
fltEyepoint.cxx
1 // Filename: fltEyepoint.cxx
2 // Created by: drose (26Aug00)
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 "fltEyepoint.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: FltEyepoint::Constructor
21 // Access: Public
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 FltEyepoint::
25 FltEyepoint() {
26  _rotation_center.set(0.0, 0.0, 0.0);
27  _hpr.set(0.0, 0.0, 0.0);
28  _rotation = LMatrix4::ident_mat();
29  _fov = 60.0;
30  _scale = 1.0;
31  _near_clip = 0.1;
32  _far_clip = 10000.0;
33  _fly_through = LMatrix4::ident_mat();
34  _eyepoint.set(0.0, 0.0, 0.0);
35  _fly_through_yaw = 0.0;
36  _fly_through_pitch = 0.0;
37  _eyepoint_direction.set(0.0, 1.0, 0.0);
38  _no_fly_through = true;
39  _ortho_mode = false;
40  _is_valid = true;
41  _image_offset_x = 0;
42  _image_offset_y = 0;
43  _image_zoom = 1;
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: FltEyepoint::extract_record
48 // Access: Public
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 bool FltEyepoint::
52 extract_record(FltRecordReader &reader) {
53  DatagramIterator &iterator = reader.get_iterator();
54 
55  _rotation_center[0] = iterator.get_be_float64();
56  _rotation_center[1] = iterator.get_be_float64();
57  _rotation_center[2] = iterator.get_be_float64();
58  _hpr[0] = iterator.get_be_float32();
59  _hpr[1] = iterator.get_be_float32();
60  _hpr[2] = iterator.get_be_float32();
61  int r;
62  for (r = 0; r < 4; r++) {
63  for (int c = 0; c < 4; c++) {
64  _rotation(r, c) = iterator.get_be_float32();
65  }
66  }
67  _fov = iterator.get_be_float32();
68  _scale = iterator.get_be_float32();
69  _near_clip = iterator.get_be_float32();
70  _far_clip = iterator.get_be_float32();
71  for (r = 0; r < 4; r++) {
72  for (int c = 0; c < 4; c++) {
73  _fly_through(r, c) = iterator.get_be_float32();
74  }
75  }
76  _eyepoint[0] = iterator.get_be_float32();
77  _eyepoint[1] = iterator.get_be_float32();
78  _eyepoint[2] = iterator.get_be_float32();
79  _fly_through_yaw = iterator.get_be_float32();
80  _fly_through_pitch = iterator.get_be_float32();
81  _eyepoint_direction[0] = iterator.get_be_float32();
82  _eyepoint_direction[1] = iterator.get_be_float32();
83  _eyepoint_direction[2] = iterator.get_be_float32();
84  _no_fly_through = (iterator.get_be_int32() != 0);
85  _ortho_mode = (iterator.get_be_int32() != 0);
86  _is_valid = (iterator.get_be_int32() != 0);
87  _image_offset_x = iterator.get_be_int32();
88  _image_offset_y = iterator.get_be_int32();
89  _image_zoom = iterator.get_be_int32();
90  iterator.skip_bytes(4*9);
91 
92  return true;
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: FltEyepoint::build_record
97 // Access: Public
98 // Description:
99 ////////////////////////////////////////////////////////////////////
100 bool FltEyepoint::
101 build_record(FltRecordWriter &writer) const {
102  Datagram &datagram = writer.update_datagram();
103 
104  datagram.add_be_float64(_rotation_center[0]);
105  datagram.add_be_float64(_rotation_center[1]);
106  datagram.add_be_float64(_rotation_center[2]);
107  datagram.add_be_float32(_hpr[0]);
108  datagram.add_be_float32(_hpr[1]);
109  datagram.add_be_float32(_hpr[2]);
110  int r;
111  for (r = 0; r < 4; r++) {
112  for (int c = 0; c < 4; c++) {
113  datagram.add_be_float32(_rotation(r, c));
114  }
115  }
116  datagram.add_be_float32(_fov);
117  datagram.add_be_float32(_scale);
118  datagram.add_be_float32(_near_clip);
119  datagram.add_be_float32(_far_clip);
120  for (r = 0; r < 4; r++) {
121  for (int c = 0; c < 4; c++) {
122  datagram.add_be_float32(_fly_through(r, c));
123  }
124  }
125  datagram.add_be_float32(_eyepoint[0]);
126  datagram.add_be_float32(_eyepoint[1]);
127  datagram.add_be_float32(_eyepoint[2]);
128  datagram.add_be_float32(_fly_through_yaw);
129  datagram.add_be_float32(_fly_through_pitch);
130  datagram.add_be_float32(_eyepoint_direction[0]);
131  datagram.add_be_float32(_eyepoint_direction[1]);
132  datagram.add_be_float32(_eyepoint_direction[2]);
133  datagram.add_be_int32(_no_fly_through);
134  datagram.add_be_int32(_ortho_mode);
135  datagram.add_be_int32(_is_valid);
136  datagram.add_be_int32(_image_offset_x);
137  datagram.add_be_int32(_image_offset_y);
138  datagram.add_be_int32(_image_zoom);
139  datagram.pad_bytes(4*9);
140 
141  return true;
142 }
static const LMatrix4f & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:903
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...
PN_float64 get_be_float64()
Extracts a 64-bit big-endian floating-point number.
PN_float32 get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
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:111
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
Definition: datagram.I:339
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
Definition: datagram.I:327
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
void add_be_int32(PN_int32 value)
Adds a signed 32-bit big-endian integer to the datagram.
Definition: datagram.I:267
A class to retrieve the individual data elements previously stored in a Datagram. ...
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:43
PN_int32 get_be_int32()
Extracts a signed 32-bit big-endian integer.