1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
50 #include "OSGCamera.h"
51 #include "OSGDrawEnv.h"
54 #include "OSGClipPlaneChunk.h"
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 /***************************************************************************\
65 \***************************************************************************/
67 StateChunkClass
ClipPlaneChunk::_class("ClipPlane", 6, 140);
69 void ClipPlaneChunk::initMethod(InitPhase ePhase
)
71 Inherited::initMethod(ePhase
);
74 /***************************************************************************\
76 \***************************************************************************/
78 /*-------------------------------------------------------------------------*\
80 \*-------------------------------------------------------------------------*/
82 /*----------------------- constructors & destructors ----------------------*/
84 ClipPlaneChunk::ClipPlaneChunk(void) :
89 ClipPlaneChunk::ClipPlaneChunk(const ClipPlaneChunk
&source
) :
94 ClipPlaneChunk::~ClipPlaneChunk(void)
98 /*----------------------- Chunk Class Access -----------------------------*/
100 const StateChunkClass
*ClipPlaneChunk::getClass(void) const
105 /*------------------------------- Sync -----------------------------------*/
107 void ClipPlaneChunk::changed(ConstFieldMaskArg whichField
,
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();
132 Matrix cameraMat
= pEnv
->getCameraViewing();
134 if(getBeacon() != NULL
)
136 getBeacon()->getToWorld(beaconMat
);
140 beaconMat
.setIdentity();
142 SWARNING
<< "NO beacon" << std::endl
;
145 cameraMat
.mult(beaconMat
);
147 if(getEnable() == true)
150 const Vec4f
&eq
= getEquation();
158 glLoadMatrixf(cameraMat
.getValues());
160 glClipPlane( GL_CLIP_PLANE0
+ idx
, glEq
);
161 glEnable( GL_CLIP_PLANE0
+ idx
);
173 void ClipPlaneChunk::changeFrom(DrawEnv
*pEnv
,
174 StateChunk
*old_chunk
,
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?
187 pEnv
->incNumChunkChanges();
191 Matrix cameraMat
= pEnv
->getCameraViewing();
193 if(getBeacon() != NULL
)
195 getBeacon()->getToWorld(beaconMat
);
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)
213 const Vec4f
&eq
= getEquation();
221 glLoadMatrixf(cameraMat
.getValues());
223 glClipPlane(GL_CLIP_PLANE0
+ idx
, glEq
);
224 glEnable (GL_CLIP_PLANE0
+ idx
);
230 glDisable(GL_CLIP_PLANE0
+ idx
);
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
);
252 /*-------------------------- Comparison -----------------------------------*/
254 Real32
ClipPlaneChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
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
);
271 if(getEnable() != tother
->getEnable())
274 if(getEquation() != tother
->getEquation())
277 if(getBeacon() != tother
->getBeacon())
283 bool ClipPlaneChunk::operator != (const StateChunk
&other
) const
285 return ! (*this == other
);