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 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <OSGConfig.h>
00047
00048 #include <OSGGL.h>
00049
00050 #include <OSGDrawActionBase.h>
00051 #include <OSGRenderAction.h>
00052 #include <OSGCamera.h>
00053
00054 #include "OSGClipPlaneChunk.h"
00055
00056 OSG_USING_NAMESPACE
00057
00058
00059
00060
00061
00073
00074
00075
00076
00077 StateChunkClass ClipPlaneChunk::_class("ClipPlane", 6);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 ClipPlaneChunk::ClipPlaneChunk(void) :
00090 Inherited()
00091 {
00092 }
00093
00094 ClipPlaneChunk::ClipPlaneChunk(const ClipPlaneChunk &source) :
00095 Inherited(source)
00096 {
00097 }
00098
00099 ClipPlaneChunk::~ClipPlaneChunk(void)
00100 {
00101 }
00102
00103
00104
00105 const StateChunkClass *ClipPlaneChunk::getClass(void) const
00106 {
00107 return &_class;
00108 }
00109
00110
00111
00112 void ClipPlaneChunk::changed(BitVector, UInt32)
00113 {
00114 }
00115
00116
00117
00118 void ClipPlaneChunk::dump( UInt32 ,
00119 const BitVector) const
00120 {
00121 SLOG << "Dump ClipPlaneChunk NI" << std::endl;
00122 }
00123
00124
00125
00126
00127 void ClipPlaneChunk::activate(DrawActionBase *action, UInt32 idx)
00128 {
00129 RenderAction *ra = dynamic_cast<RenderAction *>(action);
00130
00131 Matrix beaconMat;
00132
00133 if(ra != NULL)
00134 {
00135 beaconMat = ra->top_matrix();
00136 }
00137 else
00138 {
00139 beaconMat = action->getActNode()->getToWorld();
00140 }
00141
00142
00143 Matrix cameraMat = action->getCameraToWorld();
00144
00145 cameraMat.invert();
00146
00147 if(getBeacon() != NullFC)
00148 {
00149 getBeacon()->getToWorld(beaconMat);
00150 }
00151 else
00152 {
00153 SWARNING << "NO beacon" << std::endl;
00154 }
00155
00156 cameraMat.mult(beaconMat);
00157
00158 if(getEnable())
00159 {
00160 GLdouble glEq[4];
00161 Vec4f & eq = getEquation();
00162 glEq[0] = eq[0];
00163 glEq[1] = eq[1];
00164 glEq[2] = eq[2];
00165 glEq[3] = eq[3];
00166
00167 glPushMatrix();
00168 glLoadMatrixf(cameraMat.getValues());
00169
00170 glClipPlane( GL_CLIP_PLANE0 + idx, glEq);
00171 glEnable( GL_CLIP_PLANE0 + idx);
00172
00173 glPopMatrix();
00174 }
00175 }
00176
00177
00178
00179
00180 void ClipPlaneChunk::changeFrom(DrawActionBase *action, StateChunk * old_chunk,
00181 UInt32 idx)
00182 {
00183 ClipPlaneChunk const *old = dynamic_cast<ClipPlaneChunk const*>(old_chunk);
00184
00185
00186
00187 if(old == this)
00188 return;
00189
00190
00191 RenderAction *ra = dynamic_cast<RenderAction *>(action);
00192
00193 Matrix beaconMat;
00194
00195 if(ra != NULL)
00196 {
00197 beaconMat = ra->top_matrix();
00198 }
00199 else
00200 {
00201 beaconMat = action->getActNode()->getToWorld();
00202 }
00203
00204
00205 Matrix cameraMat = action->getCameraToWorld();
00206
00207 cameraMat.invert();
00208
00209 if (getBeacon() != NullFC)
00210 {
00211 getBeacon()->getToWorld(beaconMat);
00212 }
00213 else
00214 {
00215 SWARNING << "ClipPlaneChunk::changeFrom: NO beacon" << std::endl;
00216 }
00217
00218 cameraMat.mult(beaconMat);
00219
00220 if(getEnable() != old->getEnable() ||
00221 getBeacon() != old->getBeacon())
00222 {
00223 if(getEnable())
00224 {
00225 GLdouble glEq[4];
00226 Vec4f & eq = getEquation();
00227 glEq[0] = eq[0];
00228 glEq[1] = eq[1];
00229 glEq[2] = eq[2];
00230 glEq[3] = eq[3];
00231
00232 glPushMatrix();
00233 glLoadMatrixf(cameraMat.getValues());
00234
00235 glClipPlane( GL_CLIP_PLANE0 + idx, glEq);
00236 glEnable( GL_CLIP_PLANE0 + idx);
00237
00238 glPopMatrix();
00239 }
00240 else
00241 {
00242 glDisable( GL_CLIP_PLANE0 + idx);
00243 }
00244 }
00245 else
00246 {
00247 ;
00248 }
00249 }
00250
00251
00252 void ClipPlaneChunk::deactivate(DrawActionBase *, UInt32 idx)
00253 {
00254 if(getEnable())
00255 {
00256 glDisable( GL_CLIP_PLANE0 + idx);
00257 }
00258 }
00259
00260
00261
00262
00263 Real32 ClipPlaneChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00264 {
00265 return 0;
00266 }
00267
00268 bool ClipPlaneChunk::operator < (const StateChunk &other) const
00269 {
00270 return this < &other;
00271 }
00272
00273 bool ClipPlaneChunk::operator == (const StateChunk &other) const
00274 {
00275 ClipPlaneChunk const *tother = dynamic_cast<ClipPlaneChunk const*>(&other);
00276
00277 if(!tother)
00278 return false;
00279
00280 if(getEnable() != tother->getEnable())
00281 return false;
00282
00283 if(getEquation() != tother->getEquation())
00284 return false;
00285
00286 if(getBeacon() != tother->getBeacon())
00287 return false;
00288
00289 return true;
00290 }
00291
00292 bool ClipPlaneChunk::operator != (const StateChunk &other) const
00293 {
00294 return ! (*this == other);
00295 }
00296
00297
00298
00299
00300
00301 #ifdef OSG_SGI_CC
00302 #pragma set woff 1174
00303 #endif
00304
00305 #ifdef OSG_LINUX_ICC
00306 #pragma warning( disable : 177)
00307 #endif
00308
00309 namespace
00310 {
00311 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00312 static Char8 cvsid_hpp [] = OSGCLIPPLANECHUNK_HEADER_CVSID;
00313 static Char8 cvsid_inl [] = OSGCLIPPLANECHUNK_INLINE_CVSID;
00314
00315 static Char8 cvsid_fields_hpp[] = OSGCLIPPLANECHUNKFIELDS_HEADER_CVSID;
00316 }
00317
00318 #ifdef __sgi
00319 #pragma reset woff 1174
00320 #endif
00321