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