Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

region.cpp

Go to the documentation of this file.
00001 /* *************************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
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         // creation du tableau de points
00047         int nbPt = points.GetNbElem();
00048         int nbElem = nbPt/4;
00049         POINT *tabPoints = new POINT[nbPt+4]; // a voir: +4 sinon pb je sais pas pkoi!
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         // creation de la liste de taille des polygones
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         // normalisation des points
00069         ptrPoint = tabPoints-4;
00070         for (int i=0;i<nbElem;i++) NormalizeSens(ptrPoint+=4,4);
00071 
00072         // calcul des mins maxs
00073         if (computeMinMax)
00074         {
00075                 ptrPoint = tabPoints-4;
00076                 for (int i=0;i<nbElem;i++) SetMinMax(ptrPoint+=4,4);
00077         }
00078 
00079         // creation de la region
00080         hRgnBase = CreatePolyPolygonRgn(tabPoints,tabPoly,nbElem,WINDING);
00081         //hRgnBase = CreateRectRgn(xMin,yMin,xMax,yMax);
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         // determination du sens de rotation (3 points suffisent)
00098         BOOL sensTrigo = GetTrigoSens(tabPoints);
00099         // si sens non trigonometrique change les points de sens sinon CreatePolyPolygonRgn fait un NON OR
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 }

Generated on Fri Aug 20 19:19:49 2004 for 3d Controls by doxygen 1.3.6