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
00048 #include "OSGScreenGroup.h"
00049 #include "OSGDrawAction.h"
00050 #include "OSGIntersectAction.h"
00051 #include "OSGRenderAction.h"
00052 #include "OSGViewport.h"
00053 #include "OSGCamera.h"
00054
00055 OSG_BEGIN_NAMESPACE
00056
00057
00058
00059
00060
00065
00066
00067
00068
00069
00070
00071
00072
00073 void ScreenGroup::initMethod (void)
00074 {
00075 DrawAction::registerEnterDefault(
00076 getClassType(),
00077 osgTypedMethodFunctor2BaseCPtrRef<
00078 Action::ResultE,
00079 ScreenGroupPtr ,
00080 CNodePtr ,
00081 Action *>(&ScreenGroup::drawEnter));
00082
00083 DrawAction::registerLeaveDefault(
00084 getClassType(),
00085 osgTypedMethodFunctor2BaseCPtrRef<
00086 Action::ResultE,
00087 ScreenGroupPtr ,
00088 CNodePtr ,
00089 Action *>(&ScreenGroup::drawLeave));
00090
00091
00092 IntersectAction::registerEnterDefault(
00093 getClassType(),
00094 osgTypedMethodFunctor2BaseCPtrRef<
00095 Action::ResultE,
00096 ScreenGroupPtr ,
00097 CNodePtr ,
00098 Action *>(&ScreenGroup::intersectEnter));
00099
00100 IntersectAction::registerLeaveDefault(
00101 getClassType(),
00102 osgTypedMethodFunctor2BaseCPtrRef<
00103 Action::ResultE,
00104 ScreenGroupPtr ,
00105 CNodePtr ,
00106 Action *>(&ScreenGroup::intersectLeave));
00107
00108
00109 RenderAction::registerEnterDefault(
00110 getClassType(),
00111 osgTypedMethodFunctor2BaseCPtrRef<
00112 Action::ResultE,
00113 ScreenGroupPtr ,
00114 CNodePtr ,
00115 Action *>(&ScreenGroup::renderEnter));
00116
00117 RenderAction::registerLeaveDefault(
00118 getClassType(),
00119 osgTypedMethodFunctor2BaseCPtrRef<
00120 Action::ResultE,
00121 ScreenGroupPtr ,
00122 CNodePtr ,
00123 Action *>(&ScreenGroup::renderLeave));
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 ScreenGroup::ScreenGroup(void) :
00138 Inherited()
00139 {
00140 }
00141
00142 ScreenGroup::ScreenGroup(const ScreenGroup &source) :
00143 Inherited(source)
00144 {
00145 }
00146
00147 ScreenGroup::~ScreenGroup(void)
00148 {
00149 }
00150
00151
00152
00153 void ScreenGroup::changed(BitVector whichField, UInt32 origin)
00154 {
00155 Inherited::changed(whichField, origin);
00156 }
00157
00158 void ScreenGroup::dump( UInt32 ,
00159 const BitVector ) const
00160 {
00161 SLOG << "Dump ScreenGroup NI" << std::endl;
00162 }
00163
00164
00165
00166
00167 void ScreenGroup::adjustVolume( Volume & volume )
00168 {
00169 Matrix m;
00170 m.setScale(0, 0, 1);
00171 volume.transform(m);
00172 }
00173
00174 void ScreenGroup::accumulateMatrix(Matrix &result)
00175 {
00176 result.mult(_camTransform);
00177 }
00178
00179 void ScreenGroup::calcMatrix( DrawActionBase *pAction,
00180 const Matrix &mToWorld,
00181 Matrix &mResult)
00182 {
00183 Viewport *viewport = pAction->getViewport();
00184 Matrix mToScreen;
00185 pAction->getCamera()->getWorldToScreen(mToScreen, *viewport);
00186 mToScreen.mult(mToWorld);
00187
00188 Pnt3f origin(0.f, 0.f, 0.f);
00189 mToScreen.multFullMatrixPnt(origin);
00190
00191 Pnt3f xAxis(1.f, 0.f, 0.f);
00192 mToScreen.multFullMatrixPnt(xAxis);
00193 Real32 scaleX = 2.f / viewport->getPixelWidth() / (xAxis - origin).length();
00194
00195 Pnt3f yAxis(0.f, 1.f, 0.f);
00196 mToScreen.multFullMatrixPnt(yAxis);
00197 Real32 scaleY = 2.f / viewport->getPixelHeight() / (yAxis - origin).length();
00198
00199 mResult.setScale(scaleX, scaleY, 1.f);
00200 mResult.setTranslate(0.375 * scaleX, 0.375 * scaleY, 0.f);
00201 _camTransform = mResult;
00202 }
00203
00204
00205
00206
00207 Action::ResultE ScreenGroup::drawEnter(Action *action)
00208 {
00209 DrawAction *da = dynamic_cast<DrawAction *>(action);
00210
00211 Matrix mMat;
00212
00213 calcMatrix(da,
00214 da->getActNode()->getToWorld(),
00215 mMat);
00216
00217
00218 glPushMatrix ();
00219 glMultMatrixf(mMat.getValues());
00220
00221
00222
00223
00224 return Action::Continue;
00225 }
00226
00227 Action::ResultE ScreenGroup::drawLeave(Action *)
00228 {
00229 glPopMatrix();
00230
00231 return Action::Continue;
00232 }
00233
00234
00235
00236
00237 Action::ResultE ScreenGroup::intersectEnter(Action *action)
00238 {
00239 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00240 Matrix m(_camTransform);
00241
00242 m.invert();
00243
00244 Pnt3f pos;
00245 Vec3f dir;
00246
00247 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00248 m.multMatrixVec (ia->getLine().getDirection(), dir);
00249
00250 ia->setLine(Line(pos, dir), ia->getMaxDist());
00251 ia->scale(dir.length());
00252
00253 return Action::Continue;
00254 }
00255
00256 Action::ResultE ScreenGroup::intersectLeave(Action *action)
00257 {
00258 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00259 Matrix m(_camTransform);
00260
00261 Pnt3f pos;
00262 Vec3f dir;
00263
00264 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00265 m.multMatrixVec (ia->getLine().getDirection(), dir);
00266
00267 ia->setLine(Line(pos, dir), ia->getMaxDist());
00268 ia->scale(dir.length());
00269
00270 return Action::Continue;
00271 }
00272
00273
00274
00275
00276 Action::ResultE ScreenGroup::renderEnter(Action *action)
00277 {
00278 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00279
00280 Matrix mMat;
00281
00282 calcMatrix(pAction, pAction->top_matrix(), mMat);
00283
00284 pAction->push_matrix(mMat);
00285
00286
00287
00288
00289 return Action::Continue;
00290 }
00291
00292 Action::ResultE ScreenGroup::renderLeave(Action *action)
00293 {
00294 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00295
00296 pAction->pop_matrix();
00297
00298 return Action::Continue;
00299 }
00300
00301
00302
00303
00304
00305 #ifdef OSG_SGI_CC
00306 #pragma set woff 1174
00307 #endif
00308
00309 #ifdef OSG_LINUX_ICC
00310 #pragma warning( disable : 177 )
00311 #endif
00312
00313 namespace
00314 {
00315 static Char8 cvsid_cpp [] = "@(#)$Id: OSGScreenGroup.cpp,v 1.1 2007/05/07 11:50:36 pdaehne Exp $";
00316 static Char8 cvsid_hpp [] = OSGSCREENGROUPBASE_HEADER_CVSID;
00317 static Char8 cvsid_inl [] = OSGSCREENGROUPBASE_INLINE_CVSID;
00318
00319 static Char8 cvsid_fields_hpp[] = OSGSCREENGROUPFIELDS_HEADER_CVSID;
00320 }
00321
00322 #ifdef __sgi
00323 #pragma reset woff 1174
00324 #endif
00325
00326 OSG_END_NAMESPACE
00327