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