fixed: stay with old cmake qt link setup (policy CMP0020)
[opensg.git] / Source / System / State / OpenGL / OSGClipPlaneChunk.cpp
blob8d9b84a1401bcb17f20eb9dfc253011e07d2c9be
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGL.h"
50 #include "OSGCamera.h"
51 #include "OSGDrawEnv.h"
52 #include "OSGNode.h"
54 #include "OSGClipPlaneChunk.h"
56 OSG_USING_NAMESPACE
58 // Documentation for this class is emited in the
59 // OSGClipPlaneChunkBase.cpp file.
60 // To modify it, please change the .fcd file (OSGClipPlaneChunk.fcd) and
61 // regenerate the base file.
63 /***************************************************************************\
64 * Class variables *
65 \***************************************************************************/
67 StateChunkClass ClipPlaneChunk::_class("ClipPlane", 6, 140);
69 void ClipPlaneChunk::initMethod(InitPhase ePhase)
71 Inherited::initMethod(ePhase);
74 /***************************************************************************\
75 * Instance methods *
76 \***************************************************************************/
78 /*-------------------------------------------------------------------------*\
79 - private -
80 \*-------------------------------------------------------------------------*/
82 /*----------------------- constructors & destructors ----------------------*/
84 ClipPlaneChunk::ClipPlaneChunk(void) :
85 Inherited()
89 ClipPlaneChunk::ClipPlaneChunk(const ClipPlaneChunk &source) :
90 Inherited(source)
94 ClipPlaneChunk::~ClipPlaneChunk(void)
98 /*----------------------- Chunk Class Access -----------------------------*/
100 const StateChunkClass *ClipPlaneChunk::getClass(void) const
102 return &_class;
105 /*------------------------------- Sync -----------------------------------*/
107 void ClipPlaneChunk::changed(ConstFieldMaskArg whichField,
108 UInt32 origin,
109 BitVector details)
111 Inherited::changed(whichField, origin, details);
114 /*------------------------------ Output ----------------------------------*/
116 void ClipPlaneChunk::dump( UInt32 ,
117 const BitVector) const
119 SLOG << "Dump ClipPlaneChunk NI" << std::endl;
123 /*------------------------------ State ------------------------------------*/
125 void ClipPlaneChunk::activate(DrawEnv *pEnv, UInt32 idx)
127 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
128 pEnv->incNumChunkChanges();
130 Matrix beaconMat;
132 Matrix cameraMat = pEnv->getCameraViewing();
134 if(getBeacon() != NULL)
136 getBeacon()->getToWorld(beaconMat);
138 else
140 beaconMat.setIdentity();
142 SWARNING << "NO beacon" << std::endl;
145 cameraMat.mult(beaconMat);
147 if(getEnable() == true)
149 GLdouble glEq[4];
150 const Vec4f &eq = getEquation();
152 glEq[0] = eq[0];
153 glEq[1] = eq[1];
154 glEq[2] = eq[2];
155 glEq[3] = eq[3];
157 glPushMatrix();
158 glLoadMatrixf(cameraMat.getValues());
160 glClipPlane( GL_CLIP_PLANE0 + idx, glEq);
161 glEnable( GL_CLIP_PLANE0 + idx);
163 glPopMatrix();
165 #else
166 OSG_ASSERT(false);
167 #endif
173 void ClipPlaneChunk::changeFrom(DrawEnv *pEnv,
174 StateChunk *old_chunk,
175 UInt32 idx)
177 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
178 ClipPlaneChunk const *old = dynamic_cast<ClipPlaneChunk const*>(old_chunk);
180 // change from me to me?
181 // this assumes I haven't changed in the meantime.
182 // is that a valid assumption?
184 if(old == this)
185 return;
187 pEnv->incNumChunkChanges();
189 Matrix beaconMat;
191 Matrix cameraMat = pEnv->getCameraViewing();
193 if(getBeacon() != NULL)
195 getBeacon()->getToWorld(beaconMat);
197 else
199 beaconMat.setIdentity();
201 SWARNING << "ClipPlaneChunk::changeFrom: NO beacon" << std::endl;
204 cameraMat.mult(beaconMat);
206 if(getEquation() != old->getEquation() ||
207 getEnable () != old->getEnable () ||
208 getBeacon () != old->getBeacon () )
210 if(getEnable() == true)
212 GLdouble glEq[4];
213 const Vec4f &eq = getEquation();
215 glEq[0] = eq[0];
216 glEq[1] = eq[1];
217 glEq[2] = eq[2];
218 glEq[3] = eq[3];
220 glPushMatrix();
221 glLoadMatrixf(cameraMat.getValues());
223 glClipPlane(GL_CLIP_PLANE0 + idx, glEq);
224 glEnable (GL_CLIP_PLANE0 + idx );
226 glPopMatrix();
228 else
230 glDisable(GL_CLIP_PLANE0 + idx);
233 #else
234 OSG_ASSERT(false);
235 #endif
239 void ClipPlaneChunk::deactivate(DrawEnv *, UInt32 idx)
241 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
242 if(getEnable() == true)
244 glDisable( GL_CLIP_PLANE0 + idx);
246 #else
247 OSG_ASSERT(false);
248 #endif
252 /*-------------------------- Comparison -----------------------------------*/
254 Real32 ClipPlaneChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
256 return 0;
259 bool ClipPlaneChunk::operator < (const StateChunk &other) const
261 return this < &other;
264 bool ClipPlaneChunk::operator == (const StateChunk &other) const
266 ClipPlaneChunk const *tother = dynamic_cast<ClipPlaneChunk const*>(&other);
268 if(!tother)
269 return false;
271 if(getEnable() != tother->getEnable())
272 return false;
274 if(getEquation() != tother->getEquation())
275 return false;
277 if(getBeacon() != tother->getBeacon())
278 return false;
280 return true;
283 bool ClipPlaneChunk::operator != (const StateChunk &other) const
285 return ! (*this == other);