![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cRPerspectiveProjection.cppGo to the documentation of this file.00001 /************************************************************************ 00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library 00003 Copyright (C) 2003 Aaron Cameron 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 A copy of the GNU Lesser General Public License has been provided with 00020 this library in the file 'COPYING'. 00021 00022 Contact information for the author of this library has been provided 00023 with this library in the file 'AUTHOR'. 00024 ************************************************************************/ 00025 00026 #include "cRPerspectiveProjection.h" 00027 #include <GL/glu.h> 00028 00029 #include "n2l/dynVars.h" 00030 #include "n2l/vfs.h" 00031 00032 /******************************************************************************/ 00033 namespace n2l 00034 { 00035 /**************************************************************************/ 00036 cRPerspectiveProjection::cRPerspectiveProjection() 00037 { 00038 init(); 00039 } 00040 00041 /**************************************************************************/ 00042 cRPerspectiveProjection::cRPerspectiveProjection( 00043 const tDouble &iFovY, const tDouble &iYAspectRatio, 00044 const tDouble &iNear, const tDouble &iFar ) 00045 { 00046 init(); 00047 mFovY = iFovY; 00048 mYAspectRatio = iYAspectRatio; 00049 mNear = iNear; 00050 mFar = iFar; 00051 } 00052 00053 /**************************************************************************/ 00054 cRPerspectiveProjection::cRPerspectiveProjection( 00055 const cVfsNodeInterface &iNode ) 00056 { 00057 init(); 00058 load(iNode); 00059 } 00060 00061 /**************************************************************************/ 00062 cRPerspectiveProjection::cRPerspectiveProjection( const cDynVar &iDef ) 00063 { 00064 init(); 00065 load(iDef); 00066 } 00067 00068 /**************************************************************************/ 00069 cRPerspectiveProjection::~cRPerspectiveProjection() 00070 { 00071 } 00072 00073 /**************************************************************************/ 00074 void cRPerspectiveProjection::load( const cVfsNodeInterface &iNode ) 00075 { 00076 const tUint DataOffset = 00077 vfsNodeFileWithHeader( iNode, "n2l::cRPerspectiveProjection"); 00078 00079 cDynVar def; 00080 def.unserialize( iNode.buffer().c_str()+DataOffset ); 00081 load( def ); 00082 } 00083 00084 /**************************************************************************/ 00085 void cRPerspectiveProjection::load( const cDynVar &iDef ) 00086 { 00087 mFovY = iDef.keyValueOr( "fovY", tFloat(mFovY) ); 00088 mYAspectRatio = iDef.keyValueOr( "aspectY", tFloat(mYAspectRatio) ); 00089 mNear = iDef.keyValueOr( "near", tFloat(mNear) ); 00090 mFar = iDef.keyValueOr( "far", tFloat(mFar) ); 00091 } 00092 00093 /**************************************************************************/ 00094 void cRPerspectiveProjection::render() const 00095 { 00096 gluPerspective(mFovY,mYAspectRatio,mNear,mFar); 00097 } 00098 00099 /**************************************************************************/ 00100 const tDouble &cRPerspectiveProjection::yFov() const 00101 { 00102 return mFovY; 00103 } 00104 00105 /**************************************************************************/ 00106 const tDouble &cRPerspectiveProjection::yAspectRatio() const 00107 { 00108 return mYAspectRatio; 00109 } 00110 00111 /**************************************************************************/ 00112 const tDouble &cRPerspectiveProjection::farClipDistance() const 00113 { 00114 return mFar; 00115 } 00116 00117 /**************************************************************************/ 00118 const tDouble &cRPerspectiveProjection::nearClipDistance() const 00119 { 00120 return mNear; 00121 } 00122 00123 /**************************************************************************/ 00124 cRProjectionInterface *const cRPerspectiveProjection::clone() const 00125 { 00126 return new cRPerspectiveProjection( mFovY, mYAspectRatio, mNear,mFar ); 00127 } 00128 00129 /**************************************************************************/ 00130 void cRPerspectiveProjection::init() 00131 { 00132 mFovY = 50.0; 00133 mYAspectRatio = 0.75; 00134 mNear = 1.0; 00135 mFar = 1000.0; 00136 } 00137 00138 00139 } // namespace |