00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "3d.h"
00020 #include "region.h"
00021
00022 Region::Region()
00023 {
00024 enable = FALSE;
00025 computeMinMax = FALSE;
00026 Reset();
00027 }
00028
00029 void Region::Reset(int deltaXwin,int deltaYwin)
00030 {
00031 points.i.SuprAll();
00032 xMin=deltaXwin;
00033 yMin=deltaYwin;
00034 zMin=10000;
00035 xMax=0;
00036 yMax=0;
00037 zMax=0;
00038 nbOr = 0;
00039 hRgnBase = NULL;
00040 }
00041
00042 BOOL Region::Use(HWND hWnd)
00043 {
00044 if (!enable) return FALSE;
00045
00046
00047 int nbPt = points.GetNbElem();
00048 int nbElem = nbPt/4;
00049 POINT *tabPoints = new POINT[nbPt+4];
00050 if (!tabPoints) return FALSE;
00051 POINT *ptrPoint = tabPoints;
00052 for (points.i=0;points.i.More();points.i++)
00053 {
00054 Point3D<double> *pt = points.i();
00055 ptrPoint->x=(LONG)pt->x;
00056 ptrPoint->y=(LONG)pt->y;
00057 ptrPoint++;
00058 }
00059
00060 int *tabPoly = new int[nbElem];
00061 if (!tabPoly)
00062 {
00063 delete tabPoints;
00064 return FALSE;
00065 }
00066 for (int i=0;i<nbElem;i++) tabPoly[i]=4;
00067
00068
00069 ptrPoint = tabPoints-4;
00070 for (int i=0;i<nbElem;i++) NormalizeSens(ptrPoint+=4,4);
00071
00072
00073 if (computeMinMax)
00074 {
00075 ptrPoint = tabPoints-4;
00076 for (int i=0;i<nbElem;i++) SetMinMax(ptrPoint+=4,4);
00077 }
00078
00079
00080 hRgnBase = CreatePolyPolygonRgn(tabPoints,tabPoly,nbElem,WINDING);
00081
00082 if (!hRgnBase)
00083 {
00084 delete []tabPoints;
00085 delete []tabPoly;
00086 return FALSE;
00087 }
00088 SetWindowRgn(hWnd,hRgnBase,TRUE);
00089 delete []tabPoints;
00090 delete []tabPoly;
00091 DeleteObject(hRgnBase);
00092 return TRUE;
00093 }
00094
00095 void Region::NormalizeSens(POINT *tabPoints,int nbPt)
00096 {
00097
00098 BOOL sensTrigo = GetTrigoSens(tabPoints);
00099
00100 if (!sensTrigo) ChangeTrigoSens(tabPoints,nbPt);
00101 }
00102
00103 void Region::SetMinMax(POINT *tabPoints,int nbPt)
00104 {
00105 for (int i=0;i<nbPt;i++)
00106 {
00107 xMin = min(xMin,tabPoints->x);
00108 xMax = max(xMax,tabPoints->x);
00109 yMin = min(yMin,tabPoints->y);
00110 yMax = max(yMax,tabPoints->y);
00111 tabPoints++;
00112 }
00113 }
00114
00115 BOOL Region::AddElem(Point2D<GLdouble> pos,GLdouble *modelMatrix,GLdouble *projMatrix,GLint *viewPort)
00116 {
00117 Point3D<double> *pt = points.i.AddNewLast();
00118 return Compute(pos,modelMatrix,projMatrix,viewPort,pt);
00119 return TRUE;
00120 }
00121
00122 BOOL Region::Compute(Point2D<GLdouble> pos,GLdouble *modelMatrix,GLdouble *projMatrix,GLint *viewPort,Point3D<double> *pt)
00123 {
00124 gluProject(pos.x,pos.y,0,modelMatrix,projMatrix,viewPort,&pt->x,&pt->y,&pt->z);
00125 pt->y=viewPort[3]-pt->y;
00126 return TRUE;
00127 }