Panda3D

matrixLens.cxx

00001 // Filename: matrixLens.cxx
00002 // Created by:  drose (12Dec01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "matrixLens.h"
00016 #include "indent.h"
00017 #include "bamReader.h"
00018 
00019 TypeHandle MatrixLens::_type_handle;
00020 
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: MatrixLens::make_copy
00024 //       Access: Public, Virtual
00025 //  Description: Allocates a new Lens just like this one.
00026 ////////////////////////////////////////////////////////////////////
00027 PT(Lens) MatrixLens::
00028 make_copy() const {
00029   return new MatrixLens(*this);
00030 }
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: MatrixLens::is_linear
00034 //       Access: Published, Virtual
00035 //  Description: Returns true if the lens represents a linear
00036 //               projection (e.g. PerspectiveLens, MatrixLens),
00037 //               and therefore there is a valid matrix returned by
00038 //               get_projection_mat(), or false otherwise.
00039 ////////////////////////////////////////////////////////////////////
00040 bool MatrixLens::
00041 is_linear() const {
00042   return true;
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: MatrixLens::write
00047 //       Access: Public, Virtual
00048 //  Description: 
00049 ////////////////////////////////////////////////////////////////////
00050 void MatrixLens::
00051 write(ostream &out, int indent_level) const {
00052   indent(out, indent_level) << get_type() << ":\n";
00053   get_projection_mat().write(out, indent_level + 2);
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: MatrixLens::do_compute_projection_mat
00058 //       Access: Protected, Virtual
00059 //  Description: Computes the complete transformation matrix from 3-d
00060 //               point to 2-d point, if the lens is linear.
00061 ////////////////////////////////////////////////////////////////////
00062 void MatrixLens::
00063 do_compute_projection_mat(Lens::CData *lens_cdata) {
00064   lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * _user_mat * do_get_film_mat(lens_cdata);
00065   
00066   if (_ml_flags & MF_has_left_eye) {
00067     lens_cdata->_projection_mat_left = do_get_lens_mat_inv(lens_cdata) * _left_eye_mat * do_get_film_mat(lens_cdata);
00068   } else {
00069     lens_cdata->_projection_mat_left = lens_cdata->_projection_mat;
00070   }
00071   
00072   if (_ml_flags & MF_has_right_eye) {
00073     lens_cdata->_projection_mat_right = do_get_lens_mat_inv(lens_cdata) * _right_eye_mat * do_get_film_mat(lens_cdata);
00074   } else {
00075     lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
00076   }
00077   
00078   do_adjust_comp_flags(lens_cdata, CF_projection_mat_inv, 
00079                        CF_projection_mat);
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: MatrixLens::register_with_read_factory
00084 //       Access: Public, Static
00085 //  Description: Tells the BamReader how to create objects of type
00086 //               Lens.
00087 ////////////////////////////////////////////////////////////////////
00088 void MatrixLens::
00089 register_with_read_factory() {
00090   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: MatrixLens::make_from_bam
00095 //       Access: Protected, Static
00096 //  Description: This function is called by the BamReader's factory
00097 //               when a new object of type Lens is encountered
00098 //               in the Bam file.  It should create the Lens
00099 //               and extract its information from the file.
00100 ////////////////////////////////////////////////////////////////////
00101 TypedWritable *MatrixLens::
00102 make_from_bam(const FactoryParams &params) {
00103   MatrixLens *lens = new MatrixLens;
00104   DatagramIterator scan;
00105   BamReader *manager;
00106 
00107   parse_params(params, scan, manager);
00108   lens->fillin(scan, manager);
00109 
00110   return lens;
00111 }
 All Classes Functions Variables Enumerations