OSGClipPlaneChunk.cpp
Go to the documentation of this file.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 <cstdlib>
00044 #include <cstdio>
00045
00046 #include "OSGConfig.h"
00047
00048 #include "OSGGL.h"
00049
00050 #include "OSGCamera.h"
00051 #include "OSGDrawEnv.h"
00052
00053 #include "OSGClipPlaneChunk.h"
00054
00055 OSG_USING_NAMESPACE
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 StateChunkClass ClipPlaneChunk::_class("ClipPlane", 6);
00067
00068 void ClipPlaneChunk::initMethod(InitPhase ePhase)
00069 {
00070 Inherited::initMethod(ePhase);
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 ClipPlaneChunk::ClipPlaneChunk(void) :
00084 Inherited()
00085 {
00086 }
00087
00088 ClipPlaneChunk::ClipPlaneChunk(const ClipPlaneChunk &source) :
00089 Inherited(source)
00090 {
00091 }
00092
00093 ClipPlaneChunk::~ClipPlaneChunk(void)
00094 {
00095 }
00096
00097
00098
00099 const StateChunkClass *ClipPlaneChunk::getClass(void) const
00100 {
00101 return &_class;
00102 }
00103
00104
00105
00106 void ClipPlaneChunk::changed(ConstFieldMaskArg whichField,
00107 UInt32 origin,
00108 BitVector details)
00109 {
00110 Inherited::changed(whichField, origin, details);
00111 }
00112
00113
00114
00115 void ClipPlaneChunk::dump( UInt32 ,
00116 const BitVector) const
00117 {
00118 SLOG << "Dump ClipPlaneChunk NI" << std::endl;
00119 }
00120
00121
00122
00123
00124 void ClipPlaneChunk::activate(DrawEnv *pEnv, UInt32 idx)
00125 {
00126 Matrix beaconMat;
00127
00128 Matrix cameraMat = pEnv->getCameraViewing();
00129
00130 if(getBeacon() != NULL)
00131 {
00132 getBeacon()->getToWorld(beaconMat);
00133 }
00134 else
00135 {
00136 beaconMat.setIdentity();
00137
00138 SWARNING << "NO beacon" << std::endl;
00139 }
00140
00141 cameraMat.mult(beaconMat);
00142
00143 if(getEnable() == true)
00144 {
00145 GLdouble glEq[4];
00146 const Vec4f &eq = getEquation();
00147
00148 glEq[0] = eq[0];
00149 glEq[1] = eq[1];
00150 glEq[2] = eq[2];
00151 glEq[3] = eq[3];
00152
00153 glPushMatrix();
00154 glLoadMatrixf(cameraMat.getValues());
00155
00156 glClipPlane( GL_CLIP_PLANE0 + idx, glEq);
00157 glEnable( GL_CLIP_PLANE0 + idx);
00158
00159 glPopMatrix();
00160 }
00161 }
00162
00163
00164
00165
00166 void ClipPlaneChunk::changeFrom(DrawEnv *pEnv,
00167 StateChunk *old_chunk,
00168 UInt32 idx)
00169 {
00170 ClipPlaneChunk const *old = dynamic_cast<ClipPlaneChunk const*>(old_chunk);
00171
00172
00173
00174
00175
00176 if(old == this)
00177 return;
00178
00179 Matrix beaconMat;
00180
00181 Matrix cameraMat = pEnv->getCameraViewing();
00182
00183 if(getBeacon() != NULL)
00184 {
00185 getBeacon()->getToWorld(beaconMat);
00186 }
00187 else
00188 {
00189 beaconMat.setIdentity();
00190
00191 SWARNING << "ClipPlaneChunk::changeFrom: NO beacon" << std::endl;
00192 }
00193
00194 cameraMat.mult(beaconMat);
00195
00196 if(getEnable() != old->getEnable() ||
00197 getBeacon() != old->getBeacon() )
00198 {
00199 if(getEnable() == true)
00200 {
00201 GLdouble glEq[4];
00202
00203 const Vec4f &eq = getEquation();
00204
00205 glEq[0] = eq[0];
00206 glEq[1] = eq[1];
00207 glEq[2] = eq[2];
00208 glEq[3] = eq[3];
00209
00210 glPushMatrix();
00211 glLoadMatrixf(cameraMat.getValues());
00212
00213 glClipPlane(GL_CLIP_PLANE0 + idx, glEq);
00214 glEnable (GL_CLIP_PLANE0 + idx );
00215
00216 glPopMatrix();
00217 }
00218 else
00219 {
00220 glDisable(GL_CLIP_PLANE0 + idx);
00221 }
00222 }
00223 }
00224
00225
00226 void ClipPlaneChunk::deactivate(DrawEnv *, UInt32 idx)
00227 {
00228 if(getEnable() == true)
00229 {
00230 glDisable( GL_CLIP_PLANE0 + idx);
00231 }
00232 }
00233
00234
00235
00236
00237 Real32 ClipPlaneChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00238 {
00239 return 0;
00240 }
00241
00242 bool ClipPlaneChunk::operator < (const StateChunk &other) const
00243 {
00244 return this < &other;
00245 }
00246
00247 bool ClipPlaneChunk::operator == (const StateChunk &other) const
00248 {
00249 ClipPlaneChunk const *tother = dynamic_cast<ClipPlaneChunk const*>(&other);
00250
00251 if(!tother)
00252 return false;
00253
00254 if(getEnable() != tother->getEnable())
00255 return false;
00256
00257 if(getEquation() != tother->getEquation())
00258 return false;
00259
00260 if(getBeacon() != tother->getBeacon())
00261 return false;
00262
00263 return true;
00264 }
00265
00266 bool ClipPlaneChunk::operator != (const StateChunk &other) const
00267 {
00268 return ! (*this == other);
00269 }