VisualVisitor.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #include <sofa/simulation/common/VisualVisitor.h>
00026 
00027 namespace sofa
00028 {
00029 
00030 namespace simulation
00031 {
00032 
00033 
00034 Visitor::Result VisualDrawVisitor::processNodeTopDown(simulation::Node* node)
00035 {
00036     glPushMatrix();
00037     double glMatrix[16];
00038     node->getPositionInWorld().writeOpenGlMatrix(glMatrix);
00039     glMultMatrixd( glMatrix );
00040 
00041     hasShader = (node->getShader()!=NULL);
00042 
00043     for_each(this, node, node->visualModel,     &VisualDrawVisitor::fwdVisualModel);
00044     this->VisualVisitor::processNodeTopDown(node);
00045 
00046     glPopMatrix();
00047     return RESULT_CONTINUE;
00048 }
00049 
00050 void VisualDrawVisitor::processNodeBottomUp(simulation::Node* node)
00051 {
00052     for_each(this, node, node->visualModel,     &VisualDrawVisitor::bwdVisualModel);
00053 }
00054 
00055 void VisualDrawVisitor::processObject(simulation::Node* /*node*/, core::objectmodel::BaseObject* o)
00056 {
00057     if (pass == core::VisualModel::Std || pass == core::VisualModel::Shadow)
00058         o->draw();
00059 }
00060 
00061 void VisualDrawVisitor::fwdVisualModel(simulation::Node* /*node*/, core::VisualModel* vm)
00062 {
00063     vm->fwdDraw(pass);
00064 }
00065 
00066 void VisualDrawVisitor::bwdVisualModel(simulation::Node* /*node*/, core::VisualModel* vm)
00067 {
00068     vm->bwdDraw(pass);
00069 }
00070 
00071 void VisualDrawVisitor::processVisualModel(simulation::Node* node, core::VisualModel* vm)
00072 {
00073     //cerr<<"VisualDrawVisitor::processVisualModel "<<vm->getName()<<endl;
00074     sofa::core::Shader* shader = NULL;
00075     if (hasShader)
00076         shader = dynamic_cast<sofa::core::Shader*>(node->getShader());
00077 
00078     switch(pass)
00079     {
00080     case core::VisualModel::Std:
00081     {
00082         if (shader)
00083             shader->start();
00084         vm->drawVisual();
00085         if (shader)
00086             shader->stop();
00087         break;
00088     }
00089     case core::VisualModel::Transparent:
00090     {
00091         if (shader)
00092             shader->start();
00093         vm->drawTransparent();
00094         if (shader)
00095             shader->stop();
00096         break;
00097     }
00098     case core::VisualModel::Shadow:
00099         vm->drawShadow();
00100         break;
00101     }
00102 }
00103 
00104 void VisualUpdateVisitor::processVisualModel(simulation::Node*, core::VisualModel* vm)
00105 {
00106     vm->updateVisual();
00107 }
00108 
00109 void VisualInitVisitor::processVisualModel(simulation::Node*, core::VisualModel* vm)
00110 {
00111     vm->initVisual();
00112 }
00113 
00114 VisualComputeBBoxVisitor::VisualComputeBBoxVisitor()
00115 {
00116     minBBox[0] = minBBox[1] = minBBox[2] = 1e10;
00117     maxBBox[0] = maxBBox[1] = maxBBox[2] = -1e10;
00118 }
00119 
00120 void VisualComputeBBoxVisitor::processMechanicalState(simulation::Node*, core::componentmodel::behavior::BaseMechanicalState* vm)
00121 {
00122   vm->addBBox(minBBox, maxBBox);
00123 }
00124 void VisualComputeBBoxVisitor::processVisualModel(simulation::Node*, core::VisualModel* vm)
00125 {
00126   vm->addBBox(minBBox, maxBBox);
00127 }
00128 
00129 } // namespace simulation
00130 
00131 } // namespace sofa
00132 

Generated on Sun Nov 23 04:05:47 2008 for Sofa by  doxygen 1.5.7.1