00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "face.h"
00020 #include "trigo.h"
00021 #include "controlEngine.h"
00022
00023 extern ControlEngine ce;
00024
00025
00026
00027 void Face::Set(char *_name,int _idControl,int _idFace,BOOL _view)
00028 {
00029 idControl = _idControl;
00030 idFace = _idFace;
00031 name = _name;
00032 view = _view;
00033 }
00034
00038 BOOL Face::ConfigDynamicLayout(Face *father,double xPosition,double yPosition,double xSize,double ySize)
00039 {
00040 if (!father) return FALSE;
00041 position.x.SetPercent(xPosition,&father->computeSize.x);
00042 position.y.SetPercent(yPosition,&father->computeSize.y);
00043 size.x.SetPercent(xSize,&father->computeSize.x);
00044 size.y.SetPercent(ySize,&father->computeSize.y);
00045 return TRUE;
00046 }
00047
00048 void Face::ConfigStaticLayout(double xPosition,double yPosition,double zPosition,double xSize,double ySize)
00049 {
00050 MoveTo(xPosition,yPosition,zPosition);
00051 size.x.constValue=xSize;
00052 size.y.constValue=ySize;
00053 }
00054
00055 void Face::ConfigCenter(int xCenter,int yCenter)
00056 {
00057 center.x=xCenter;
00058 center.y=xCenter;
00059 }
00060
00061 void Face::Move(double x,double y,double z)
00062 {
00063 position.x.constValue+=x;
00064 position.y.constValue+=y;
00065 position.z.constValue+=z;
00066 }
00067
00068 void Face::MoveTo(double x,double y,double z)
00069 {
00070 position.x.constValue=x;
00071 position.y.constValue=y;
00072 position.z.constValue=z;
00073 }
00074
00075 void Face::ComputeLayout()
00076 {
00077 computeSize.x = size.x.Compute()*scale.x;
00078 computeSize.y = size.y.Compute()*scale.y;
00079 computePosition.x = position.x.Compute()*scale.x;
00080 computePosition.y = position.y.Compute()*scale.y;
00081 computePosition.z = position.z.Compute();
00082
00083 switch (center.x)
00084 {
00085 case -1: computeCenter.x = -computeSize.x/2.0; break;
00086 case 0: computeCenter.x = 0; break;
00087 case 1: computeCenter.x = computeSize.x/2.0; break;
00088 }
00089 switch (center.y)
00090 {
00091 case -1: computeCenter.y = -computeSize.y/2.0; break;
00092 case 0: computeCenter.y = 0; break;
00093 case 1: computeCenter.y = computeSize.y/2.0; break;
00094 }
00095 }
00096
00109 void Face::Draw(BOOL onPicking)
00110 {
00111 GLdouble dx = computeSize.x/2.0;
00112 GLdouble dy = computeSize.y/2.0;
00113 if (!onPicking) material.Use();
00114 if (view)
00115 {
00116 if (onPicking)
00117 {
00118 if (noPicking) return;
00119 glPushName(idControl);
00120 glPushName(idFace);
00121 childRecorder.Play();
00122
00123 if (curve.IsActive())
00124 {
00125 glTranslated(-dx,dy,0);
00126 curve.Draw(computeSize,NULL);
00127 glTranslated(dx,-dy,0);
00128 }
00129 else
00130 {
00131 glBegin(GL_QUADS);
00132 glVertex2d(-dx,-dy);
00133 glVertex2d(dx,-dy);
00134 glVertex2d(dx,dy);
00135 glVertex2d(-dx,dy);
00136 glEnd();
00137 }
00138
00139 if (text)
00140 {
00141 text->SetClipping(computeSize);
00142 text->SetRatioXY(ratioXY);
00143 glTranslated(-dx,dy,0);
00144 text->DrawPicking();
00145 glTranslated(dx,-dy,0);
00146 }
00147
00148 glPopName();
00149 glPopName();
00150 }
00151 else
00152 {
00153 if (!fog&&ce.fog.isEnable) glDisable(GL_FOG);
00154
00155 if (texture)
00156 {
00157 glEnable(GL_TEXTURE_2D);
00158 glBindTexture(GL_TEXTURE_2D,texture->id);
00159 }
00160 else glDisable(GL_TEXTURE_2D);
00161 if (blending)
00162 {
00163 glEnable(GL_BLEND);
00164 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00165 }
00166 else glDisable(GL_BLEND);
00167
00168 childRecorder.Play();
00169
00170 if (ce.screenMain.region.enable)
00171 {
00172
00173 ce.RegionAdd(-dx,-dy);
00174 ce.RegionAdd(dx,-dy);
00175 ce.RegionAdd(dx,dy);
00176 ce.RegionAdd(-dx,dy);
00177 }
00178
00179
00180 if (curve.IsActive())
00181 {
00182 glTranslated(-dx,dy,0);
00183 curve.Draw(computeSize,texture);
00184 glTranslated(dx,-dy,0);
00185 }
00186 else
00187 {
00188 glBegin(GL_QUADS);
00189 if (texture)
00190 {
00191 texture->SetCoord(0,0); glVertex2d(-dx,-dy);
00192 texture->SetCoord(1,0); glVertex2d(dx,-dy);
00193 texture->SetCoord(1,1); glVertex2d(dx,dy);
00194 texture->SetCoord(0,1); glVertex2d(-dx,dy);
00195 }
00196 else
00197 {
00198 glVertex2d(-dx,-dy);
00199 glVertex2d(dx,-dy);
00200 glVertex2d(dx,dy);
00201 glVertex2d(-dx,dy);
00202 }
00203 glEnd();
00204 }
00205 if (!fog&&ce.fog.isEnable) glEnable(GL_FOG);
00206 if (texture) glDisable(GL_TEXTURE_2D);
00207 if (blending) glDisable(GL_BLEND);
00208
00209 if (text)
00210 {
00211
00212 text->SetClipping(computeSize);
00213 glPushAttrib(GL_LIGHTING_BIT);
00214 text->SetRatioXY(ratioXY);
00215 glTranslated(-dx,dy,0);
00216 text->Draw();
00217 glTranslated(dx,-dy,0);
00218 glPopAttrib();
00219 }
00220 }
00221 }
00222 else
00223 {
00224 if (!onPicking)
00225 {
00226 childRecorder.Play();
00227 }
00228 }
00229 if (!onPicking&&line)
00230 {
00231 if (antialias)
00232 {
00233 glEnable(GL_BLEND);
00234 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00235 }
00236 glPushAttrib(GL_LIGHTING_BIT);
00237 lineMaterial.Use();
00238 glLineWidth(line);
00239 glBegin(GL_LINE_LOOP);
00240 glVertex2d(-dx,-dy);
00241 glVertex2d(dx,-dy);
00242 glVertex2d(dx,dy);
00243 glVertex2d(-dx,dy);
00244 glEnd();
00245 glPopAttrib();
00246 if (antialias) glDisable(GL_BLEND);
00247 }
00248 }
00249
00251 void Face::MovingInside()
00252 {
00253 computePosition.glTranslated();
00254 angle.glRotated();
00255 glTranslated(computeCenter.x,computeCenter.y,0);
00256 }
00257
00259 void Face::GetCorners(Point3D<double> *corners)
00260 {
00261 GLdouble dx = computeSize.x/2.0;
00262 GLdouble dy = computeSize.y/2.0;
00263
00264 ce.RegionGet(-dx,-dy,&corners[0]);
00265 ce.RegionGet(dx,-dy,&corners[1]);
00266 ce.RegionGet(dx,dy,&corners[2]);
00267 ce.RegionGet(-dx,dy,&corners[3]);
00268 }
00269
00270
00271
00272 Face::Face()
00273 {
00274 Zero();
00275 }
00276
00277 Face::~Face()
00278 {
00279 }
00280
00281
00282
00283 void Face::Zero()
00284 {
00285 idFace = 0;
00286 childRecorder.Delete();
00287 idControl = 0;
00288 name = "";
00289
00290 size.Zero();
00291 center.Zero();
00292 position.Zero();
00293 computeSize.Zero();
00294 computeCenter.Zero();
00295 computePosition.Zero();
00296 angle.Zero();
00297 scale.Set(1,1,1);
00298 ratioXY = 1;
00299
00300 view = TRUE;
00301 blending = FALSE;
00302 antialias = TRUE;
00303 noPicking = FALSE;
00304 fog = TRUE;
00305 line = 0;
00306 lineMaterial.Zero();
00307
00308 texture = NULL;
00309 material.Zero();
00310 curve.Zero();
00311
00312 text = NULL;
00313 }
00314
00315
00316
00317 void Face::operator=(Face &src)
00318 {
00319 line = src.line;
00320 lineMaterial = src.lineMaterial;
00321 name = src.name;
00322 idFace = src.idFace;
00323 idControl = src.idControl;
00324
00325 fog = src.fog;
00326
00327 size=src.size;
00328 center=src.center;
00329 position=src.position;
00330 computeSize=src.computeSize;
00331 computeCenter=src.computeCenter;
00332 computePosition=src.computePosition;
00333 angle=src.angle;
00334 scale=src.scale;
00335 ratioXY = src.ratioXY;
00336
00337 view = src.view;
00338 blending = src.blending;
00339 noPicking = src.noPicking;
00340 antialias = src.antialias;
00341 texture = src.texture;
00342 material = src.material;
00343 curve = src.curve;
00344
00345 angle = src.angle;
00346 text = src.text;
00347 }
00348
00349