00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "3d.h"
00020 #include "cursor.h"
00021
00022 #include "controlEngine.h"
00023 extern ControlEngine ce;
00024
00025
00026
00027 void Config(Face *face,double dx,double dy,float alpha)
00028 {
00029 face->size.x=dx;
00030 face->size.y=dy;
00031 face->blending=TRUE;
00032 face->noPicking=TRUE;
00033 face->material.SetDS(1,1,1,alpha);
00034 Face *faceMC = ce.masterContainer->faceNode->elem;
00035 face->position.x.SetPercent(-0.5,&faceMC->computeSize.x);
00036 face->position.y.SetPercent(0.5,&faceMC->computeSize.y);
00037 }
00038
00039 Cursor::Cursor()
00040 {
00041 curType=cursorArrow;
00042 leftType=cursorNothing;
00043 rightType=cursorNothing;
00044 midType=cursorNothing;
00045 }
00046
00047 void Cursor::Create()
00048 {
00049 recorderRepere.BeginRecord(FALSE);
00050 DrawRepere();
00051 recorderRepere.EndRecord();
00052
00053 Config(&curFace,32,32,1);
00054 Config(&leftFace,16,16,0.5f);
00055 Config(&midFace,16,16,0.5f);
00056 Config(&leftFace,16,16,0.5f);
00057 ApplyTypes();
00058 }
00059
00060 void Cursor::Draw(double x,double y)
00061 {
00062 glDisable(GL_DEPTH_TEST);
00063 glDepthMask(GL_FALSE);
00064 y=-y;
00065
00066 glPushMatrix();
00067 curFace.MoveTo(x,y,0);
00068 curFace.ComputeLayout();
00069 curFace.MovingInside();
00070 curFace.Draw(FALSE);
00071 glPopMatrix();
00072
00073 glPushMatrix();
00074 leftFace.MoveTo(x-16,y-16,0);
00075 leftFace.ComputeLayout();
00076 leftFace.MovingInside();
00077 leftFace.Draw(FALSE);
00078 glPopMatrix();
00079
00080 glPushMatrix();
00081 midFace.MoveTo(x,y-16,0);
00082 midFace.ComputeLayout();
00083 midFace.MovingInside();
00084 midFace.Draw(FALSE);
00085 glPopMatrix();
00086
00087 glPushMatrix();
00088 rightFace.MoveTo(x+16,y-16,0);
00089 rightFace.ComputeLayout();
00090 rightFace.MovingInside();
00091 rightFace.Draw(FALSE);
00092 glPopMatrix();
00093
00094 glDepthMask(GL_TRUE);
00095 glEnable(GL_DEPTH_TEST);
00096 }
00097
00098 Point2D<int> Cursor::GetHotSpot(CursorType type)
00099 {
00100 Point2D<int> hotSpot;
00101 switch (type)
00102 {
00103 case cursorArrow: hotSpot.Set(11,10); break;
00104 case cursorPush: hotSpot.Set(11,10); break;
00105
00106
00107
00108
00109
00110
00111 }
00112 return hotSpot;
00113 }
00114
00115 void Cursor::ApplyTypes(CursorType current,CursorType left,CursorType mid,CursorType right)
00116 {
00117 if (current!=cursorNoChange) curType=current;
00118 if (left!=cursorNoChange) leftType=left;
00119 if (mid!=cursorNoChange) midType=mid;
00120 if (right!=cursorNoChange) rightType=right;
00121 ApplyType(&curFace,curType);
00122 ApplyType(&leftFace,leftType);
00123 ApplyType(&midFace,midType);
00124 ApplyType(&rightFace,rightType);
00125 }
00126
00127 void Cursor::ApplyType(Face *face,CursorType type)
00128 {
00129 face->view = TRUE;
00130 if (type!=cursorRepere) face->childRecorder.Zero();
00131 switch (type)
00132 {
00133 case cursorNothing: face->view = FALSE; break;
00134 case cursorArrow: face->texture = &ce.texture.cursorArrow; break;
00135 case cursorWait: face->texture = &ce.texture.cursorWait; break;
00136 case cursorPush: face->texture = &ce.texture.cursorPush; break;
00137 case cursorText: face->texture = &ce.texture.cursorText; break;
00138 case cursorMoving: face->texture = &ce.texture.cursorMoving; break;
00139 case cursorRepere: face->view = FALSE; face->childRecorder=recorderRepere; break;
00140 }
00141 }
00142
00143 void Cursor::Rotate(Face *face,CursorType type,Point3D<double> angle)
00144 {
00145 switch (type)
00146 {
00147 case cursorRepere: face->angle=angle; break;
00148 default: face->angle.Zero();
00149 }
00150 }
00151 void Cursor::Rotate(Point3D<double> angle)
00152 {
00153 Rotate(&curFace,curType,angle);
00154 Rotate(&leftFace,leftType,angle);
00155 Rotate(&midFace,midType,angle);
00156 Rotate(&rightFace,rightType,angle);
00157 }
00158
00159 BOOL Cursor::DrawVectorMinMax(double x,double y,double minIntensity,double maxIntensity)
00160 {
00161 double intensity = sqrt(x*x+y*y);
00162
00163
00164 if (intensity<minIntensity) return FALSE;
00165 if (intensity>maxIntensity)
00166 {
00167 double angle=atan2(y,-x);
00168 x=cos(angle)*maxIntensity;
00169 y=sin(angle)*maxIntensity;
00170 }
00171 DrawVector(x,y);
00172 return TRUE;
00173 }
00174
00179 void Cursor::DrawVector(double x,double y)
00180 {
00181 glDisable(GL_TEXTURE_2D);
00182
00183
00184 double angle=atan2(y,-x)*(180.0/PI);
00185 double intensity = sqrt(x*x+y*y)/25.0;
00186
00187 Point3D<double> rotate(0,0,angle);
00188
00189 Material material;
00190 material.SetNull();
00191
00192 material.emission.Set(0,0,1);
00193 material.Use();
00194
00195 glPushMatrix();
00196 rotate.glRotated();
00197 glBegin(GL_POLYGON);
00198 glVertex2d(0,0);
00199 glVertex2d(intensity,0);
00200 glVertex2d(intensity-0.05,-0.05);
00201 glVertex2d(intensity-0.05,0.05);
00202 glVertex2d(intensity,0);
00203 glEnd();
00204 glPopMatrix();
00205
00206 }
00207
00208 void Cursor::DrawArrow(Color color)
00209 {
00210 glDisable(GL_BLEND);
00211 glDisable(GL_TEXTURE_2D);
00212 Material material;
00213
00214 material.SetNull();
00215 material.emission = color;
00216 material.Use();
00217
00218
00219 glBegin(GL_POLYGON);
00220 glVertex2d(0,0);
00221 glVertex2d(0,-0.2);
00222 glVertex2d(0.05,-0.15);
00223 glVertex2d(0.12,-0.3);
00224 glVertex2d(0.20,-0.22);
00225 glVertex2d(0.10,-0.10);
00226 glVertex2d(0.15,-0.06);
00227 glVertex2d(0,0);
00228 glEnd();
00229
00230
00231 material.emission.SetNull();
00232 material.Use();
00233 glBegin(GL_LINE_LOOP);
00234 glVertex2d(0,0);
00235 glVertex2d(0,-0.2);
00236 glVertex2d(0.05,-0.15);
00237 glVertex2d(0.12,-0.3);
00238 glVertex2d(0.2,-0.22);
00239 glVertex2d(0.10,-0.10);
00240 glVertex2d(0.15,-0.06);
00241 glEnd();
00242 }
00243
00244
00245
00246 void Cursor::DrawRepere()
00247 {
00248 Material material;
00249 glDisable(GL_BLEND);
00250 glDisable(GL_TEXTURE_2D);
00251
00252 material.SetNull();
00253
00254 GLUquadric *newQuadric = gluNewQuadric();
00255 gluQuadricNormals(newQuadric,GLU_NONE);
00256 double size=0.6;
00257 double baseSize=8;
00258 double arrowSize=6;
00259 double baseArrowSize=3;
00260
00261 glPushMatrix();
00262 material.emission.Set(1,0,0);
00263 material.Use();
00264 gluCylinder(newQuadric,size,size,baseSize,3,3);
00265 glTranslated(0,0,baseSize);
00266 gluCylinder(newQuadric,baseArrowSize,0,arrowSize,3,3);
00267
00268
00269 glPopMatrix();
00270
00271 glPushMatrix();
00272 material.emission.Set(0,1,0);
00273 material.Use();
00274 glRotated(-90,1,0,0);
00275 gluCylinder(newQuadric,size,size,baseSize,3,3);
00276 glTranslated(0,0,baseSize);
00277 gluCylinder(newQuadric,baseArrowSize,0,arrowSize,3,3);
00278
00279
00280 glPopMatrix();
00281
00282 glPushMatrix();
00283 material.emission.Set(0,0,1);
00284 material.Use();
00285 glRotated(90,0,1,0);
00286 gluCylinder(newQuadric,size,size,baseSize,3,3);
00287 glTranslated(0,0,baseSize);
00288 gluCylinder(newQuadric,baseArrowSize,0,arrowSize,3,3);
00289
00290
00291 glPopMatrix();
00292
00293 gluDeleteQuadric(newQuadric);
00294
00295 material.emission.SetNull();
00296 material.Use();
00297 }
00298
00300
00301 void Cursor::DrawText(char *text)
00302 {
00303
00304 }