OSGOffCenterPerspectiveCamera.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 #include <math.h>
00046
00047 #include "OSGMatrixUtility.h"
00048 #include "OSGOffCenterPerspectiveCamera.h"
00049
00050 OSG_USING_NAMESPACE
00051
00052
00053
00054
00055
00056
00081
00082
00083
00084
00085
00086
00087
00088
00089 void OffCenterPerspectiveCamera::initMethod(InitPhase ePhase)
00090 {
00091 Inherited::initMethod(ePhase);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 OffCenterPerspectiveCamera::OffCenterPerspectiveCamera(void) :
00106 Inherited()
00107 {
00108 }
00109
00110 OffCenterPerspectiveCamera::OffCenterPerspectiveCamera(
00111 const OffCenterPerspectiveCamera &source) :
00112
00113 Inherited(source)
00114 {
00115 }
00116
00117 OffCenterPerspectiveCamera::~OffCenterPerspectiveCamera(void)
00118 {
00119 }
00120
00121 void OffCenterPerspectiveCamera::changed(ConstFieldMaskArg whichField,
00122 UInt32 origin,
00123 BitVector details)
00124 {
00125 Inherited::changed(whichField, origin, details);
00126 }
00127
00128
00129
00130
00131 void OffCenterPerspectiveCamera::getProjection(Matrix &result,
00132 UInt32 width,
00133 UInt32 height)
00134 {
00135 Real32 fov = getFov();
00136
00137
00138 if(fov < 0 || width == 0 || height == 0)
00139 {
00140 result.setIdentity();
00141 return;
00142 }
00143
00144
00145 if(fov > Pi)
00146 fov = osgDegree2Rad(fov);
00147
00148
00149 Real32 rNear = getNear();
00150 Real32 rFar = getFar();
00151 Real32 aspect = Real32(width) / Real32(height) * getAspect();
00152 Real32 ct = osgTan(fov / 2.f);
00153
00154 if(rNear > rFar)
00155 {
00156 SWARNING << "MatrixPerspective: near " << rNear << " > far " << rFar
00157 << "!\n" << std::endl;
00158 result.setIdentity();
00159 return;
00160 }
00161
00162 if(fov <= Eps)
00163 {
00164 SWARNING << "MatrixPerspective: fov " << fov << " very small!\n"
00165 << std::endl;
00166 result.setIdentity();
00167 return;
00168 }
00169
00170 if(osgAbs(rNear - rFar) < Eps)
00171 {
00172 SWARNING << "MatrixPerspective: near " << rNear << " ~= far " << rFar
00173 << "!\n" << std::endl;
00174 result.setIdentity();
00175 return;
00176 }
00177
00178 if(aspect < Eps)
00179 {
00180 SWARNING << "MatrixPerspective: aspect ratio " << aspect
00181 << " very small!\n" << std::endl;
00182 result.setIdentity();
00183 return;
00184 }
00185
00186 Real32 x = ct * rNear;
00187 Real32 y = ct * rNear;
00188 UInt32 fovMode = getFovMode();
00189
00190 switch (fovMode)
00191 {
00192 case VerticalFoV:
00193 x *= aspect;
00194 break;
00195
00196 case HorizontalFoV:
00197 y /= aspect;
00198 break;
00199
00200 case SmallerFoV:
00201 if(width * getAspect() >= height)
00202 {
00203 x *= aspect;
00204 }
00205 else
00206 {
00207 y /= aspect;
00208 }
00209 break;
00210
00211 default:
00212 result.setIdentity();
00213 return;
00214 }
00215
00216 Real32 principalPointX = getPrincipalPoint()[0];
00217 Real32 principalPointY = getPrincipalPoint()[1];
00218
00219
00220
00221 if ((principalPointX == 0.f) && (principalPointY == 0.f))
00222 {
00223 MatrixFrustum( result,
00224 -x,
00225 x,
00226 -y,
00227 y,
00228 rNear,
00229 rFar);
00230 }
00231 else
00232 {
00233 MatrixFrustum( result,
00234 -x * (1.f + principalPointX),
00235 x * (1.f - principalPointX),
00236 -y * (1.f + principalPointY),
00237 y * (1.f - principalPointY),
00238 rNear,
00239 rFar);
00240 }
00241 }
00242
00243
00244
00245
00246 void OffCenterPerspectiveCamera::dump(
00247 UInt32 OSG_CHECK_ARG(uiIndent),
00248 const BitVector OSG_CHECK_ARG(bvFlags)) const
00249 {
00250 SLOG << "Dump OffCenterPerspectiveCamera NI" << std::endl;
00251 }
00252
00253