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
00046 #include "OSGConfig.h"
00047 #include "OSGLog.h"
00048
00049 #include <OSGGL.h>
00050
00051 #include "OSGNode.h"
00052 #include "OSGFieldContainerPtr.h"
00053 #include "OSGViewport.h"
00054 #include "OSGWindow.h"
00055 #include "OSGCamera.h"
00056
00057 OSG_USING_NAMESPACE
00058
00059
00060
00061
00062
00063
00072
00073
00074
00075
00076 void Camera::initMethod (void)
00077 {
00078 }
00079
00080
00081
00082
00083
00084 Camera::Camera(void) :
00085 Inherited()
00086 {
00087 }
00088
00089 Camera::Camera(const Camera &source) :
00090 Inherited(source)
00091 {
00092 }
00093
00094 Camera::~Camera(void)
00095 {
00096 }
00097
00098 void Camera::changed(BitVector whichField, UInt32 origin)
00099 {
00100 Inherited::changed(whichField, origin);
00101 }
00102
00103
00104
00105
00109 void Camera::setup( DrawActionBase *OSG_CHECK_ARG(action),
00110 const Viewport &port )
00111 {
00112 Matrix m, t;
00113
00114
00115
00116 getProjection ( m, port.getPixelWidth(), port.getPixelHeight() );
00117 getProjectionTranslation( t, port.getPixelWidth(), port.getPixelHeight() );
00118
00119 m.mult(t);
00120
00121
00122
00123 glMatrixMode( GL_PROJECTION );
00124 glLoadMatrixf( m.getValues() );
00125
00126
00127
00128 getViewing( m, port.getPixelWidth(), port.getPixelHeight() );
00129
00130
00131
00132 glMatrixMode( GL_MODELVIEW );
00133 glLoadMatrixf( m.getValues() );
00134 }
00135
00138 void Camera::setupProjection( DrawActionBase *OSG_CHECK_ARG(action),
00139 const Viewport &port )
00140 {
00141 Matrix m, t;
00142
00143
00144
00145 getProjection ( m, port.getPixelWidth(), port.getPixelHeight() );
00146 getProjectionTranslation( t, port.getPixelWidth(), port.getPixelHeight() );
00147
00148 m.mult(t);
00149
00150
00151
00152 glMatrixMode( GL_PROJECTION );
00153 glLoadMatrixf( m.getValues() );
00154 }
00155
00158 void Camera::draw( DrawAction *OSG_CHECK_ARG(action),
00159 const Viewport &OSG_CHECK_ARG(port ))
00160 {
00161 }
00162
00165 void Camera::getProjection(Matrix &OSG_CHECK_ARG(result),
00166 UInt32 OSG_CHECK_ARG(width ),
00167 UInt32 OSG_CHECK_ARG(height))
00168 {
00169 SFATAL << "Camera::getProjection: NIY" << std::endl;
00170 abort();
00171 }
00172
00176 void Camera::getProjectionTranslation(Matrix &result,
00177 UInt32 OSG_CHECK_ARG(width ),
00178 UInt32 OSG_CHECK_ARG(height))
00179 {
00180 result.setIdentity();
00181 }
00182
00186 void Camera::getViewing(Matrix &result,
00187 UInt32 OSG_CHECK_ARG(width ),
00188 UInt32 OSG_CHECK_ARG(height))
00189 {
00190 if (getBeacon() == NullFC)
00191 {
00192 SWARNING << "Camera::setup: no beacon!" << std::endl;
00193 return;
00194 }
00195
00196 getBeacon()->getToWorld(result);
00197 result.invert();
00198 }
00199
00202 void Camera::getFrustum(FrustumVolume& result, const Viewport& p)
00203 {
00204 Matrix mv,prt,pr;
00205
00206 getProjection (pr , p.getPixelWidth(), p.getPixelHeight());
00207 getProjectionTranslation(prt, p.getPixelWidth(), p.getPixelHeight());
00208 getViewing (mv , p.getPixelWidth(), p.getPixelHeight());
00209
00210 pr.mult(prt);
00211 pr.mult(mv );
00212
00213 result.setPlanes(pr);
00214 }
00215
00218 void Camera::getFrustum(FrustumVolume& result,
00219 UInt32 width, UInt32 height)
00220 {
00221 Matrix mv,prt,pr;
00222
00223 getProjection (pr , width, height);
00224 getProjectionTranslation(prt, width, height);
00225 getViewing (mv , width, height);
00226
00227 pr.mult(prt);
00228 pr.mult(mv );
00229
00230 result.setPlanes(pr);
00231 }
00232
00236 void Camera::getWorldToScreen(Matrix &result, const Viewport& p)
00237 {
00238 Matrix mv,prt,pr;
00239
00240 getProjection (result, p.getPixelWidth(), p.getPixelHeight());
00241 getProjectionTranslation(prt , p.getPixelWidth(), p.getPixelHeight());
00242 getViewing (mv , p.getPixelWidth(), p.getPixelHeight());
00243
00244 result.mult(prt);
00245 result.mult(mv );
00246 }
00247
00250 void Camera::getDecoration(Matrix &result, UInt32 width, UInt32 height)
00251 {
00252 result.setIdentity();
00253 }
00254
00259 bool Camera::calcViewRay(Line & line, Int32 x, Int32 y, const Viewport& port)
00260 {
00261 if(port.getPixelWidth() <= 0 || port.getPixelHeight() <= 0)
00262 {
00263 return false;
00264 }
00265
00266 Matrix proj, projtrans, view;
00267
00268 getProjection(proj, port.getPixelWidth(), port.getPixelHeight());
00269 getProjectionTranslation(projtrans, port.getPixelWidth(),
00270 port.getPixelHeight());
00271 getViewing(view, port.getPixelWidth(), port.getPixelHeight());
00272
00273 Matrix wctocc = proj;
00274 wctocc.mult(projtrans);
00275 wctocc.mult(view);
00276
00277 Matrix cctowc;
00278 cctowc.invertFrom(wctocc);
00279
00280 Real32 rx = (x - port.getPixelLeft()) / (Real32) port.getPixelWidth()
00281 * 2.f - 1.f,
00282 ry = 1.f - ((y - (port.getParent()->getHeight() -
00283 port.getPixelTop())
00284 ) /
00285 (Real32) port.getPixelHeight()
00286 ) * 2.f;
00287
00288 Pnt3f from, at;
00289 cctowc.multFullMatrixPnt(Pnt3f(rx, ry, -1), from);
00290 cctowc.multFullMatrixPnt(Pnt3f(rx, ry, 1), at);
00291
00292 line.setValue(from, at-from);
00293
00294 return true;
00295 }
00296
00297
00298
00299 void Camera::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00300 const BitVector OSG_CHECK_ARG(bvFlags )) const
00301 {
00302 SLOG << "Dump Camera NI" << std::endl;
00303 }
00304
00305
00306
00307
00308
00309 #ifdef OSG_SGI_CC
00310 #pragma set woff 1174
00311 #endif
00312
00313 #ifdef OSG_LINUX_ICC
00314 #pragma warning( disable : 177 )
00315 #endif
00316
00317 namespace
00318 {
00319 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00320 static Char8 cvsid_hpp [] = OSGCAMERA_HEADER_CVSID;
00321 static Char8 cvsid_inl [] = OSGCAMERA_INLINE_CVSID;
00322
00323 static Char8 cvsid_fields_hpp[] = OSGCAMERAFIELDS_HEADER_CVSID;
00324 }
00325
00326 #ifdef __sgi
00327 #pragma reset woff 1174
00328 #endif
00329