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 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00148 Matrix m = this->getMatrix();
00149
00150 m.invert();
00151
00152 Pnt3f pos;
00153 Vec3f dir;
00154
00155 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00156 m.multMatrixVec (ia->getLine().getDirection(), dir);
00157
00158 ia->setLine(Line(pos, dir), ia->getMaxDist());
00159 ia->scale(dir.length());
00160
00161 return Action::Continue;
00162 }
00163
00164 Action::ResultE Transform::intersectLeave(Action *action)
00165 {
00166 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00167 Matrix m = this->getMatrix();
00168
00169 Pnt3f pos;
00170 Vec3f dir;
00171
00172 m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00173 m.multMatrixVec (ia->getLine().getDirection(), dir);
00174
00175 ia->setLine(Line(pos, dir), ia->getMaxDist());
00176 ia->scale(dir.length());
00177
00178 return Action::Continue;
00179 }
00180
00181 NewActionTypes::ResultE
00182 Transform::intersectEnter(ActorBase::FunctorArgumentType &funcArg)
00183 {
00184 IntersectActor *pIA = dynamic_cast<IntersectActor *>(funcArg.getActor());
00185 Matrix matrix = this->getMatrix();
00186 Line transLine;
00187 Pnt3f pos;
00188 Vec3f dir;
00189
00190 matrix.invert();
00191
00192 matrix.multFullMatrixPnt(pIA->getRay().getPosition (), pos);
00193 matrix.multMatrixVec (pIA->getRay().getDirection(), dir);
00194
00195 transLine.setValue(pos, dir);
00196
00197 pIA->beginEditState();
00198 {
00199 pIA->setRay (transLine );
00200 pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
00201 }
00202 pIA->endEditState ();
00203
00204 pIA->setupChildrenPriorities();
00205
00206 return NewActionTypes::Continue;
00207 }
00208
00209 NewActionTypes::ResultE
00210 Transform::intersectLeave(ActorBase::FunctorArgumentType &funcArg)
00211 {
00212 IntersectActor *pIA = dynamic_cast<IntersectActor *>(funcArg.getActor());
00213 const Matrix &matrix = this->getMatrix();
00214 Pnt3f pos;
00215 Vec3f dir;
00216
00217 matrix.multFullMatrixPnt(pIA->getRay().getPosition (), pos);
00218 matrix.multMatrixVec (pIA->getRay().getDirection(), dir);
00219
00220 pIA->beginEditState();
00221 {
00222 pIA->setRay (Line(pos, dir) );
00223 pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
00224 }
00225 pIA->endEditState ();
00226
00227 return NewActionTypes::Continue;
00228 }
00229
00230
00231
00232
00233 Action::ResultE Transform::renderEnter(Action *action)
00234 {
00235 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00236
00237 pAction->pushVisibility();
00238
00239 pAction->push_matrix(this->getMatrix());
00240
00241 return Action::Continue;
00242 }
00243
00244 Action::ResultE Transform::renderLeave(Action *action)
00245 {
00246 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00247
00248 pAction->popVisibility();
00249
00250 pAction->pop_matrix();
00251
00252 return Action::Continue;
00253 }
00254
00255
00256
00257
00258 void Transform::initMethod (void)
00259 {
00260 DrawAction::registerEnterDefault(
00261 getClassType(),
00262 osgTypedMethodFunctor2BaseCPtrRef<
00263 Action::ResultE,
00264 TransformPtr ,
00265 CNodePtr ,
00266 Action *>(&Transform::drawEnter));
00267
00268 DrawAction::registerLeaveDefault(
00269 getClassType(),
00270 osgTypedMethodFunctor2BaseCPtrRef<
00271 Action::ResultE,
00272 TransformPtr ,
00273 CNodePtr ,
00274 Action *>(&Transform::drawLeave));
00275
00276
00277 IntersectAction::registerEnterDefault(
00278 getClassType(),
00279 osgTypedMethodFunctor2BaseCPtrRef<
00280 Action::ResultE,
00281 TransformPtr ,
00282 CNodePtr ,
00283 Action *>(&Transform::intersectEnter));
00284
00285 IntersectAction::registerLeaveDefault(
00286 getClassType(),
00287 osgTypedMethodFunctor2BaseCPtrRef<
00288 Action::ResultE,
00289 TransformPtr ,
00290 CNodePtr ,
00291 Action *>(&Transform::intersectLeave));
00292
00293
00294 RenderAction::registerEnterDefault(
00295 getClassType(),
00296 osgTypedMethodFunctor2BaseCPtrRef<
00297 Action::ResultE,
00298 TransformPtr ,
00299 CNodePtr ,
00300 Action *>(&Transform::renderEnter));
00301
00302 RenderAction::registerLeaveDefault(
00303 getClassType(),
00304 osgTypedMethodFunctor2BaseCPtrRef<
00305 Action::ResultE,
00306 TransformPtr ,
00307 CNodePtr ,
00308 Action *>(&Transform::renderLeave));
00309
00310 IntersectActor::regClassEnter(
00311 osgTypedMethodFunctor2BaseCPtr<
00312 NewActionTypes::ResultE,
00313 TransformPtr ,
00314 NodeCorePtr ,
00315 ActorBase::FunctorArgumentType &>(&Transform::intersectEnter),
00316 getClassType());
00317
00318 IntersectActor::regClassLeave(
00319 osgTypedMethodFunctor2BaseCPtr<
00320 NewActionTypes::ResultE,
00321 TransformPtr ,
00322 NodeCorePtr ,
00323 ActorBase::FunctorArgumentType &>(&Transform::intersectLeave),
00324 getClassType());
00325 }
00326
00327
00328
00329
00330
00331 #ifdef __sgi
00332 #pragma set woff 1174
00333 #endif
00334
00335 #ifdef OSG_LINUX_ICC
00336 #pragma warning( disable : 177 )
00337 #endif
00338
00339 namespace
00340 {
00341 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00342 static Char8 cvsid_hpp[] = OSGTRANSFORM_HEADER_CVSID;
00343 static Char8 cvsid_inl[] = OSGTRANSFORM_INLINE_CVSID;
00344 }