OSGDoubleTransform.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
00048 #include "OSGGL.h"
00049
00050 #ifndef OSG_EMBEDDED
00051 #include "OSGIntersectAction.h"
00052 #endif
00053
00054 #include "OSGRenderAction.h"
00055
00056 #ifdef OSG_HAVE_ACTION //CHECK
00057 #include "OSGIntersectActor.h"
00058 #endif
00059
00060 #include "OSGDoubleTransform.h"
00061 #include "OSGVolume.h"
00062
00063 OSG_BEGIN_NAMESPACE
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 void DoubleTransform::changed(ConstFieldMaskArg whichField,
00074 UInt32 origin,
00075 BitVector details)
00076 {
00077 if(whichField & MatrixFieldMask)
00078 {
00079 invalidateVolume();
00080 }
00081
00082 Inherited::changed(whichField, origin, details);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 void DoubleTransform::accumulateMatrix(Matrixr &result)
00100 {
00101 result.mult(getMatrix());
00102 }
00103
00104 void DoubleTransform::adjustVolume(Volume &volume)
00105 {
00106 Matrix4f temp;
00107 temp.convertFrom(_sfMatrix.getValue());
00108 volume.transform(temp);
00109 }
00110
00111 void DoubleTransform::dump( UInt32 uiIndent,
00112 const BitVector bvFlags ) const
00113 {
00114 Inherited::dump(uiIndent, bvFlags);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 DoubleTransform::DoubleTransform(void) :
00124 Inherited()
00125 {
00126 _sfMatrix.getValue().setIdentity();
00127 }
00128
00129 DoubleTransform::DoubleTransform(const DoubleTransform &source) :
00130 Inherited(source)
00131 {
00132 }
00133
00134 DoubleTransform::~DoubleTransform(void)
00135 {
00136 }
00137
00138
00139
00140
00141 ActionBase::ResultE DoubleTransform::renderEnter(Action *action)
00142 {
00143 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00144
00145 pAction->pushVisibility();
00146
00147 pAction->pushMatrix(this->getMatrix());
00148
00149 return ActionBase::Continue;
00150 }
00151
00152 ActionBase::ResultE DoubleTransform::renderLeave(Action *action)
00153 {
00154 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00155
00156 pAction->popVisibility();
00157
00158 pAction->popMatrix();
00159
00160 return ActionBase::Continue;
00161 }
00162
00163
00164
00165
00166 #ifndef OSG_EMBEDDED
00167 ActionBase::ResultE DoubleTransform::intersectEnter(Action *action)
00168 {
00169 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00170 Matrix4d matd = this->getMatrix();
00171
00172 matd.invert();
00173
00174 Matrix4f m;
00175 m.convertFrom(matd);
00176
00177 Pnt3f pos;
00178 Vec3f dir;
00179
00180 m.multFull(ia->getLine().getPosition (), pos);
00181 m.mult (ia->getLine().getDirection(), dir);
00182
00183 ia->setLine(Line(pos, dir), ia->getMaxDist());
00184 ia->scale(dir.length());
00185
00186 return ActionBase::Continue;
00187 }
00188
00189 ActionBase::ResultE DoubleTransform::intersectLeave(Action *action)
00190 {
00191 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00192 Matrix4d matd = this->getMatrix();
00193
00194 Matrix4f m;
00195 m.convertFrom(matd);
00196
00197 Pnt3f pos;
00198 Vec3f dir;
00199
00200 m.multFull(ia->getLine().getPosition (), pos);
00201 m.mult (ia->getLine().getDirection(), dir);
00202
00203 ia->setLine(Line(pos, dir), ia->getMaxDist());
00204 ia->scale(dir.length());
00205
00206 return ActionBase::Continue;
00207 }
00208 #endif
00209
00210 #ifdef OSG_HAVE_ACTION //CHECK
00211 NewActionTypes::ResultE Transform::intersectActorEnter(
00212 ActorBase::FunctorArgumentType &funcArg)
00213 {
00214 IntersectActor *pIA = dynamic_cast<IntersectActor *>(
00215 funcArg.getActor());
00216 Matrix matrix = this->getMatrix();
00217 Line transLine;
00218 Pnt3f pos;
00219 Vec3f dir;
00220
00221 matrix.invert();
00222
00223 matrix.multFullMatrixPnt(pIA->getRay().getPosition (), pos);
00224 matrix.multMatrixVec (pIA->getRay().getDirection(), dir);
00225
00226 transLine.setValue(pos, dir);
00227
00228 pIA->beginEditState();
00229 {
00230 pIA->setRay (transLine );
00231 pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
00232 }
00233 pIA->endEditState ();
00234
00235 pIA->setupChildrenPriorities();
00236
00237 return NewActionTypes::Continue;
00238 }
00239
00240 NewActionTypes::ResultE Transform::intersectActorLeave(
00241 ActorBase::FunctorArgumentType &funcArg)
00242 {
00243 IntersectActor *pIA = dynamic_cast<IntersectActor *>(
00244 funcArg.getActor());
00245 const Matrix &matrix = this->getMatrix();
00246 Pnt3f pos;
00247 Vec3f dir;
00248
00249 matrix.multFullMatrixPnt(pIA->getRay().getPosition (), pos);
00250 matrix.multMatrixVec (pIA->getRay().getDirection(), dir);
00251
00252 pIA->beginEditState();
00253 {
00254 pIA->setRay (Line(pos, dir) );
00255 pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
00256 }
00257 pIA->endEditState ();
00258
00259 return NewActionTypes::Continue;
00260 }
00261 #endif
00262
00263
00264
00265
00266 void DoubleTransform::initMethod(InitPhase ePhase)
00267 {
00268 Inherited::initMethod(ePhase);
00269
00270 if(ePhase == TypeObject::SystemPost)
00271 {
00272 #ifndef OSG_EMBEDDED
00273 IntersectAction::registerEnterDefault(
00274 getClassType(),
00275 reinterpret_cast<Action::Callback>(&DoubleTransform::intersectEnter));
00276
00277 IntersectAction::registerLeaveDefault(
00278 getClassType(),
00279 reinterpret_cast<Action::Callback>(&DoubleTransform::intersectLeave));
00280 #endif
00281
00282 RenderAction::registerEnterDefault(
00283 getClassType(),
00284 reinterpret_cast<Action::Callback>(&DoubleTransform::renderEnter));
00285
00286 RenderAction::registerLeaveDefault(
00287 getClassType(),
00288 reinterpret_cast<Action::Callback>(&DoubleTransform::renderLeave));
00289
00290 #ifdef OSG_HAVE_ACTION //CHECK
00291 IntersectActor::regClassEnter(
00292 osgTypedMethodFunctor2BaseCPtr<
00293 NewActionTypes::ResultE,
00294 TransformPtr ,
00295 NodeCorePtr ,
00296 ActorBase::FunctorArgumentType &>(&DoubleTransform::intersectActorEnter),
00297 getClassType());
00298
00299 IntersectActor::regClassLeave(
00300 osgTypedMethodFunctor2BaseCPtr<
00301 NewActionTypes::ResultE,
00302 TransformPtr ,
00303 NodeCorePtr ,
00304 ActorBase::FunctorArgumentType &>(&DoubleTransform::intersectActorLeave),
00305 getClassType());
00306 #endif
00307 }
00308 }
00309
00310
00311 OSG_END_NAMESPACE