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 "OSGConfig.h"
00048
00049 #include <OSGBaseFunctions.h>
00050 #include <OSGBaseTypes.h>
00051 #include <OSGLog.h>
00052 #include <OSGVector.h>
00053 #include <OSGMatrix.h>
00054 #include <OSGMatrixUtility.h>
00055
00056 #include "OSGNodePtr.h"
00057 #include "OSGViewport.h"
00058 #include "OSGCamera.h"
00059 #include "OSGWindow.h"
00060 #include "OSGBackground.h"
00061 #include "OSGOffCenterPerspectiveCamera.h"
00062
00063 OSG_USING_NAMESPACE
00064
00065
00066
00067
00068
00069
00094
00095
00096
00097
00098
00099
00100
00101
00102 void OffCenterPerspectiveCamera::initMethod(void)
00103 {
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 OffCenterPerspectiveCamera::OffCenterPerspectiveCamera(void) :
00118 Inherited()
00119 {
00120 }
00121
00122 OffCenterPerspectiveCamera::
00123 OffCenterPerspectiveCamera(const OffCenterPerspectiveCamera &source) :
00124 Inherited(source)
00125 {
00126 }
00127
00128 OffCenterPerspectiveCamera::~OffCenterPerspectiveCamera(void)
00129 {
00130 }
00131
00132 void OffCenterPerspectiveCamera::changed(BitVector whichField, UInt32 origin)
00133 {
00134 Inherited::changed(whichField, origin);
00135 }
00136
00137
00138
00139 void OffCenterPerspectiveCamera::draw( DrawAction *OSG_CHECK_ARG(action),
00140 const Viewport& OSG_CHECK_ARG(port ))
00141 {
00142 }
00143
00144 bool OffCenterPerspectiveCamera::
00145 MatrixPerspectivePrincipalPnt(Matrix &result,
00146 Real32 rFovy,
00147 Real32 rAspect,
00148 Real32 rNear,
00149 Real32 rFar,
00150 Real32 rPrincipalPointX,
00151 Real32 rPrincipalPointY)
00152 {
00153 Real32 ct = osgtan(rFovy);
00154 bool error = false;
00155
00156 if(rNear > rFar)
00157 {
00158 SWARNING << "MatrixPerspective: near " << rNear << " > far " << rFar
00159 << "!\n" << std::endl;
00160 error = true;
00161 }
00162
00163 if(rFovy <= Eps)
00164 {
00165 SWARNING << "MatrixPerspective: fovy " << rFovy << " very small!\n"
00166 << std::endl;
00167 error = true;
00168 }
00169
00170 if(osgabs(rNear - rFar) < Eps)
00171 {
00172 SWARNING << "MatrixPerspective: near " << rNear << " ~= far " << rFar
00173 << "!\n" << std::endl;
00174 error = true;
00175 }
00176
00177 if(rAspect < Eps)
00178 {
00179 SWARNING << "MatrixPerspective: aspect ratio " << rAspect
00180 << " very small!\n" << std::endl;
00181 error = true;
00182 }
00183
00184 if(error)
00185 {
00186 result.setIdentity();
00187 return true;
00188 }
00189
00190 MatrixFrustum( result,
00191 -rNear * ct * rAspect * (Real32(1)+rPrincipalPointX),
00192 rNear * ct * rAspect * (Real32(1)-rPrincipalPointX),
00193 -rNear * ct * (Real32(1)+rPrincipalPointY),
00194 rNear * ct * (Real32(1)-rPrincipalPointY),
00195 rNear,
00196 rFar );
00197
00198 return false;
00199 }
00200
00201 void OffCenterPerspectiveCamera::getProjection(Matrix& result,
00202 UInt32 width, UInt32 height)
00203 {
00204 Real32 fov = getFov();
00205
00206
00207 if(fov < 0 || width == 0 || height == 0)
00208 {
00209 result.setIdentity();
00210 return;
00211 }
00212
00213
00214 if(fov > Pi)
00215 fov = osgdegree2rad(fov);
00216
00217 Real32 principalPointX = getPrincipalPoint()[0];
00218 Real32 principalPointY = getPrincipalPoint()[1];
00219
00220
00221
00222 if ( principalPointX==Real32(0) && principalPointY==Real32(0) ) {
00223 MatrixPerspective(result, fov / 2,
00224 width /(Real32) height * getAspect(),
00225 getNear(), getFar());
00226 }
00227 else {
00228 MatrixPerspectivePrincipalPnt(result, fov / 2,
00229 width /(Real32) height * getAspect(),
00230 getNear(), getFar(),
00231 principalPointX, principalPointY);
00232 }
00233 }
00234
00235
00236
00237
00238 void OffCenterPerspectiveCamera::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00239 const BitVector OSG_CHECK_ARG(bvFlags)) const
00240 {
00241 SLOG << "Dump OffCenterPerspectiveCamera NI" << std::endl;
00242 }
00243
00244
00245
00246
00247
00248
00249 #ifdef OSG_SGI_CC
00250 #pragma set woff 1174
00251 #endif
00252
00253 #ifdef OSG_LINUX_ICC
00254 #pragma warning(disable : 177)
00255 #endif
00256
00257 namespace
00258 {
00259 static Char8 cvsid_cpp [] = "@(#)$Id: OSGOffCenterPerspectiveCamera.cpp,v 1.1 2005/07/18 18:46:23 dirk Exp $";
00260 static Char8 cvsid_hpp [] = OSGOFFCENTERPERSPECTIVECAMERA_HEADER_CVSID;
00261 static Char8 cvsid_inl [] = OSGOFFCENTERPERSPECTIVECAMERA_INLINE_CVSID;
00262
00263 static Char8 cvsid_fields_hpp[] = OSGOFFCENTERPERSPECTIVECAMERAFIELDS_HEADER_CVSID;
00264 }
00265
00266 #ifdef __sgi
00267 #pragma reset woff 1174
00268 #endif
00269