00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "curve.h"
00020
00021 Curve::Curve()
00022 {
00023 tabQuads = NULL;
00024 tabSommets = NULL;
00025 tabCoorTextures = NULL;
00026 Zero();
00027 }
00028
00029 Curve::~Curve()
00030 {
00031 UnAlloc();
00032 }
00033 void Curve::Zero()
00034 {
00035 UnAlloc();
00036 nbCut.Set(1,1);
00037 center.Set(0.5,0.5);
00038 numList=0;
00039 }
00040
00041 void Curve::operator=(Curve &source)
00042 {
00043 nbCut = source.nbCut;
00044 center = source.center;
00045 oldCenter = source.oldCenter;
00046 oldNbCut = source.oldNbCut;
00047 }
00048
00049 BOOL Curve::Set(GLdouble zCenter,int nbCutXY)
00050 {
00051 if (nbCutXY<0) return FALSE;
00052 nbCut.Set(nbCutXY,nbCutXY);
00053 center.Set(0.5,0.5,zCenter);
00054 return TRUE;
00055 }
00056
00057 BOOL Curve::Set(GLdouble zCenter,int nbCutX,int nbCutY)
00058 {
00059 if ((nbCutX<0)||(nbCutY<0)) return FALSE;
00060 nbCut.Set(nbCutX,nbCutY);
00061 center.Set(0.5,0.5,zCenter);
00062 return TRUE;
00063 }
00064
00065 BOOL Curve::IsActive()
00066 {
00067 return ((nbCut.x>1)||(nbCut.y>1))?TRUE:FALSE;
00068 }
00069
00076 BOOL Curve::Draw(Point2D<double> size,Texture *texture)
00077 {
00078 if (!IsActive()) return FALSE;
00079 glBegin(GL_QUADS);
00080 GLdouble cdx = 1.0/(GLdouble)nbCut.x;
00081 GLdouble cdy = 1.0/(GLdouble)nbCut.y;
00082 BOOL noCutX = nbCut.x==1?TRUE:FALSE;
00083 BOOL noCutY = nbCut.y==1?TRUE:FALSE;
00084 GLdouble px = 0;
00085 GLdouble py = 0;
00086 GLdouble z1,z2,z3,z4;
00087 for (int x=0;x<nbCut.x;x++)
00088 {
00089 for (int y=0;y<nbCut.y;y++)
00090 {
00091 #define f(value) sin(PI*(value))
00092 #define fxy(value,center) ((value<center)?sin((HALF_PI/center)*(value)):cos((HALF_PI/(1-center))*((value)-center)))
00093 #define fx(value) fxy(value,center.x)
00094 #define fy(value) fxy(value,center.y)
00095 if (noCutX)
00096 {
00097 z1 = fy(py)*center.z;
00098 z2 = fy(py)*center.z;
00099 z3 = fy(py+cdy)*center.z;
00100 z4 = fy(py+cdy)*center.z;
00101 }
00102 else if (noCutY)
00103 {
00104 z1 = fx(px)*center.z;
00105 z2 = fx(px+cdx)*center.z;
00106 z3 = fx(px+cdx)*center.z;
00107 z4 = fx(px)*center.z;
00108 }
00109 else
00110 {
00111 z1 = (fx(px)*fy(py))*center.z;
00112 z2 = (fx(px+cdx)*fy(py))*center.z;
00113 z3 = (fx(px+cdx)*fy(py+cdy))*center.z;
00114 z4 = (fx(px)*fy(py+cdy))*center.z;
00115 }
00116 GLdouble x1 = px*size.x;
00117 GLdouble y1 = py*size.y-size.y;
00118 GLdouble x2 = (px+cdx)*size.x;
00119 GLdouble y2 = (py+cdy)*size.y-size.y;
00120
00121 if (texture)
00122 {
00123 texture->SetCoord(px,py);
00124 glVertex3d(x1,y1,z1);
00125 texture->SetCoord(px+cdx,py);
00126 glVertex3d(x2,y1,z2);
00127 texture->SetCoord(px+cdx,py+cdy);
00128 glVertex3d(x2,y2,z3);
00129 texture->SetCoord(px,py+cdy);
00130 glVertex3d(x1,y2,z4);
00131 }
00132 else
00133 {
00134 glVertex3d(x1,y1,z1);
00135 glVertex3d(x2,y1,z2);
00136 glVertex3d(x2,y2,z3);
00137 glVertex3d(x1,y2,z4);
00138 }
00139 py+=cdy;
00140 }
00141 px+=cdx;
00142 py=0;
00143 }
00144 glEnd();
00145 return TRUE;
00146 }
00147
00148
00149
00156 void Curve::Refresh()
00157 {
00158 nbCut.Set(-1,-1);
00159 }
00160
00161 void Curve::UnAlloc()
00162 {
00163 if (tabQuads) delete tabQuads;
00164 if (tabSommets) delete tabSommets;
00165 if (tabCoorTextures) delete tabCoorTextures;
00166 tabQuads = NULL;
00167 tabSommets = NULL;
00168 tabCoorTextures = NULL;
00169 }
00170
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272