OSGInverseTransform.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 <cstdlib>
00044 #include <cstdio>
00045
00046 #include "OSGConfig.h"
00047 #include "OSGGL.h"
00048
00049 #include "OSGInverseTransform.h"
00050 #ifndef OSG_EMBEDDED
00051 #include "OSGIntersectAction.h"
00052 #endif
00053 #include "OSGRenderAction.h"
00054 #include "OSGNode.h"
00055
00056 OSG_USING_NAMESPACE
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 void InverseTransform::initMethod(InitPhase ePhase)
00072 {
00073 Inherited::initMethod(ePhase);
00074
00075 if(ePhase == TypeObject::SystemPost)
00076 {
00077 #ifndef OSG_EMBEDDED
00078 IntersectAction::registerEnterDefault(
00079 getClassType(),
00080 reinterpret_cast<Action::Callback>(
00081 &InverseTransform::intersectEnter));
00082
00083 IntersectAction::registerLeaveDefault(
00084 getClassType(),
00085 reinterpret_cast<Action::Callback>(
00086 &InverseTransform::intersectLeave));
00087 #endif
00088
00089 RenderAction::registerEnterDefault(
00090 InverseTransform::getClassType(),
00091 reinterpret_cast<Action::Callback>(&InverseTransform::renderEnter));
00092
00093 RenderAction::registerLeaveDefault(
00094 InverseTransform::getClassType(),
00095 reinterpret_cast<Action::Callback>(&InverseTransform::renderLeave));
00096 }
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 InverseTransform::InverseTransform(void) :
00111 Inherited(),
00112 _invWorld ()
00113 {
00114 }
00115
00116 InverseTransform::InverseTransform(const InverseTransform &source) :
00117 Inherited(source ),
00118 _invWorld (source._invWorld)
00119 {
00120 }
00121
00122 InverseTransform::~InverseTransform(void)
00123 {
00124 }
00125
00126
00127
00128 void InverseTransform::changed(ConstFieldMaskArg whichField,
00129 UInt32 origin,
00130 BitVector details)
00131 {
00132 Inherited::changed(whichField, origin, details);
00133 }
00134
00135 void InverseTransform::dump( UInt32 uiIndent,
00136 const BitVector bvFlags ) const
00137 {
00138 Inherited::dump(uiIndent, bvFlags);
00139 }
00140
00141
00142
00143 void InverseTransform::adjustVolume(Volume &volume)
00144 {
00145 volume.transform(_invWorld);
00146 }
00147
00148 void InverseTransform::accumulateMatrix(Matrixr &result)
00149 {
00150 result.mult(_invWorld);
00151 }
00152
00153
00154
00155 void InverseTransform::calcMatrix(const Matrixr &mToWorld,
00156 Matrixr &mResult)
00157 {
00158 mResult.invertFrom(mToWorld);
00159
00160 _invWorld = mResult;
00161 }
00162
00163 void InverseTransform::initMatrix(const Matrixr &mToWorld)
00164 {
00165 _invWorld.invertFrom(mToWorld);
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 #ifndef OSG_EMBEDDED
00175 Action::ResultE InverseTransform::intersectEnter(Action *action)
00176 {
00177 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00178 Matrix m(_invWorld);
00179
00180 m.invert();
00181
00182 Pnt3f pos;
00183 Vec3f dir;
00184
00185 m.multFull(ia->getLine().getPosition (), pos);
00186 m.mult (ia->getLine().getDirection(), dir);
00187
00188 ia->setLine(Line(pos, dir), ia->getMaxDist());
00189 ia->scale(dir.length());
00190
00191 return Action::Continue;
00192 }
00193
00194 Action::ResultE InverseTransform::intersectLeave(Action *action)
00195 {
00196 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00197 Matrix m(_invWorld);
00198
00199 Pnt3f pos;
00200 Vec3f dir;
00201
00202 m.multFull(ia->getLine().getPosition (), pos);
00203 m.mult (ia->getLine().getDirection(), dir);
00204
00205 ia->setLine(Line(pos, dir), ia->getMaxDist());
00206 ia->scale(dir.length());
00207
00208 return Action::Continue;
00209 }
00210 #endif
00211
00212
00213
00214
00215 #ifdef OSG_OLD_RENDER_ACTION
00216 Action::ResultE InverseTransform::renderEnter(Action *action)
00217 {
00218 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00219 Matrixr mMat;
00220
00221 calcMatrix(pAction, pAction->top_matrix(), mMat);
00222
00223 pAction->push_matrix(mMat);
00224
00225 return Action::Continue;
00226 }
00227
00228 Action::ResultE InverseTransform::renderLeave(Action *action)
00229 {
00230 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00231
00232 pAction->pop_matrix();
00233
00234 return Action::Continue;
00235 }
00236 #endif
00237
00238 Action::ResultE InverseTransform::renderEnter(Action *action)
00239 {
00240 RenderAction *pAction =
00241 dynamic_cast<RenderAction *>(action);
00242
00243 Matrixr mMat;
00244
00245 calcMatrix(pAction->topMatrix(), mMat);
00246
00247 pAction->pushVisibility();
00248
00249 pAction->pushMatrix(mMat);
00250
00251 return Action::Continue;
00252 }
00253
00254 Action::ResultE InverseTransform::renderLeave(Action *action)
00255 {
00256 RenderAction *pAction =
00257 dynamic_cast<RenderAction *>(action);
00258
00259 pAction->popVisibility();
00260
00261 pAction->popMatrix();
00262
00263 return Action::Continue;
00264 }