Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CameraProjection.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile: CameraProjection.cpp,v $
00027  * Date modified: $Date: 2003/10/06 19:28:50 $
00028  * Version:       $Revision: 1.10 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <vrj/vrjConfig.h>
00034 
00035 #include <jccl/Config/ConfigElement.h>
00036 
00037 #include <gmtl/Output.h>
00038 #include <gmtl/Generate.h>
00039 
00040 #include <vrj/Display/Display.h>
00041 #include <vrj/Display/CameraProjection.h>
00042 
00043 #include <boost/concept_check.hpp>
00044 
00045 
00046 namespace vrj
00047 {
00048 
00049 void CameraProjection::config(jccl::ConfigElementPtr element)
00050 {
00051    Projection::config(element);
00052 }
00053 
00058 void CameraProjection::calcViewMatrix(gmtl::Matrix44f& cameraPos, const float scaleFactor)
00059 {
00060    boost::ignore_unused_variable_warning(scaleFactor);
00061    mViewMat = cameraPos;
00062 
00063    gmtl::Vec3f camera_trans = gmtl::makeTrans<gmtl::Vec3f>(cameraPos);
00064    vprDEBUG(vprDBG_ALL, vprDBG_DETAILED_LVL) << "calcView: Cam pos:" << camera_trans << std::endl << vprDEBUG_FLUSH;
00065 
00066    int win_xo, win_yo, win_xs, win_ys;  // origin and size of display window
00067    float vp_xo, vp_yo, vp_xs, vp_ys;  // origin and size of viewport
00068    float width, height;
00069    float aspect_ratio;
00070 
00071    getViewport()->getDisplay()->getOriginAndSize(win_xo,win_yo, win_xs, win_ys);
00072    getViewport()->getOriginAndSize( vp_xo, vp_yo, vp_xs, vp_ys );
00073    width = float(win_xs) * vp_xs;
00074    height = float(win_ys) * vp_ys;
00075 
00076    aspect_ratio = (width/height);
00077 
00078    // Calculate frustum
00079    float top, right;
00080    top = gmtl::Math::tan( gmtl::Math::deg2Rad(mVertFOV/2.0f) ) * mNearDist;     // Calculate the top based on fovy
00081    right = aspect_ratio * top;
00082 
00083    // Calculate the frustum to use for the camera
00084    mFrustum.set(-right, right, -top, top, mNearDist, mFarDist);
00085 }
00086 
00087 std::ostream& CameraProjection::outStream(std::ostream& out,
00088                                           const unsigned int indentLevel)
00089 {
00090 //   const int pad_width_dot(20 - indentLevel);
00091    out.setf(std::ios::left);
00092 
00093    const std::string indent_text(indentLevel, ' ');
00094 
00095    out << indent_text << "vrj::CameraProjection:\n";
00096 
00097    return Projection::outStream(out, indentLevel);
00098 }
00099 
00100 }

Generated on Sun May 2 15:10:16 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002