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 <stdlib.h>
00040 #include <stdio.h>
00041
00042 #include "OSGConfig.h"
00043
00044 #include <OSGGL.h>
00045
00046 #include <OSGDrawAction.h>
00047 #include <OSGIntersectAction.h>
00048 #include <OSGRenderAction.h>
00049
00050 #include <OSGIntersectActor.h>
00051
00052 #include "OSGTransform.h"
00053
00054 OSG_USING_NAMESPACE
00055
00063
00064
00065
00066 void Transform::changed(BitVector whichField, UInt32 origin)
00067 {
00068 if(whichField & MatrixFieldMask)
00069 {
00070 invalidateVolume();
00071 }
00072
00073 Inherited::changed(whichField, origin);
00074 }
00075
00076
00077
00078
00079 void Transform::accumulateMatrix(Matrix &result)
00080 {
00081 result.mult(getMatrix());
00082 }
00083
00084 void Transform::adjustVolume(Volume &volume)
00085 {
00086 volume.transform(_sfMatrix.getValue());
00087 }
00088
00089
00090
00091
00092 void Transform::dump( UInt32 uiIndent,
00093 const BitVector bvFlags) const
00094 {
00095 Inherited::dump(uiIndent, bvFlags);
00096 }
00097
00098
00099
00100
00101 Transform::Transform(void) :
00102 Inherited()
00103 {
00104 }
00105
00106 Transform::Transform(const Transform &source) :
00107 Inherited(source)
00108 {
00109 }
00110
00111
00112
00113
00114 Transform::~Transform(void)
00115 {
00116 }
00117
00118
00119
00120
00121
00122 Action::ResultE Transform::drawEnter(Action *action)
00123 {
00124 DrawAction *da = dynamic_cast<DrawAction *>(action);
00125
00126
00127 glPushMatrix ();
00128 glMultMatrixf(getMatrix().getValues());
00129
00130 da->selectVisibles();
00131
00132 return Action::Continue;
00133 }
00134
00135 Action::ResultE Transform::drawLeave(Action *)
00136 {
00137 glPopMatrix();
00138
00139 return Action::Continue;
00140 }
00141
00142
00143
00144
00145 Action::ResultE Transform::intersectEnter(Action *action)
00146 {
00147
00148 if(Inherited::intersect(action) == Action::Skip)
00149 return Action::Skip;
00150
00151
00152 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00153 Matrix m = this->getMatrix();
00154
00155 m.invert();
00156
00157 Pnt3f pos;
00158 Vec3f dir;
00159
00160 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00161 m.multMatrixVec (ia->getLine().getDirection(), dir);
00162
00163 ia->setLine(Line(pos, dir), ia->getMaxDist());
00164 ia->scale(dir.length());
00165
00166 return Action::Continue;
00167 }
00168
00169 Action::ResultE Transform::intersectLeave(Action *action)
00170 {
00171 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00172 Matrix m = this->getMatrix();
00173
00174 Pnt3f pos;
00175 Vec3f dir;
00176
00177 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00178 m.multMatrixVec (ia->getLine().getDirection(), dir);
00179
00180 ia->setLine(Line(pos, dir), ia->getMaxDist());
00181 ia->scale(dir.length());
00182
00183 return Action::Continue;
00184 }
00185
00186 NewActionTypes::ResultE
00187 Transform::intersectActorEnter(ActorBase::FunctorArgumentType &funcArg)
00188 {
00189 IntersectActor *pIA = dynamic_cast<IntersectActor *>(funcArg.getActor());
00190 Matrix matrix = this->getMatrix();
00191 Line transLine;
00192 Pnt3f pos;
00193 Vec3f dir;
00194
00195 matrix.invert();
00196
00197 matrix.multFullMatrixPnt(pIA->getRay().getPosition (), pos);
00198 matrix.multMatrixVec (pIA->getRay().getDirection(), dir);
00199
00200 transLine.setValue(pos, dir);
00201
00202 pIA->beginEditState();
00203 {
00204 pIA->setRay (transLine );
00205 pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
00206 }
00207 pIA->endEditState ();
00208
00209 pIA->setupChildrenPriorities();
00210
00211 return NewActionTypes::Continue;
00212 }
00213
00214 NewActionTypes::ResultE
00215 Transform::intersectActorLeave(ActorBase::FunctorArgumentType &funcArg)
00216 {
00217 IntersectActor *pIA = dynamic_cast<IntersectActor *>(funcArg.getActor());
00218 const Matrix &matrix = this->getMatrix();
00219 Pnt3f pos;
00220 Vec3f dir;
00221
00222 matrix.multFullMatrixPnt(pIA->getRay().getPosition (), pos);
00223 matrix.multMatrixVec (pIA->getRay().getDirection(), dir);
00224
00225 pIA->beginEditState();
00226 {
00227 pIA->setRay (Line(pos, dir) );
00228 pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
00229 }
00230 pIA->endEditState ();
00231
00232 return NewActionTypes::Continue;
00233 }
00234
00235
00236
00237
00238 Action::ResultE Transform::renderEnter(Action *action)
00239 {
00240 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00241
00242 pAction->pushVisibility();
00243
00244 pAction->push_matrix(this->getMatrix());
00245
00246 return Action::Continue;
00247 }
00248
00249 Action::ResultE Transform::renderLeave(Action *action)
00250 {
00251 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00252
00253 pAction->popVisibility();
00254
00255 pAction->pop_matrix();
00256
00257 return Action::Continue;
00258 }
00259
00260
00261
00262
00263 void Transform::initMethod (void)
00264 {
00265 DrawAction::registerEnterDefault(
00266 getClassType(),
00267 osgTypedMethodFunctor2BaseCPtrRef<
00268 Action::ResultE,
00269 TransformPtr ,
00270 CNodePtr ,
00271 Action *>(&Transform::drawEnter));
00272
00273 DrawAction::registerLeaveDefault(
00274 getClassType(),
00275 osgTypedMethodFunctor2BaseCPtrRef<
00276 Action::ResultE,
00277 TransformPtr ,
00278 CNodePtr ,
00279 Action *>(&Transform::drawLeave));
00280
00281
00282 IntersectAction::registerEnterDefault(
00283 getClassType(),
00284 osgTypedMethodFunctor2BaseCPtrRef<
00285 Action::ResultE,
00286 TransformPtr ,
00287 CNodePtr ,
00288 Action *>(&Transform::intersectEnter));
00289
00290 IntersectAction::registerLeaveDefault(
00291 getClassType(),
00292 osgTypedMethodFunctor2BaseCPtrRef<
00293 Action::ResultE,
00294 TransformPtr ,
00295 CNodePtr ,
00296 Action *>(&Transform::intersectLeave));
00297
00298
00299 RenderAction::registerEnterDefault(
00300 getClassType(),
00301 osgTypedMethodFunctor2BaseCPtrRef<
00302 Action::ResultE,
00303 TransformPtr ,
00304 CNodePtr ,
00305 Action *>(&Transform::renderEnter));
00306
00307 RenderAction::registerLeaveDefault(
00308 getClassType(),
00309 osgTypedMethodFunctor2BaseCPtrRef<
00310 Action::ResultE,
00311 TransformPtr ,
00312 CNodePtr ,
00313 Action *>(&Transform::renderLeave));
00314
00315 IntersectActor::regClassEnter(
00316 osgTypedMethodFunctor2BaseCPtr<
00317 NewActionTypes::ResultE,
00318 TransformPtr ,
00319 NodeCorePtr ,
00320 ActorBase::FunctorArgumentType &>(&Transform::intersectActorEnter),
00321 getClassType());
00322
00323 IntersectActor::regClassLeave(
00324 osgTypedMethodFunctor2BaseCPtr<
00325 NewActionTypes::ResultE,
00326 TransformPtr ,
00327 NodeCorePtr ,
00328 ActorBase::FunctorArgumentType &>(&Transform::intersectActorLeave),
00329 getClassType());
00330
00331 }
00332
00333
00334
00335
00336
00337 #ifdef __sgi
00338 #pragma set woff 1174
00339 #endif
00340
00341 #ifdef OSG_LINUX_ICC
00342 #pragma warning( disable : 177 )
00343 #endif
00344
00345 namespace
00346 {
00347 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00348 static Char8 cvsid_hpp[] = OSGTRANSFORM_HEADER_CVSID;
00349 static Char8 cvsid_inl[] = OSGTRANSFORM_INLINE_CVSID;
00350 }