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