1 /*---------------------------------------------------------------------------*\
5 * Copyright(C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
47 #include "OSGConfig.h"
49 #include "OSGBaseTypes.h"
51 #include "OSGVector.h"
52 #include "OSGMatrix.h"
53 #include "OSGMatrixUtility.h"
55 #include "OSGWindow.h"
56 #include "OSGViewport.h"
57 #include "OSGCamera.h"
58 #include "OSGWindow.h"
59 #include "OSGBackground.h"
60 #include "OSGPerspectiveCamera.h"
64 // Documentation for this class is emited in the
65 // OSGPerspectiveCameraBase.cpp file.
66 // To modify it, please change the .fcd file (OSGPerspectiveCamera.fcd) and
67 // regenerate the base file.
69 /***************************************************************************\
71 \***************************************************************************/
73 /*-------------------------------------------------------------------------*\
75 \*-------------------------------------------------------------------------*/
77 void PerspectiveCamera::initMethod(InitPhase ePhase
)
79 Inherited::initMethod(ePhase
);
82 /***************************************************************************\
84 \***************************************************************************/
86 /*-------------------------------------------------------------------------*\
88 \*-------------------------------------------------------------------------*/
91 /*------------- constructors & destructors --------------------------------*/
93 PerspectiveCamera::PerspectiveCamera(void) :
98 PerspectiveCamera::PerspectiveCamera(const PerspectiveCamera
&source
) :
103 PerspectiveCamera::~PerspectiveCamera(void)
107 void PerspectiveCamera::changed(ConstFieldMaskArg whichField
,
111 Inherited::changed(whichField
, origin
, details
);
114 /*-------------------------- your_category---------------------------------*/
118 void PerspectiveCamera::getProjection(Matrix
&result
,
122 Real32 fov
= getFov();
124 // catch some illegal cases
126 if(fov
< 0 || width
== 0 || height
== 0)
128 result
.setIdentity();
132 // try to be nice to people giving degrees...
135 fov
= osgDegree2Rad(fov
);
138 Real32 rNear
= getNear();
139 Real32 rFar
= getFar ();
140 Real32 aspect
= Real32(width
) / Real32(height
) * getAspect();
141 Real32 ct
= osgTan(fov
/ 2.f
);
145 SWARNING
<< "MatrixPerspective: near " << rNear
<< " > far " << rFar
146 << "!\n" << std::endl
;
147 result
.setIdentity();
151 if(fov
<= TypeTraits
<Real32
>::getDefaultEps())
153 SWARNING
<< "MatrixPerspective: fov " << fov
<< " very small!\n"
155 result
.setIdentity();
159 if(osgAbs(rNear
- rFar
) < TypeTraits
<Real32
>::getDefaultEps())
161 SWARNING
<< "MatrixPerspective: near " << rNear
<< " ~= far " << rFar
162 << "!\n" << std::endl
;
163 result
.setIdentity();
167 if(aspect
< TypeTraits
<Real32
>::getDefaultEps())
169 SWARNING
<< "MatrixPerspective: aspect ratio " << aspect
170 << " very small!\n" << std::endl
;
171 result
.setIdentity();
175 Real32 x
= ct
* rNear
;
176 Real32 y
= ct
* rNear
;
178 UInt32 fovMode
= getFovMode();
191 if(width
* getAspect() >= height
)
202 result
.setIdentity();
206 MatrixFrustum( result
,
217 /*------------------------------- dump ----------------------------------*/
219 void PerspectiveCamera::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
220 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
222 SLOG
<< "Dump PerspectiveCamera NI" << std::endl
;