CartesianClippingNode.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 
00048 #include "CartesianClippingNode.hh"
00049 
00050 //=============================================================================
00051 
00052 namespace ACG {
00053 namespace SceneGraph {
00054 
00055 //=============================================================================
00056 
00057 
00058 CartesianClippingNode::CartesianClippingNode( BaseNode*           _parent,
00059                                               const std::string&  _name )
00060   : BaseNode( _parent, _name )
00061 {
00062   set_cursor( Vec3f( 0, 0, 0 ) );
00063   enabled_ = NONE;
00064 }
00065 
00066 //-----------------------------------------------------------------------------
00067 
00068 
00069 void
00070 CartesianClippingNode::enter( GLState & _state, unsigned int /* _drawmode */ )
00071 {
00072   Vec3d eye = _state.eye();
00073 
00074   if ( is_enabled( XY_PLANE ) )
00075   {
00076     GLdouble xy_plane[4];  
00077     if ( eye[2] > 0 )
00078     {  
00079       xy_plane[0] = 0;
00080       xy_plane[1] = 0;
00081       xy_plane[2] = -1;
00082       xy_plane[3] = cursor_[2];
00083     }
00084     else
00085     {
00086       xy_plane[0] = 0;
00087       xy_plane[1] = 0;
00088       xy_plane[2] = 1;
00089       xy_plane[3] = -cursor_[2];
00090     }
00091     
00092     glClipPlane( GL_CLIP_PLANE0, xy_plane );
00093     glEnable( GL_CLIP_PLANE0 );
00094   }
00095 
00096   if ( is_enabled( YZ_PLANE ) )
00097   {
00098     GLdouble yz_plane[4];  
00099     if ( eye[0] > 0 )
00100     {  
00101       yz_plane[0] = -1;
00102       yz_plane[1] = 0;
00103       yz_plane[2] = 0;
00104       yz_plane[3] = cursor_[0];
00105     }
00106     else
00107     {
00108       yz_plane[0] = 1;
00109       yz_plane[1] = 0;
00110       yz_plane[2] = 0;
00111       yz_plane[3] = -cursor_[0];
00112     }
00113     
00114     glClipPlane( GL_CLIP_PLANE1, yz_plane );
00115     glEnable( GL_CLIP_PLANE1 );
00116   }
00117 
00118   if ( is_enabled( XZ_PLANE ) )
00119   {
00120     GLdouble xz_plane[4];  
00121     if ( eye[1] > 0 )
00122     {  
00123       xz_plane[0] = 0;
00124       xz_plane[1] = -1;
00125       xz_plane[2] = 0;
00126       xz_plane[3] = cursor_[1];
00127     }
00128     else
00129     {
00130       xz_plane[0] = 0;
00131       xz_plane[1] = 1;
00132       xz_plane[2] = 0;
00133       xz_plane[3] = -cursor_[1];
00134     }
00135     
00136     glClipPlane( GL_CLIP_PLANE2, xz_plane );
00137     glEnable( GL_CLIP_PLANE2 );
00138   }
00139 
00140 
00141   
00142 }
00143 
00144 
00145 //-----------------------------------------------------------------------------
00146 
00147 
00148 void
00149 CartesianClippingNode::leave( GLState & /* _state */ , unsigned int /* _drawmode */ )
00150 {
00151   glDisable( GL_CLIP_PLANE0 );
00152   glDisable( GL_CLIP_PLANE1 );
00153   glDisable( GL_CLIP_PLANE2 );
00154 }
00155 
00156 
00157 //-----------------------------------------------------------------------------
00158 
00159 
00160 void
00161 CartesianClippingNode::set_cursor( const Vec3f & _cursor )
00162 {
00163   cursor_ = _cursor;
00164   
00165 }
00166 
00167 
00168 //-----------------------------------------------------------------------------
00169 
00170 
00171 const
00172 Vec3f &
00173 CartesianClippingNode::cursor() const
00174 {
00175   return cursor_;
00176 }
00177 
00178 
00179 //-----------------------------------------------------------------------------
00180 
00181 
00182 void
00183 CartesianClippingNode::set_enabled( Plane _plane ) 
00184 {
00185   enabled_ = _plane;
00186 }
00187 
00188 
00189 //-----------------------------------------------------------------------------
00190 
00191 
00192 bool
00193 CartesianClippingNode::is_enabled( Plane _plane ) const
00194 {
00195   return ( enabled_ == _plane );
00196 }
00197 
00198 
00199 //=============================================================================
00200 } // namespace SceneGraph
00201 } // namespace ACG
00202 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .