Developer Documentation
CartesianClippingNode.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 
49 #include "CartesianClippingNode.hh"
50 
51 //=============================================================================
52 
53 namespace ACG {
54 namespace SceneGraph {
55 
56 //=============================================================================
57 
58 
59 CartesianClippingNode::CartesianClippingNode( BaseNode* _parent,
60  const std::string& _name )
61  : BaseNode( _parent, _name )
62 {
63  set_cursor( Vec3f( 0, 0, 0 ) );
64  enabled_ = NONE;
65 }
66 
67 //-----------------------------------------------------------------------------
68 
69 
70 void
71 CartesianClippingNode::enter( GLState & _state, const DrawModes::DrawMode& /* _drawmode */ )
72 {
73  Vec3d eye = _state.eye();
74 
75  if ( is_enabled( XY_PLANE ) )
76  {
77  GLdouble xy_plane[4];
78  if ( eye[2] > 0 )
79  {
80  xy_plane[0] = 0;
81  xy_plane[1] = 0;
82  xy_plane[2] = -1;
83  xy_plane[3] = cursor_[2];
84  }
85  else
86  {
87  xy_plane[0] = 0;
88  xy_plane[1] = 0;
89  xy_plane[2] = 1;
90  xy_plane[3] = -cursor_[2];
91  }
92 
93  glClipPlane( GL_CLIP_PLANE0, xy_plane );
94  ACG::GLState::enable( GL_CLIP_PLANE0 );
95  }
96 
97  if ( is_enabled( YZ_PLANE ) )
98  {
99  GLdouble yz_plane[4];
100  if ( eye[0] > 0 )
101  {
102  yz_plane[0] = -1;
103  yz_plane[1] = 0;
104  yz_plane[2] = 0;
105  yz_plane[3] = cursor_[0];
106  }
107  else
108  {
109  yz_plane[0] = 1;
110  yz_plane[1] = 0;
111  yz_plane[2] = 0;
112  yz_plane[3] = -cursor_[0];
113  }
114 
115  glClipPlane( GL_CLIP_PLANE1, yz_plane );
116  ACG::GLState::enable( GL_CLIP_PLANE1 );
117  }
118 
119  if ( is_enabled( XZ_PLANE ) )
120  {
121  GLdouble xz_plane[4];
122  if ( eye[1] > 0 )
123  {
124  xz_plane[0] = 0;
125  xz_plane[1] = -1;
126  xz_plane[2] = 0;
127  xz_plane[3] = cursor_[1];
128  }
129  else
130  {
131  xz_plane[0] = 0;
132  xz_plane[1] = 1;
133  xz_plane[2] = 0;
134  xz_plane[3] = -cursor_[1];
135  }
136 
137  glClipPlane( GL_CLIP_PLANE2, xz_plane );
138  ACG::GLState::enable( GL_CLIP_PLANE2 );
139  }
140 
141 
142 
143 }
144 
145 
146 //-----------------------------------------------------------------------------
147 
148 
149 void
150 CartesianClippingNode::leave( GLState & /* _state */ , const DrawModes::DrawMode& /* _drawmode */ )
151 {
152  ACG::GLState::disable( GL_CLIP_PLANE0 );
153  ACG::GLState::disable( GL_CLIP_PLANE1 );
154  ACG::GLState::disable( GL_CLIP_PLANE2 );
155 }
156 
157 
158 //-----------------------------------------------------------------------------
159 
160 
161 void
163 {
164  cursor_ = _cursor;
165 
166 }
167 
168 
169 //-----------------------------------------------------------------------------
170 
171 
172 const
173 Vec3f &
175 {
176  return cursor_;
177 }
178 
179 
180 //-----------------------------------------------------------------------------
181 
182 
183 void
184 CartesianClippingNode::set_enabled( Plane _plane )
185 {
186  enabled_ = _plane;
187 }
188 
189 
190 //-----------------------------------------------------------------------------
191 
192 
193 bool
194 CartesianClippingNode::is_enabled( Plane _plane ) const
195 {
196  return ( enabled_ == _plane );
197 }
198 
199 
200 //=============================================================================
201 } // namespace SceneGraph
202 } // namespace ACG
203 //=============================================================================
const Vec3f & cursor() const
get position
Namespace providing different geometric functions concerning angles.
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode) override
begin clipping
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:119
void set_cursor(const Vec3f &_pos)
set position
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode) override
stop clipping
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
Vec3d eye() const
get eye point
Definition: GLState.cc:886