ClipPlane.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/component/visualmodel/ClipPlane.h>
00026 #include <sofa/core/ObjectFactory.h>
00027 
00028 namespace sofa
00029 {
00030 
00031 namespace component
00032 {
00033 
00034 namespace visualmodel
00035 {
00036 
00037 SOFA_DECL_CLASS(ClipPlane)
00038 
00039 int ClipPlaneClass = core::RegisterObject("OpenGL Clipping Plane")
00040 .add< ClipPlane >()
00041 ;
00042 
00043 
00044 ClipPlane::ClipPlane()
00045 : position(initData(&position, Vector3(0,0,0), "position", "Point crossed by the clipping plane"))
00046 , normal(initData(&normal, Vector3(1,0,0), "normal", "Normal of the clipping plane, pointing toward the clipped region"))
00047 , id(initData(&id, 0, "id", "Clipping plane OpenGL ID"))
00048 , active(initData(&active,true,"active","Control whether the clipping plane should be applied or not"))
00049 {
00050 
00051 }
00052 
00053 ClipPlane::~ClipPlane()
00054 {
00055 }
00056 
00057 void ClipPlane::init()
00058 {
00059 }
00060 
00061 void ClipPlane::reinit()
00062 {
00063 }
00064 
00065 void ClipPlane::fwdDraw(Pass)
00066 {
00067     wasActive = glIsEnabled(GL_CLIP_PLANE0+id.getValue());
00068     if (active.getValue())
00069     {
00070         glGetClipPlane(GL_CLIP_PLANE0+id.getValue(), saveEq);
00071         Vector3 p = position.getValue();
00072         Vector3 n = normal.getValue();
00073         GLdouble c[4] = { (GLdouble) -n[0], (GLdouble)-n[1], (GLdouble)-n[2], (GLdouble)(p*n) };
00074         glClipPlane(GL_CLIP_PLANE0+id.getValue(), c);
00075         if (!wasActive)
00076             glEnable(GL_CLIP_PLANE0+id.getValue());
00077     }
00078     else
00079     {
00080         if (wasActive)
00081             glDisable(GL_CLIP_PLANE0+id.getValue());
00082     }
00083 }
00084 
00085 void ClipPlane::bwdDraw(Pass)
00086 {
00087     if (active.getValue())
00088     {
00089         glClipPlane(GL_CLIP_PLANE0+id.getValue(), saveEq);
00090         if (!wasActive)
00091             glDisable(GL_CLIP_PLANE0+id.getValue());
00092     }
00093     else
00094     {
00095         if (wasActive)
00096             glEnable(GL_CLIP_PLANE0+id.getValue());
00097     }
00098 }
00099 
00100 } // namespace visualmodel
00101 
00102 } //namespace component
00103 
00104 } //namespace sofa

Generated on Sun Nov 23 03:47:41 2008 for Sofa by  doxygen 1.5.7.1