Panda3D
matrixLens.cxx
1 // Filename: matrixLens.cxx
2 // Created by: drose (12Dec01)
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 "matrixLens.h"
16 #include "indent.h"
17 #include "bamReader.h"
18 
19 TypeHandle MatrixLens::_type_handle;
20 
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: MatrixLens::make_copy
24 // Access: Public, Virtual
25 // Description: Allocates a new Lens just like this one.
26 ////////////////////////////////////////////////////////////////////
27 PT(Lens) MatrixLens::
28 make_copy() const {
29  return new MatrixLens(*this);
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: MatrixLens::is_linear
34 // Access: Published, Virtual
35 // Description: Returns true if the lens represents a linear
36 // projection (e.g. PerspectiveLens, MatrixLens),
37 // and therefore there is a valid matrix returned by
38 // get_projection_mat(), or false otherwise.
39 ////////////////////////////////////////////////////////////////////
40 bool MatrixLens::
41 is_linear() const {
42  return true;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: MatrixLens::write
47 // Access: Public, Virtual
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 void MatrixLens::
51 write(ostream &out, int indent_level) const {
52  indent(out, indent_level) << get_type() << ":\n";
53  get_projection_mat().write(out, indent_level + 2);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: MatrixLens::do_compute_projection_mat
58 // Access: Protected, Virtual
59 // Description: Computes the complete transformation matrix from 3-d
60 // point to 2-d point, if the lens is linear.
61 ////////////////////////////////////////////////////////////////////
62 void MatrixLens::
63 do_compute_projection_mat(Lens::CData *lens_cdata) {
64  lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * _user_mat * do_get_film_mat(lens_cdata);
65 
66  if (_ml_flags & MF_has_left_eye) {
67  lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) * _left_eye_mat * do_get_film_mat(lens_cdata);
68  } else {
69  lens_cdata->_projection_mat_left = lens_cdata->_projection_mat;
70  }
71 
72  if (_ml_flags & MF_has_right_eye) {
73  lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) * _right_eye_mat * do_get_film_mat(lens_cdata);
74  } else {
75  lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
76  }
77 
78  do_adjust_comp_flags(lens_cdata, CF_projection_mat_inv,
79  CF_projection_mat);
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: MatrixLens::register_with_read_factory
84 // Access: Public, Static
85 // Description: Tells the BamReader how to create objects of type
86 // Lens.
87 ////////////////////////////////////////////////////////////////////
88 void MatrixLens::
90  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: MatrixLens::make_from_bam
95 // Access: Protected, Static
96 // Description: This function is called by the BamReader's factory
97 // when a new object of type Lens is encountered
98 // in the Bam file. It should create the Lens
99 // and extract its information from the file.
100 ////////////////////////////////////////////////////////////////////
101 TypedWritable *MatrixLens::
102 make_from_bam(const FactoryParams &params) {
103  MatrixLens *lens = new MatrixLens;
104  DatagramIterator scan;
105  BamReader *manager;
106 
107  parse_params(params, scan, manager);
108  lens->fillin(scan, manager);
109 
110  return lens;
111 }
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:45
A completely generic linear lens.
Definition: matrixLens.h:31
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
static void register_with_read_factory()
Tells the BamReader how to create objects of type Lens.
Definition: matrixLens.cxx:89
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
const LMatrix4 & get_projection_mat(StereoChannel channel=SC_mono) const
Returns the complete transformation matrix from a 3-d point in space to a point on the film...
Definition: lens.I:717
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
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:85
virtual bool is_linear() const
Returns true if the lens represents a linear projection (e.g.