Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGInverseTransform.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *               Copyright (C) 2000-2002 by the OpenSG Forum                 *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include <OSGConfig.h>
00047 #include <OSGGL.h>
00048 
00049 #include "OSGInverseTransform.h"
00050 #include "OSGNodePtr.h"
00051 #include "OSGDrawAction.h"
00052 #include "OSGIntersectAction.h"
00053 #include "OSGRenderAction.h"
00054 #include "OSGNode.h"
00055 
00056 OSG_USING_NAMESPACE
00057 
00058 /***************************************************************************\
00059  *                            Description                                  *
00060 \***************************************************************************/
00061 
00066 /***************************************************************************\
00067  *                           Class variables                               *
00068 \***************************************************************************/
00069 
00070 /***************************************************************************\
00071  *                           Class methods                                 *
00072 \***************************************************************************/
00073 
00074 void InverseTransform::initMethod (void)
00075 {
00076     DrawAction::registerEnterDefault(
00077         getClassType(),
00078         osgTypedMethodFunctor2BaseCPtrRef<
00079             Action::ResultE,
00080             InverseTransformPtr    ,
00081             CNodePtr        ,
00082             Action         *>(&InverseTransform::drawEnter));
00083 
00084     DrawAction::registerLeaveDefault(
00085         getClassType(),
00086         osgTypedMethodFunctor2BaseCPtrRef<
00087             Action::ResultE,
00088             InverseTransformPtr    ,
00089             CNodePtr        ,
00090             Action         *>(&InverseTransform::drawLeave));
00091 
00092 
00093     IntersectAction::registerEnterDefault(
00094         getClassType(),
00095         osgTypedMethodFunctor2BaseCPtrRef<
00096             Action::ResultE,
00097             InverseTransformPtr    ,
00098             CNodePtr        ,
00099             Action         *>(&InverseTransform::intersectEnter));
00100 
00101     IntersectAction::registerLeaveDefault(
00102         getClassType(),
00103         osgTypedMethodFunctor2BaseCPtrRef<
00104             Action::ResultE,
00105             InverseTransformPtr    ,
00106             CNodePtr        ,
00107             Action         *>(&InverseTransform::intersectLeave));
00108 
00109 
00110     RenderAction::registerEnterDefault(
00111         getClassType(),
00112         osgTypedMethodFunctor2BaseCPtrRef<
00113             Action::ResultE,
00114             InverseTransformPtr    ,
00115             CNodePtr        ,
00116             Action         *>(&InverseTransform::renderEnter));
00117 
00118     RenderAction::registerLeaveDefault(
00119         getClassType(),
00120         osgTypedMethodFunctor2BaseCPtrRef<
00121             Action::ResultE,
00122             InverseTransformPtr    ,
00123             CNodePtr        ,
00124             Action         *>(&InverseTransform::renderLeave));
00125 }
00126 
00127 
00128 /***************************************************************************\
00129  *                           Instance methods                              *
00130 \***************************************************************************/
00131 
00132 /*-------------------------------------------------------------------------*\
00133  -  private                                                                 -
00134 \*-------------------------------------------------------------------------*/
00135 
00136 /*----------------------- constructors & destructors ----------------------*/
00137 
00138 InverseTransform::InverseTransform(void) :
00139     Inherited(),
00140     _invWorld()
00141 {
00142 }
00143 
00144 InverseTransform::InverseTransform(const InverseTransform &source) :
00145     Inherited(source),
00146     _invWorld(source._invWorld)
00147 {
00148 }
00149 
00150 InverseTransform::~InverseTransform(void)
00151 {
00152 }
00153 
00154 /*----------------------------- class specific ----------------------------*/
00155 
00156 void InverseTransform::changed(BitVector whichField, UInt32 origin)
00157 {
00158     Inherited::changed(whichField, origin);
00159 }
00160 
00161 void InverseTransform::dump(      UInt32    uiIndent,
00162                             const BitVector bvFlags ) const
00163 {
00164     Inherited::dump(uiIndent, bvFlags);
00165 }
00166 
00167 /*------------------------- volume update -------------------------------*/
00168 
00169 void InverseTransform::adjustVolume( Volume & volume )
00170 {
00171     volume.transform(_invWorld);
00172 }
00173 
00174 void InverseTransform::accumulateMatrix(Matrix &result)
00175 {
00176     result.mult(_invWorld);
00177 }
00178 
00179 /*------------------------- calc matrix ---------------------------------*/
00180 
00181 void InverseTransform::calcMatrix(      DrawActionBase * OSG_CHECK_ARG(pAction),
00182                                   const Matrix         &mToWorld,
00183                                         Matrix         &mResult)
00184 {
00185     mResult.invertFrom(mToWorld);
00186 
00187     _invWorld = mResult;    // remember dynamically set matrix field
00188 }
00189 
00190 void InverseTransform::initMatrix(const Matrix &mToWorld)
00191 {
00192     _invWorld.invertFrom(mToWorld);
00193 }
00194 
00195 /*-------------------------------------------------------------------------*/
00196 /*                               Draw                                      */
00197 
00198 Action::ResultE InverseTransform::drawEnter(Action *action)
00199 {
00200     DrawAction *da = dynamic_cast<DrawAction *>(action);
00201     Matrix mMat;
00202 
00203     calcMatrix(da, da->getActNode()->getToWorld(), mMat);
00204 
00205     // should use the chunk, but it's not updated yet
00206     glPushMatrix ();
00207     glMultMatrixf(mMat.getValues());
00208 
00209     return Action::Continue;
00210 }
00211 
00212 Action::ResultE InverseTransform::drawLeave(Action * OSG_CHECK_ARG(action))
00213 {
00214     glPopMatrix();
00215 
00216     return Action::Continue;
00217 }
00218 
00219 /*-------------------------------------------------------------------------*/
00220 /*                            Intersect                                    */
00221 
00222 Action::ResultE InverseTransform::intersectEnter(Action *action)
00223 {
00224     IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00225     Matrix           m(_invWorld);
00226 
00227     m.invert();
00228 
00229     Pnt3f pos;
00230     Vec3f dir;
00231 
00232     m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00233     m.multMatrixVec    (ia->getLine().getDirection(), dir);
00234 
00235     ia->setLine(Line(pos, dir), ia->getMaxDist());
00236     ia->scale(dir.length());
00237 
00238     return Action::Continue;
00239 }
00240 
00241 Action::ResultE InverseTransform::intersectLeave(Action *action)
00242 {
00243     IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
00244     Matrix           m(_invWorld);
00245 
00246     Pnt3f pos;
00247     Vec3f dir;
00248 
00249     m.multFullMatrixPnt(ia->getLine().getPosition (), pos);
00250     m.multMatrixVec    (ia->getLine().getDirection(), dir);
00251 
00252     ia->setLine(Line(pos, dir), ia->getMaxDist());
00253     ia->scale(dir.length());
00254 
00255     return Action::Continue;
00256 }
00257 
00258 /*-------------------------------------------------------------------------*/
00259 /*                                Render                                   */
00260 
00261 Action::ResultE InverseTransform::renderEnter(Action *action)
00262 {
00263     RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00264     Matrix mMat;    // will be set to World^-1
00265 
00266     calcMatrix(pAction, pAction->top_matrix(), mMat);
00267 
00268     pAction->push_matrix(mMat);
00269 
00270     return Action::Continue;
00271 }
00272 
00273 Action::ResultE InverseTransform::renderLeave(Action *action)
00274 {
00275     RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00276 
00277     pAction->pop_matrix();
00278 
00279     return Action::Continue;
00280 }
00281 
00282 /*------------------------------------------------------------------------*/
00283 /*                              cvs id's                                  */
00284 
00285 #ifdef OSG_SGI_CC
00286 #pragma set woff 1174
00287 #endif
00288 
00289 #ifdef OSG_LINUX_ICC
00290 #pragma warning( disable : 177 )
00291 #endif
00292 
00293 namespace
00294 {
00295     static Char8 cvsid_cpp       [] = "@(#)$Id: OSGInverseTransform.cpp,v 1.2 2004/10/13 14:51:34 a-m-z Exp $";
00296     static Char8 cvsid_hpp       [] = OSGINVERSETRANSFORMBASE_HEADER_CVSID;
00297     static Char8 cvsid_inl       [] = OSGINVERSETRANSFORMBASE_INLINE_CVSID;
00298 
00299     static Char8 cvsid_fields_hpp[] = OSGINVERSETRANSFORMFIELDS_HEADER_CVSID;
00300 }
00301 
00302 #ifdef __sgi
00303 #pragma reset woff 1174
00304 #endif

Generated on Thu Aug 25 04:06:34 2005 for OpenSG by  doxygen 1.4.3