gfx.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        gfx.h
00012 // DESCRIPTION: main graphics system include file.
00013 // AUTHOR:      Don Brittain
00014 // HISTORY:     
00015 //**************************************************************************/
00016 #pragma once
00017 
00018 #include "maxheap.h"
00019 #include "geomlib.h"
00020 #include "export.h"
00021 #include "tab.h"
00022 #include "mtl.h"
00023 #include "BaseInterface.h"
00024 #include "HWMesh.h"
00025 #include "MeshFaceFlagConstants.h"
00026 #include "GraphicsConstants.h"
00027 #include "GraphicsTypes.h"
00028 #include "GraphicsViewPortColorConstants.h"
00029 #include "maxtypes.h"
00030 #include "TabTypes.h"
00031 #include "LightTypeEnums.h"
00032 #include "Strip.h"
00033 #include "GraphicsWindow.h"
00034 
00036 class VertexBuffer: public MaxHeapOperators {
00037 public:
00038     Point3  position;
00039     DWORD       color;
00040 };
00041 
00043 class LineBuffer: public MaxHeapOperators {
00044 public:
00045     Point3  position;
00046     DWORD       color;
00047 };
00048 
00050 class GWFace: public MaxHeapOperators {
00051 public:
00052     DWORD   v[3];   //< indexed references to the vertex array
00053     DWORD   flags;  
00054 };
00055 
00059 class Light : public BaseInterfaceServer {
00060 public:
00062     DllExport Light();
00063     
00069     LightType       type; 
00070 
00072     Point3          color;
00073 
00075     int             attenType;
00076 
00078     float           attenStart;
00079 
00081     float           attenEnd;
00082 
00084     float           intensity;
00085 
00087     float           hotSpotAngle;
00088 
00090     float           fallOffAngle;
00091 
00095     int             shape;
00096 
00098     float           aspect;
00099     
00101     int             overshoot;
00102 
00106     BOOL            affectDiffuse;
00107     
00111     BOOL            affectSpecular;
00112 };
00113 
00115 class Camera : public BaseInterfaceServer {
00116 public:
00117     DllExport Camera();
00118 
00119 
00121     void            setPersp(float f, float asp)
00122                         { type = PERSP_CAM; persp.fov = f; 
00123                           persp.aspect = asp; makeMatrix(); }
00124 
00126     void            setOrtho(float l, float t, float r, float b)
00127                         { type = ORTHO_CAM; ortho.left = l; ortho.top = t; 
00128                           ortho.right = r; ortho.bottom = b; makeMatrix(); }
00129     
00131     void            setClip(float h, float y) 
00132                         { hither = h; yon = y; makeMatrix(); }
00133     
00135     CameraType      getType(void)   { return type; }
00136 
00138     float           getHither(void) { return hither; }
00139 
00141     float           getYon(void)    { return yon; }
00142 
00144     DllExport void  reset();
00145 
00147     DllExport void  getProj(float mat[4][4]);
00148 private:
00149     DllExport void  makeMatrix();
00150     float           proj[4][4];
00151     CameraType      type;
00152     union {
00153         struct : public MaxHeapOperators {
00154             float   fov;
00155             float   aspect;
00156         } persp;
00157         struct : public MaxHeapOperators {
00158             float   left;
00159             float   right;
00160             float   bottom;
00161             float   top;
00162         } ortho;
00163     };
00164     float           hither;
00165     float           yon;
00166 };
00167 
00169 
00170 
00171 DllExport void  setAutoCross(int onOff);
00173 DllExport int   getAutoCross();
00175 DllExport void  setAutoCrossDir(int dir);
00177 DllExport int   getAutoCrossDir();
00179 
00181 struct CIRCLE: public MaxHeapOperators
00182 {
00183     LONG  x; //< X coordinates of circle.
00184     LONG  y; //< Y coordinates of circle
00185     LONG  r; //< Radius of circle.
00186 };
00187 
00191 class HitRegion: public MaxHeapOperators {
00192     DWORD size;
00193 public:
00200     int             type;
00201 
00203     int             dir;        // region direction
00204 
00209     int             crossing;   
00210 
00216     int             epsilon;    
00217 
00219     union {
00220         POINT       pt;
00221         RECT        rect;
00222         CIRCLE      circle;
00223         POINT *     pts;
00224     };
00225 
00226     HitRegion()     { dir = RGN_DIR_UNDEF; size = sizeof(HitRegion);}
00227 };
00228 
00229 #ifndef ABS
00230 
00231 inline int ABS(const int x) { return (x > 0) ? x : -x; }
00232 #endif
00233 
00239 class GWinSetup: public MaxHeapOperators {
00240 public:
00241     DllExport GWinSetup();
00242     MCHAR       caption[GW_MAX_CAPTION_LEN];
00243     MCHAR       renderer[GW_MAX_FILE_LEN];
00244     MCHAR       device[GW_MAX_FILE_LEN];
00245     DWORD       winStyle;
00246     POINT       size;
00247     POINT       place;
00248     INT_PTR     id;
00249     int         type;
00250     bool        quietMode;
00251 };
00252 
00255 inline int wIsFacingBack(const IPoint3 &v0, const IPoint3 &v1, const IPoint3 &v2, int flip=0 )
00256 {
00257     int s = ( (v0[0]-v1[0])*(v2[1]-v1[1]) - (v2[0]-v1[0])*(v0[1]-v1[1]) ) < 0;
00258     return flip ? !s : s;
00259 }
00260 
00263 inline int hIsFacingBack(const IPoint3 &v0, const IPoint3 &v1, const IPoint3 &v2, int flip=0 )
00264 {
00265     int s = ( (v0[0]-v1[0])*(v2[1]-v1[1]) - (v2[0]-v1[0])*(v0[1]-v1[1]) );
00266     return flip ? s < 0 : s > 0;
00267 }
00268 
00277 inline FacingType wFacingType(const IPoint3 &v0, const IPoint3 &v1, const IPoint3 &v2, int flip=0 )
00278 {
00279     int s = ( (v0[0]-v1[0])*(v2[1]-v1[1]) - (v2[0]-v1[0])*(v0[1]-v1[1]) );
00280     return (s == 0) ? kSideFacing : ((flip ? s > 0 : s < 0) ? kBackFacing : kFrontFacing);
00281 }
00282 
00291 inline FacingType hFacingType(const IPoint3 &v0, const IPoint3 &v1, const IPoint3 &v2, int flip=0 )
00292 {
00293     int s = ( (v0[0]-v1[0])*(v2[1]-v1[1]) - (v2[0]-v1[0])*(v0[1]-v1[1]) );
00294     return (s == 0) ? kSideFacing : ((flip ? s < 0 : s > 0) ? kBackFacing : kFrontFacing);
00295 }
00296 
00298 DllExport HINSTANCE GetGraphicsLibHandle(MCHAR *driverLibName);
00299 
00301 DllExport BOOL GraphicsSystemIsAvailable(HINSTANCE drv);
00302 
00304 DllExport BOOL GraphicsSystemCanConfigure(HINSTANCE drv);
00305 
00307 DllExport BOOL GraphicsSystemConfigure(HWND hWnd, HINSTANCE drv);
00308 
00310 DllExport void FreeGraphicsLibHandle(HINSTANCE drv);
00311 
00314 DllExport GraphicsWindow* createGW(HWND hWnd, GWinSetup &gws);
00315 
00321 DllExport void getRegionRect(HitRegion *hr, RECT *rect);
00322 
00324 DllExport BOOL pointInRegion(int x, int y, HitRegion *hr);
00325 
00327 DllExport int distToLine(int x, int y, int *p1, int *p2);
00328 
00335 DllExport int zDepthToLine(int x, int y, int *p1, int *p2);
00336 
00338 DllExport int lineCrossesRect(RECT *rc, int *p1, int *p2);
00339 
00341 DllExport int segCrossesRect(RECT *rc, int *p1, int *p2);
00342 
00345 DllExport int segCrossesCircle(int cx, int cy, int r, int *p1, int *p2);
00346 
00355 DllExport BOOL insideTriangle(IPoint3 &p0, IPoint3 &p1, IPoint3 &p2, IPoint3 &q);
00356 
00365 DllExport int getZfromTriangle(IPoint3 &p0, IPoint3 &p1, IPoint3 &p2, IPoint3 &q);
00366 
00368 DllExport int getClosestPowerOf2(int num);
00369 
00381 DllExport Point3 GetUIColor(int which);
00386 DllExport void SetUIColor(int which, Point3 *clr);
00391 DllExport Point3 GetDefaultUIColor(int which);
00393 #define GetSelColor()       GetUIColor(COLOR_SELECTION)
00394 
00395 #define GetSubSelColor()    GetUIColor(COLOR_SUBSELECTION)
00396 
00397 #define GetFreezeColor()    GetUIColor(COLOR_FREEZE)
00398