CartesianClippingNode.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
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 )
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 & , unsigned int )
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 }
00201 }
00202