OSGScreenGroup.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
00046 #include <OSGConfig.h>
00047
00048 #include "OSGScreenGroup.h"
00049 #include "OSGIntersectAction.h"
00050 #include "OSGRenderAction.h"
00051 #include "OSGViewport.h"
00052 #include "OSGCamera.h"
00053
00054 OSG_BEGIN_NAMESPACE
00055
00056
00057
00058
00059
00063
00064
00065
00066
00067
00068
00069
00070
00071 void ScreenGroup::initMethod(InitPhase ePhase)
00072 {
00073 Inherited::initMethod(ePhase);
00074
00075 if(ePhase == TypeObject::SystemPost)
00076 {
00077 IntersectAction::registerEnterDefault(
00078 ScreenGroup::getClassType(),
00079 reinterpret_cast<Action::Callback>(&ScreenGroup::intersectEnter));
00080
00081 IntersectAction::registerLeaveDefault(
00082 ScreenGroup::getClassType(),
00083 reinterpret_cast<Action::Callback>(&ScreenGroup::intersectLeave));
00084
00085 RenderAction::registerEnterDefault(
00086 ScreenGroup::getClassType(),
00087 reinterpret_cast<Action::Callback>(&ScreenGroup::renderEnter));
00088
00089 RenderAction::registerLeaveDefault(
00090 ScreenGroup::getClassType(),
00091 reinterpret_cast<Action::Callback>(&ScreenGroup::renderLeave));
00092 }
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 ScreenGroup::ScreenGroup(void) :
00107 Inherited()
00108 {
00109 }
00110
00111 ScreenGroup::ScreenGroup(const ScreenGroup &source) :
00112 Inherited(source)
00113 {
00114 }
00115
00116 ScreenGroup::~ScreenGroup(void)
00117 {
00118 }
00119
00120
00121
00122 void ScreenGroup::changed(BitVector whichField,
00123 UInt32 origin,
00124 BitVector details)
00125 {
00126 Inherited::changed(whichField, origin, details);
00127 }
00128
00129 void ScreenGroup::dump( UInt32 ,
00130 const BitVector ) const
00131 {
00132 SLOG << "Dump ScreenGroup NI" << std::endl;
00133 }
00134
00135
00136
00137
00138 void ScreenGroup::adjustVolume(Volume &volume)
00139 {
00140 volume.transform(_camTransform);
00141 }
00142
00143 void ScreenGroup::accumulateMatrix(Matrix &result)
00144 {
00145 result.mult(_camTransform);
00146 }
00147
00148 void ScreenGroup::calcMatrix( RenderAction *pAction,
00149 const Matrix &mToWorld,
00150 Matrix &mResult )
00151 {
00152 const DrawEnv &oEnv = pAction->getActivePartition()->getDrawEnv();
00153
00154 Matrix mToScreen = oEnv.getVPWorldToScreen();
00155
00156 #if 0
00157 Viewport *viewport = pAction->getViewport();
00158 pAction->getCamera()->getWorldToScreen(mToScreen, *viewport);
00159 #endif
00160
00161 mToScreen.mult(mToWorld);
00162
00163 Pnt3f origin(0.f, 0.f, 0.f);
00164
00165 mToScreen.multFull(origin, origin);
00166
00167 Pnt3f xAxis(1.f, 0.f, 0.f);
00168
00169 mToScreen.multFull(xAxis, xAxis);
00170
00171 Real32 scaleX =
00172 2.f / oEnv.getPixelWidth() / (xAxis - origin).length();
00173
00174 Pnt3f yAxis(0.f, 1.f, 0.f);
00175
00176 mToScreen.multFull(yAxis, yAxis);
00177
00178 Real32 scaleY =
00179 2.f / oEnv.getPixelHeight() / (yAxis - origin).length();
00180
00181 mResult.setScale (scaleX, scaleY, 1.f);
00182 mResult.setTranslate(0.375 * scaleX, 0.375 * scaleY, 0.f);
00183
00184 bool equal = mResult.equals(_camTransform, 0.00001f);
00185
00186 _camTransform = mResult;
00187
00188 if(!equal)
00189 this->invalidateVolume();
00190 }
00191
00192
00193
00194
00195 Action::ResultE ScreenGroup::intersectEnter(Action *action)
00196 {
00197 #if 0
00198 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00199 Matrix m(_camTransform);
00200
00201 m.invert();
00202
00203 Pnt3f pos;
00204 Vec3f dir;
00205
00206 #ifndef OSG_2_PREP
00207 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00208 m.multMatrixVec (ia->getLine().getDirection(), dir);
00209 #else
00210 m.multFull(ia->getLine().getPosition (), pos);
00211 m.mult (ia->getLine().getDirection(), dir);
00212 #endif
00213
00214 ia->setLine(Line(pos, dir), ia->getMaxDist());
00215 ia->scale(dir.length());
00216 #endif
00217
00218 return Action::Continue;
00219 }
00220
00221 Action::ResultE ScreenGroup::intersectLeave(Action *action)
00222 {
00223 #if 0
00224 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00225 Matrix m(_camTransform);
00226
00227 Pnt3f pos;
00228 Vec3f dir;
00229
00230 #ifndef OSG_2_PREP
00231 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00232 m.multMatrixVec (ia->getLine().getDirection(), dir);
00233 #else
00234 m.multFull(ia->getLine().getPosition (), pos);
00235 m.mult (ia->getLine().getDirection(), dir);
00236 #endif
00237
00238 ia->setLine(Line(pos, dir), ia->getMaxDist());
00239 ia->scale(dir.length());
00240 #endif
00241
00242 return Action::Continue;
00243 }
00244
00245
00246
00247
00248 Action::ResultE ScreenGroup::renderEnter(Action *action)
00249 {
00250 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00251
00252 Matrix mMat;
00253
00254 #if 0
00255 if(!pAction->getEffectsPass())
00256 calcMatrix(pAction, pAction->top_matrix(), mMat);
00257 else
00258 mMat = _camTransform;
00259 #else
00260 calcMatrix(pAction, pAction->topMatrix(), mMat);
00261 #endif
00262
00263 pAction->pushMatrix(mMat);
00264
00265
00266
00267
00268 return Action::Continue;
00269 }
00270
00271 Action::ResultE ScreenGroup::renderLeave(Action *action)
00272 {
00273 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00274
00275 pAction->popMatrix();
00276
00277 return Action::Continue;
00278 }
00279
00280 OSG_END_NAMESPACE
00281