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
00219 void Camera::getWorldToScreen(Matrix &result, const Viewport& p)
00220 {
00221 Matrix mv,prt,pr;
00222
00223 getProjection (result, p.getPixelWidth(), p.getPixelHeight());
00224 getProjectionTranslation(prt , p.getPixelWidth(), p.getPixelHeight());
00225 getViewing (mv , p.getPixelWidth(), p.getPixelHeight());
00226
00227 result.mult(prt);
00228 result.mult(mv );
00229 }
00230
00235 bool Camera::calcViewRay(Line & line, Int32 x, Int32 y, const Viewport& port)
00236 {
00237 if(port.getPixelWidth() <= 0 || port.getPixelHeight() <= 0)
00238 {
00239 return false;
00240 }
00241
00242 Matrix proj, projtrans, view;
00243
00244 getProjection(proj, port.getPixelWidth(), port.getPixelHeight());
00245 getProjectionTranslation(projtrans, port.getPixelWidth(),
00246 port.getPixelHeight());
00247 getViewing(view, port.getPixelWidth(), port.getPixelHeight());
00248
00249 Matrix wctocc = proj;
00250 wctocc.mult(projtrans);
00251 wctocc.mult(view);
00252
00253 Matrix cctowc;
00254 cctowc.invertFrom(wctocc);
00255
00256 Real32 rx = (x - port.getPixelLeft()) / (Real32) port.getPixelWidth()
00257 * 2.f - 1.f,
00258 ry = 1.f - ((y - (port.getParent()->getHeight() -
00259 port.getPixelTop())
00260 ) /
00261 (Real32) port.getPixelHeight()
00262 ) * 2.f;
00263
00264 view.invert();
00265 Pnt3f from(view[3][0], view[3][1], view[3][2]);
00266
00267 Pnt3f at;
00268 cctowc.multFullMatrixPnt(Pnt3f(rx, ry, 1), at);
00269
00270 line.setValue(from, at-from);
00271
00272 return true;
00273 }
00274
00275
00276
00277 void Camera::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00278 const BitVector OSG_CHECK_ARG(bvFlags )) const
00279 {
00280 SLOG << "Dump Camera NI" << std::endl;
00281 }
00282
00283
00284
00285
00286
00287 #ifdef OSG_SGI_CC
00288 #pragma set woff 1174
00289 #endif
00290
00291 #ifdef OSG_LINUX_ICC
00292 #pragma warning( disable : 177 )
00293 #endif
00294
00295 namespace
00296 {
00297 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00298 static Char8 cvsid_hpp [] = OSGCAMERA_HEADER_CVSID;
00299 static Char8 cvsid_inl [] = OSGCAMERA_INLINE_CVSID;
00300
00301 static Char8 cvsid_fields_hpp[] = OSGCAMERAFIELDS_HEADER_CVSID;
00302 }
00303
00304 #ifdef __sgi
00305 #pragma reset woff 1174
00306 #endif
00307