![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * O p e n G L V i e w e r W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2002 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXGLViewer.h,v 1.50 2002/01/18 22:42:53 jeroen Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXGLVIEWER_H 00025 #define FXGLVIEWER_H 00026 00027 #ifndef FXGLCANVAS_H 00028 #include "FXGLCanvas.h" 00029 #endif 00030 00031 00032 00033 class FXDCPrint; 00034 class FXGLObject; 00035 00036 00037 // Pick tolerance 00038 #define PICK_TOL 3 00039 00040 00041 // GL Viewer options 00042 enum { 00043 VIEWER_LOCKED = 0x00008000, /// Mouse based view manipulation is locked 00044 VIEWER_LIGHTING = 0x00010000, /// Lighting is on 00045 VIEWER_FOG = 0x00020000, /// Fog mode on 00046 VIEWER_DITHER = 0x00040000 /// Dithering 00047 }; 00048 00049 00050 /******************************* Viewer Structs *****************************/ 00051 00052 00053 /// OpenGL Viewer Viewport 00054 struct FXViewport { 00055 FXint w,h; // Viewport dimensions 00056 FXdouble left,right; // World box 00057 FXdouble bottom,top; 00058 FXdouble hither,yon; 00059 }; 00060 00061 00062 // OpenGL Light Source 00063 struct FXAPI FXLight { 00064 FXHVec ambient; // Ambient light color 00065 FXHVec diffuse; // Diffuse light color 00066 FXHVec specular; // Specular light color 00067 FXHVec position; // Light position 00068 FXVec direction; // Spot direction 00069 FXfloat exponent; // Spotlight exponent 00070 FXfloat cutoff; // Spotlight cutoff angle 00071 FXfloat c_attn; // Constant attenuation factor 00072 FXfloat l_attn; // Linear attenuation factor 00073 FXfloat q_attn; // Quadratic attenuation factor 00074 }; 00075 00076 00077 // OpenGL Material Description 00078 struct FXAPI FXMaterial { 00079 FXHVec ambient; // Ambient material color 00080 FXHVec diffuse; // Diffuse material color 00081 FXHVec specular; // Specular material color 00082 FXHVec emission; // Emissive material color 00083 FXfloat shininess; // Specular shininess 00084 }; 00085 00086 00087 // Feedback buffer sort routine 00088 typedef FXbool (*FXZSortFunc)(FXfloat*& buffer,FXint& used,FXint& size); 00089 00090 00091 /******************************** Viewer Class ******************************/ 00092 00093 00094 /// Canvas, an area drawn by another object 00095 class FXAPI FXGLViewer : public FXGLCanvas { 00096 FXDECLARE(FXGLViewer) 00097 friend class FXGLObject; 00098 protected: 00099 FXViewport wvt; // Window viewport transform 00100 FXHMat transform; // Current transformation matrix 00101 FXHMat itransform; // Inverse of current transformation matrix 00102 FXuint projection; // Projection mode 00103 FXQuat rotation; // Viewer orientation 00104 FXdouble fov; // Field of view 00105 FXdouble zoom; // Zoom factor 00106 FXdouble offset; // Offset for lines on surfaces 00107 FXVec center; // Model center 00108 FXVec scale; // Model scale 00109 FXdouble worldpx; // Pixel size in world 00110 FXdouble modelpx; // Pixel size in model 00111 FXuint op; // Operation being performed 00112 FXint maxhits; // Maximum number of hits 00113 FXdouble ax,ay; // Quick view->world coordinate mapping 00114 FXdouble diameter; // Size of model diameter ( always > 0) 00115 FXdouble distance; // Distance of PRP to target 00116 FXHVec background; // Background color 00117 FXHVec ambient; // Global ambient light 00118 FXLight light; // Light source 00119 FXMaterial material; // Base material properties 00120 FXint dial[3]; // Dial positions 00121 FXTimer *timer; // Motion timer 00122 FXString help; // Status help 00123 FXString tip; // Tooltip for background 00124 FXbool doesturbo; // Doing turbo mode 00125 FXbool turbomode; // Turbo mode 00126 FXGLObject *dropped; // Object being dropped on 00127 FXGLObject *selection; // Current object 00128 FXZSortFunc zsortfunc; // Routine to sort feedback buffer 00129 FXGLObject *scene; // What we're looking at 00130 public: 00131 00132 // Common DND types 00133 static FXDragType objectType; // GL Object type 00134 00135 protected: 00136 00137 // Mouse actions when in viewing window 00138 enum { 00139 HOVERING, // Hovering mouse w/o doing anything 00140 PICKING, // Pick mode 00141 ROTATING, // Rotating camera around target 00142 POSTING, // Posting right-mouse menu 00143 TRANSLATING, // Translating camera 00144 ZOOMING, // Zooming 00145 FOVING, // Change field-of-view 00146 DRAGGING, // Dragging objects 00147 TRUCKING, // Trucking camera 00148 GYRATING, // Rotation of camera around eye 00149 DO_LASSOSELECT, // Lasso select when mouse pressed 00150 LASSOSELECT, // Anchor of lasso rectangle 00151 DO_LASSOZOOM, // Zoom when mouse pressed 00152 LASSOZOOM // Zoom rectangle 00153 }; 00154 00155 protected: 00156 FXGLViewer(); 00157 void glsetup(); 00158 void updateProjection(); 00159 void updateTransform(); 00160 FXVec spherePoint(FXint px,FXint py); 00161 FXQuat turn(FXint fx,FXint fy,FXint tx,FXint ty); 00162 void drawWorld(FXViewport& wv); 00163 void drawAnti(FXViewport& wv); 00164 void drawLasso(FXint x0,FXint y0,FXint x1,FXint y1); 00165 FXint selectHits(FXuint*& hits,FXint& nhits,FXint x,FXint y,FXint w,FXint h); 00166 FXint renderFeedback(FXfloat *buffer,FXint x,FXint y,FXint w,FXint h,FXint maxbuffer); 00167 void drawFeedback(FXDCPrint& pdc,const FXfloat* buffer,FXint used); 00168 virtual FXGLObject* processHits(FXuint *pickbuffer,FXint nhits); 00169 void setOp(FXuint o); 00170 virtual void layout(); 00171 private: 00172 FXGLViewer(const FXGLViewer&); 00173 FXGLViewer &operator=(const FXGLViewer&); 00174 void initialize(); 00175 public: 00176 00177 // Events 00178 long onPaint(FXObject*,FXSelector,void*); 00179 long onEnter(FXObject*,FXSelector,void*); 00180 long onLeave(FXObject*,FXSelector,void*); 00181 long onMotion(FXObject*,FXSelector,void*); 00182 long onMouseWheel(FXObject*,FXSelector,void*); 00183 long onChanged(FXObject*,FXSelector,void*); 00184 long onPick(FXObject*,FXSelector,void*); 00185 long onClicked(FXObject*,FXSelector,void*); 00186 long onDoubleClicked(FXObject*,FXSelector,void*); 00187 long onTripleClicked(FXObject*,FXSelector,void*); 00188 long onLassoed(FXObject*,FXSelector,void*); 00189 long onSelected(FXObject*,FXSelector,void*); 00190 long onDeselected(FXObject*,FXSelector,void*); 00191 long onInserted(FXObject*,FXSelector,void*); 00192 long onDeleted(FXObject*,FXSelector,void*); 00193 long onLeftBtnPress(FXObject*,FXSelector,void*); 00194 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00195 long onMiddleBtnPress(FXObject*,FXSelector,void*); 00196 long onMiddleBtnRelease(FXObject*,FXSelector,void*); 00197 long onRightBtnPress(FXObject*,FXSelector,void*); 00198 long onRightBtnRelease(FXObject*,FXSelector,void*); 00199 long onUngrabbed(FXObject*,FXSelector,void*); 00200 long onKeyPress(FXObject*,FXSelector,void*); 00201 long onKeyRelease(FXObject*,FXSelector,void*); 00202 long onFocusIn(FXObject*,FXSelector,void*); 00203 long onFocusOut(FXObject*,FXSelector,void*); 00204 long onClipboardLost(FXObject*,FXSelector,void*); 00205 long onClipboardGained(FXObject*,FXSelector,void*); 00206 long onClipboardRequest(FXObject*,FXSelector,void*); 00207 00208 // Commands 00209 long onCmdPerspective(FXObject*,FXSelector,void*); 00210 long onUpdPerspective(FXObject*,FXSelector,void*); 00211 long onCmdParallel(FXObject*,FXSelector,void*); 00212 long onUpdParallel(FXObject*,FXSelector,void*); 00213 long onCmdFront(FXObject*,FXSelector,void*); 00214 long onUpdFront(FXObject*,FXSelector,void*); 00215 long onCmdBack(FXObject*,FXSelector,void*); 00216 long onUpdBack(FXObject*,FXSelector,void*); 00217 long onCmdLeft(FXObject*,FXSelector,void*); 00218 long onUpdLeft(FXObject*,FXSelector,void*); 00219 long onCmdRight(FXObject*,FXSelector,void*); 00220 long onUpdRight(FXObject*,FXSelector,void*); 00221 long onCmdTop(FXObject*,FXSelector,void*); 00222 long onUpdTop(FXObject*,FXSelector,void*); 00223 long onCmdBottom(FXObject*,FXSelector,void*); 00224 long onUpdBottom(FXObject*,FXSelector,void*); 00225 long onCmdResetView(FXObject*,FXSelector,void*); 00226 long onCmdFitView(FXObject*,FXSelector,void*); 00227 long onDNDEnter(FXObject*,FXSelector,void*); 00228 long onDNDLeave(FXObject*,FXSelector,void*); 00229 long onDNDMotion(FXObject*,FXSelector,void*); 00230 long onDNDDrop(FXObject*,FXSelector,void*); 00231 long onTipTimer(FXObject*,FXSelector,void*); 00232 long onQueryHelp(FXObject*,FXSelector,void*); 00233 long onQueryTip(FXObject*,FXSelector,void*); 00234 long onCmdXYZDial(FXObject*,FXSelector,void*); 00235 long onUpdXYZDial(FXObject*,FXSelector,void*); 00236 long onCmdRollPitchYaw(FXObject*,FXSelector,void*); 00237 long onUpdRollPitchYaw(FXObject*,FXSelector,void*); 00238 long onCmdXYZScale(FXObject*,FXSelector,void*); 00239 long onUpdXYZScale(FXObject*,FXSelector,void*); 00240 long onUpdCurrent(FXObject*,FXSelector,void*); 00241 long onCmdCutSel(FXObject*,FXSelector,void*); 00242 long onCmdCopySel(FXObject*,FXSelector,void*); 00243 long onCmdPasteSel(FXObject*,FXSelector,void*); 00244 long onCmdDeleteSel(FXObject*,FXSelector,void*); 00245 long onUpdDeleteSel(FXObject*,FXSelector,void*); 00246 long onCmdBackColor(FXObject*,FXSelector,void*); 00247 long onUpdBackColor(FXObject*,FXSelector,void*); 00248 long onCmdAmbientColor(FXObject*,FXSelector,void*); 00249 long onUpdAmbientColor(FXObject*,FXSelector,void*); 00250 long onCmdLock(FXObject*,FXSelector,void*); 00251 long onUpdLock(FXObject*,FXSelector,void*); 00252 long onCmdLighting(FXObject*,FXSelector,void*); 00253 long onUpdLighting(FXObject*,FXSelector,void*); 00254 long onCmdFog(FXObject*,FXSelector,void*); 00255 long onUpdFog(FXObject*,FXSelector,void*); 00256 long onCmdDither(FXObject*,FXSelector,void*); 00257 long onUpdDither(FXObject*,FXSelector,void*); 00258 long onCmdFov(FXObject*,FXSelector,void*); 00259 long onUpdFov(FXObject*,FXSelector,void*); 00260 long onCmdZoom(FXObject*,FXSelector,void*); 00261 long onUpdZoom(FXObject*,FXSelector,void*); 00262 long onCmdLightAmbient(FXObject*,FXSelector,void*); 00263 long onUpdLightAmbient(FXObject*,FXSelector,void*); 00264 long onCmdLightDiffuse(FXObject*,FXSelector,void*); 00265 long onUpdLightDiffuse(FXObject*,FXSelector,void*); 00266 long onCmdLightSpecular(FXObject*,FXSelector,void*); 00267 long onUpdLightSpecular(FXObject*,FXSelector,void*); 00268 long onCmdTurbo(FXObject*,FXSelector,void*); 00269 long onUpdTurbo(FXObject*,FXSelector,void*); 00270 long onCmdPrintImage(FXObject*,FXSelector,void*); 00271 long onCmdPrintVector(FXObject*,FXSelector,void*); 00272 long onCmdLassoZoom(FXObject*,FXSelector,void*); 00273 long onCmdLassoSelect(FXObject*,FXSelector,void*); 00274 virtual long onDefault(FXObject*,FXSelector,void*); 00275 00276 public: 00277 00278 // Projection modes 00279 enum { 00280 PARALLEL, // Parallel projection 00281 PERSPECTIVE // Perspective projection 00282 }; 00283 00284 // Precompiled display lists [DEPRECATED] 00285 enum { 00286 OFFSETPROJECTION = 1, 00287 SURFACEPROJECTION = 2 00288 }; 00289 00290 // Messages 00291 enum { 00292 ID_PERSPECTIVE=FXGLCanvas::ID_LAST, 00293 ID_PARALLEL, 00294 ID_FRONT, 00295 ID_BACK, 00296 ID_LEFT, 00297 ID_RIGHT, 00298 ID_TOP, 00299 ID_BOTTOM, 00300 ID_RESETVIEW, 00301 ID_FITVIEW, 00302 ID_TIPTIMER, 00303 ID_BACK_COLOR, 00304 ID_AMBIENT_COLOR, 00305 ID_LIGHT_AMBIENT, 00306 ID_LIGHT_DIFFUSE, 00307 ID_LIGHT_SPECULAR, 00308 ID_LIGHTING, 00309 ID_TURBO, 00310 ID_FOG, 00311 ID_DITHER, 00312 ID_SCALE_X, 00313 ID_SCALE_Y, 00314 ID_SCALE_Z, 00315 ID_DIAL_X, 00316 ID_DIAL_Y, 00317 ID_DIAL_Z, 00318 ID_ROLL, 00319 ID_PITCH, 00320 ID_YAW, 00321 ID_FOV, 00322 ID_ZOOM, 00323 ID_LOCK, 00324 ID_CUT_SEL, 00325 ID_COPY_SEL, 00326 ID_PASTE_SEL, 00327 ID_DELETE_SEL, 00328 ID_PRINT_IMAGE, 00329 ID_PRINT_VECTOR, 00330 ID_LASSO_ZOOM, 00331 ID_LASSO_SELECT, 00332 ID_LAST 00333 }; 00334 00335 public: 00336 00337 // Common DND type names 00338 static const FXchar objectTypeName[]; 00339 00340 public: 00341 00342 /// Construct GL viewer widget 00343 FXGLViewer(FXComposite* p,FXGLVisual *vis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0); 00344 00345 /// Construct GL viewer widget sharing display list with another GL viewer 00346 FXGLViewer(FXComposite* p,FXGLVisual *vis,FXGLViewer* sharegroup,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0); 00347 00348 /// Create all of the server-side resources for this window 00349 virtual void create(); 00350 00351 /// Detach server-side resources 00352 virtual void detach(); 00353 00354 /// Return size of pixel in world coordinates 00355 FXdouble worldPix() const { return worldpx; } 00356 00357 /// Return size of pixel in model coordinates 00358 FXdouble modelPix() const { return modelpx; } 00359 00360 /// Return a NULL-terminated list of all objects in the given rectangle, or NULL 00361 FXGLObject** lasso(FXint x1,FXint y1,FXint x2,FXint y2); 00362 00363 /// Return a NULL-terminated list of all objects in the given rectangle, or NULL 00364 virtual FXGLObject** select(FXint x,FXint y,FXint w,FXint h); 00365 00366 /// Perform a pick operation, returning the object at the given x,y position, or NULL 00367 virtual FXGLObject* pick(FXint x,FXint y); 00368 00369 /// Change the model bounding box; this adjusts the viewer 00370 FXbool setBounds(const FXRange& box); 00371 00372 /// Fit viewer to the given bounding box 00373 FXbool fitToBounds(const FXRange& box); 00374 00375 /// Return the viewer's viewport 00376 void getViewport(FXViewport& v) const; 00377 00378 /// Translate eye-coordinate to screen coordinate 00379 void eyeToScreen(FXint& sx,FXint& sy,FXVec e); 00380 00381 /// Translate screen coordinate to eye coordinate at the given depth 00382 FXVec screenToEye(FXint sx,FXint sy,FXfloat eyez=0.0); 00383 00384 /// Translate screen coordinate to eye coordinate at the target point depth 00385 FXVec screenToTarget(FXint sx,FXint sy); 00386 00387 /// Translate world coordinate to eye coordinate 00388 FXVec worldToEye(FXVec w); 00389 00390 /// Translate world coordinate to eye coordinate depth 00391 FXfloat worldToEyeZ(FXVec w); 00392 00393 /// Translate eye coordinate to eye coordinate 00394 FXVec eyeToWorld(FXVec e); 00395 00396 /// Calculate world coordinate vector from screen movement 00397 FXVec worldVector(FXint fx,FXint fy,FXint tx,FXint ty); 00398 00399 /// Change default object material setting 00400 void setMaterial(const FXMaterial &mtl); 00401 00402 /// Return default object material setting 00403 void getMaterial(FXMaterial &mtl) const; 00404 00405 /// Change camera field of view angle (in degrees) 00406 void setFieldOfView(FXdouble fv); 00407 00408 /// Return camera field of view angle 00409 FXdouble getFieldOfView() const { return fov; } 00410 00411 /// Change camera zoom factor 00412 void setZoom(FXdouble zm); 00413 00414 /// Return camera zoom factor 00415 FXdouble getZoom() const { return zoom; } 00416 00417 /// Change target point distance 00418 void setDistance(FXdouble ed); 00419 00420 /// Return target point distance 00421 FXdouble getDistance() const { return distance; } 00422 00423 /// Change unequal model scaling factors 00424 void setScale(FXVec s); 00425 00426 /// Return current scaling factors 00427 FXVec getScale() const { return scale; } 00428 00429 /// Change camera orientation from quaternion 00430 void setOrientation(FXQuat rot); 00431 00432 /// Return current camera orientation quaternion 00433 FXQuat getOrientation() const { return rotation; } 00434 00435 /// Change object center (tranlation) 00436 void setCenter(FXVec cntr); 00437 00438 /// Return object center 00439 const FXVec& getCenter() const { return center; } 00440 00441 /// Translate object center 00442 void translate(FXVec vec); 00443 00444 /// Return boresight vector 00445 FXbool getBoreVector(FXint sx,FXint sy,FXVec& point,FXVec& dir); 00446 00447 /// Return eyesight vector 00448 FXVec getEyeVector() const; 00449 00450 /// Return eye position 00451 FXVec getEyePosition() const; 00452 00453 /// Change help text 00454 void setHelpText(const FXString& text); 00455 00456 /// Return help text 00457 FXString getHelpText() const { return help; } 00458 00459 /// Change tip text 00460 void setTipText(const FXString& text); 00461 00462 /// Return tip text 00463 FXString getTipText() const { return tip; } 00464 00465 /// Change line offset 00466 void setOffset(FXdouble offs); 00467 00468 /// Return line offset 00469 FXdouble getOffset() const { return offset; } 00470 00471 /// Return the current transformation matrix 00472 const FXHMat& getTransform() const { return transform; } 00473 00474 /// Return the inverse of the current transformation matrix 00475 const FXHMat& getInvTransform() const { return itransform; } 00476 00477 /// Change the scene, i.e. the object being displayed. 00478 void setScene(FXGLObject* sc); 00479 00480 /// Return the current scene object 00481 FXGLObject* getScene() const { return scene; } 00482 00483 /// Change selection 00484 void setSelection(FXGLObject* sel); 00485 00486 /// Return selection 00487 FXGLObject* getSelection() const { return selection; } 00488 00489 /// Change the projection mode, PERSPECTIVE or PARALLEL 00490 void setProjection(FXuint proj); 00491 00492 /// Return the projection mode 00493 FXuint getProjection() const { return projection; } 00494 00495 /// Lock the viewer, i.e. prevent mouse-based viewing operations 00496 void setViewLock(FXbool lock=TRUE); 00497 00498 /// Return viewer lock status 00499 FXbool getViewLock() const; 00500 00501 /// Change window background color 00502 void setBackgroundColor(const FXHVec& clr); 00503 00504 /// Return window background color 00505 FXHVec getBackgroundColor() const { return background; } 00506 00507 /// Change global ambient light color 00508 void setAmbientColor(const FXHVec& clr); 00509 00510 /// Return global ambient light color 00511 FXHVec getAmbientColor() const { return ambient; } 00512 00513 /// Read the pixels off the screen as R,G,B tuples. 00514 FXbool readPixels(FXuchar*& buffer,FXint x,FXint y,FXint w,FXint h); 00515 00516 /// Read the feedback buffer containing the current scene, returning used and allocated size 00517 FXbool readFeedback(FXfloat*& buffer,FXint& used,FXint& size,FXint x,FXint y,FXint w,FXint h); 00518 00519 /** 00520 * Change hidden-surface feedback buffer sorting algorithm. 00521 * This can be used for move/draw printed output depth sorting. 00522 */ 00523 void setZSortFunc(FXZSortFunc func){ zsortfunc=func; } 00524 00525 /// Return hidden surface sorting function. 00526 FXZSortFunc getZSortFunc() const { return zsortfunc; } 00527 00528 /** 00529 * Change the maximum hits, i.e. the maximum size of the pick buffer. 00530 * When set to less than or equal to zero, picking is essentially turned off. 00531 */ 00532 void setMaxHits(FXint maxh) { maxhits=maxh; } 00533 00534 /// Return maximum pickbuffer size 00535 FXint getMaxHits() const { return maxhits; } 00536 00537 /** 00538 * When drawing a GL object, if doesTurbo() is true, the object 00539 * may choose to perform a reduced complexity drawing as the user is 00540 * interactively manipulating; another update will be done later when 00541 * the full complexity drawing can be performed again. 00542 */ 00543 FXbool doesTurbo() const { return doesturbo; } 00544 00545 /// Return turbo mode setting 00546 FXbool getTurboMode() const { return turbomode; } 00547 00548 /// Set turbo mode 00549 void setTurboMode(FXbool turbo=TRUE); 00550 00551 /// Return light source settings 00552 void getLight(FXLight& lite) const; 00553 00554 /// Change light source settings 00555 void setLight(const FXLight& lite); 00556 00557 /// Save viewer to a stream 00558 virtual void save(FXStream& store) const; 00559 00560 /// Load viewer from a stream 00561 virtual void load(FXStream& store); 00562 00563 /// Destructor 00564 virtual ~FXGLViewer(); 00565 }; 00566 00567 00568 #endif 00569