00001 //----------------------------------------------------------------------------------- 00002 // 00003 // Pro-Vocation Light Engine (PVLE) 00004 // Copyright (C) 2007-2009 Sukender, KinoX & Buzib 00005 // For more information, contact us : sukender@free.fr 00006 // 00007 // This program is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // For any use that is not compatible with the terms of the GNU 00013 // General Public License, please contact the authors for alternative 00014 // licensing options. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with this program; if not, write to the Free Software Foundation, Inc., 00023 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 // 00025 //----------------------------------------------------------------------------------- 00026 00027 #ifndef _3D_PHYSICS_UPDATE_CB_H 00028 #define _3D_PHYSICS_UPDATE_CB_H 00029 00030 #include <osg/NodeCallback> 00031 #include <osg/MatrixTransform> 00032 #include <boost/cast.hpp> 00033 #include <PVLE/Physics/Geom.h> 00034 00037 class PhysicsUpdateCB : public osg::NodeCallback { 00038 public: 00039 PhysicsUpdateCB(Physics::Geom * pGeom) : pGeom(pGeom) { ASSERT(pGeom); } 00040 virtual void operator() (osg::Node * pNode, osg::NodeVisitor * pNV) { 00041 boost::polymorphic_downcast<osg::MatrixTransform *>(pNode)->setMatrix(pGeom->getMatrix()); 00042 traverse(pNode, pNV); 00043 } 00044 00045 Physics::Geom * getGeom() { return pGeom; } 00046 const Physics::Geom * getGeom() const { return pGeom; } 00047 00048 void setGeom(Physics::Geom * pGeom) { this->pGeom = pGeom; } 00049 00051 osg::Matrix getLTWCamMatrix() const { return pGeom->getMatrix(); } 00053 osg::Matrix getWTLCamMatrix() const { return osg::Matrix::inverse(pGeom->getMatrix()); } 00054 00055 protected: 00056 Physics::Geom * pGeom; 00057 }; 00058 00059 00060 00061 /* Old version that use the OSG's node path to get WTL / LTW matrices. More complete, but useless for the moment. 00062 00064 class PhysicsTrackUpdateCB : public PhysicsUpdateCB { 00065 public: 00066 PhysicsTrackUpdateCB(Physics::Geom * pGeom) : PhysicsUpdateCB(pGeom) {} 00067 virtual void operator() (osg::Node * pNode, osg::NodeVisitor * pNV) { 00068 PhysicsUpdateCB::operator()(pNode, pNV); 00069 //LOG_ALWAYS << pGeom->getMatrix() << std::endl; 00070 wtl = osg::computeWorldToLocal(pNV->getNodePath()); 00071 } 00072 00073 osg::Matrix getLTWCamMatrix() const { return osg::Matrix::inverse(wtl); } 00074 osg::Matrix getWTLCamMatrix() const { return wtl; } 00075 00076 protected: 00077 osg::Matrix wtl; 00078 }; 00079 */ 00080 00081 00082 #endif // _3D_PHYSICS_UPDATE_CB_H