Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/gobj/orthographicLens.cxx

Go to the documentation of this file.
00001 // Filename: orthographicLens.cxx
00002 // Created by:  mike (18Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "orthographicLens.h"
00020 #include "indent.h"
00021 
00022 TypeHandle OrthographicLens::_type_handle;
00023 
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: OrthographicLens::make_copy
00027 //       Access: Public, Virtual
00028 //  Description: Allocates a new Lens just like this one.
00029 ////////////////////////////////////////////////////////////////////
00030 PT(Lens) OrthographicLens::
00031 make_copy() const {
00032   return new OrthographicLens(*this);
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: OrthographicLens::is_linear
00037 //       Access: Published, Virtual
00038 //  Description: Returns true if the lens represents a linear
00039 //               projection (e.g. PerspectiveLens, OrthographicLens),
00040 //               and therefore there is a valid matrix returned by
00041 //               get_projection_mat(), or false otherwise.
00042 ////////////////////////////////////////////////////////////////////
00043 bool OrthographicLens::
00044 is_linear() const {
00045   return true;
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: OrthographicLens::write
00050 //       Access: Public, Virtual
00051 //  Description: 
00052 ////////////////////////////////////////////////////////////////////
00053 void OrthographicLens::
00054 write(ostream &out, int indent_level) const {
00055   indent(out, indent_level) << get_type() << " film size = " << get_film_size() << "\n";
00056 }
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //     Function: OrthographicLens::compute_projection_mat
00060 //       Access: Protected, Virtual
00061 //  Description: Computes the complete transformation matrix from 3-d
00062 //               point to 2-d point, if the lens is linear.
00063 ////////////////////////////////////////////////////////////////////
00064 void OrthographicLens::
00065 compute_projection_mat() {
00066   CoordinateSystem cs = _cs;
00067   if (cs == CS_default) {
00068     cs = default_coordinate_system;
00069   }
00070 
00071   float a = 2.0f / (_far_distance - _near_distance);
00072   float b = -(_far_distance + _near_distance) / (_far_distance - _near_distance);
00073 
00074   LMatrix4f canonical;
00075   switch (cs) {
00076   case CS_zup_right:
00077     canonical.set(1.0f,  0.0f,  0.0f,  0.0f,
00078                   0.0f,  0.0f,     a,  0.0f,
00079                   0.0f,  1.0f,  0.0f,  0.0f,
00080                   0.0f,  0.0f,     b,  1.0f);
00081     break;
00082 
00083   case CS_yup_right:
00084     canonical.set(1.0f,  0.0f,  0.0f,  0.0f,
00085                   0.0f,  1.0f,  0.0f,  0.0f,
00086                   0.0f,  0.0f,    -a,  0.0f,
00087                   0.0f,  0.0f,     b,  1.0f);
00088     break;
00089 
00090   case CS_zup_left:
00091     canonical.set(1.0f,  0.0f,  0.0f,  0.0f,
00092                   0.0f,  0.0f,    -a,  0.0f,
00093                   0.0f,  1.0f,  0.0f,  0.0f,
00094                   0.0f,  0.0f,     b,  1.0f);
00095     break;
00096 
00097   case CS_yup_left:
00098     canonical.set(1.0f,  0.0f,  0.0f,  0.0f,
00099                   0.0f,  1.0f,  0.0f,  0.0f,
00100                   0.0f,  0.0f,     a,  0.0f,
00101                   0.0f,  0.0f,     b,  1.0f);
00102     break;
00103 
00104   default:
00105     gobj_cat.error()
00106       << "Invalid coordinate system " << (int)cs << " in PerspectiveLens!\n";
00107     canonical = LMatrix4f::ident_mat();
00108   }
00109 
00110 
00111   _projection_mat = get_lens_mat_inv() * canonical * get_film_mat();
00112   adjust_comp_flags(CF_projection_mat_inv, 
00113                     CF_projection_mat);
00114 }

Generated on Fri May 2 00:39:39 2003 for Panda by doxygen1.3