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