Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXGLViewer.h
1 /********************************************************************************
2 * *
3 * O p e n G L V i e w e r W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXGLVIEWER_H
22 #define FXGLVIEWER_H
23 
24 #ifndef FXGLCANVAS_H
25 #include "FXGLCanvas.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 class FXDCPrint;
32 class FXGLObject;
33 class FXGLVisual;
34 
35 
36 // GL Viewer options
37 enum {
38  GLVIEWER_LIGHTING = 0x00010000,
39  GLVIEWER_FOG = 0x00020000,
40  GLVIEWER_DITHER = 0x00040000
41  };
42 
43 
44 /******************************* Viewer Structs *****************************/
45 
46 
48 struct FXViewport {
49  FXint w;
50  FXint h;
51  FXdouble left;
52  FXdouble right;
53  FXdouble bottom;
54  FXdouble top;
55  FXdouble hither;
56  FXdouble yon;
57  };
58 
59 
61 struct FXAPI FXLight {
62  FXVec4f ambient;
67  FXfloat exponent;
68  FXfloat cutoff;
69  FXfloat c_attn;
70  FXfloat l_attn;
71  FXfloat q_attn;
72  };
73 
74 
76 struct FXAPI FXMaterial {
77  FXVec4f ambient;
81  FXfloat shininess;
82  };
83 
84 
85 // Feedback buffer sort routine
86 typedef FXbool (*FXZSortFunc)(FXfloat*& buffer,FXint& used,FXint& size);
87 
88 
89 /******************************** Viewer Class ******************************/
90 
91 
93 class FXAPI FXGLViewer : public FXGLCanvas {
94  FXDECLARE(FXGLViewer)
95  friend class FXGLObject;
96 protected:
97  FXViewport wvt; // Window viewport transform
98  FXMat4f transform; // Current transformation matrix
99  FXMat4f itransform; // Inverse of current transformation matrix
100  FXuint projection; // Projection mode
101  FXQuatf rotation; // Viewer orientation
102  FXdouble fov; // Field of view
103  FXdouble zoom; // Zoom factor
104  FXVec3f center; // Model center
105  FXVec3f scale; // Model scale
106  FXdouble worldpx; // Pixel size in world
107  FXdouble modelpx; // Pixel size in model
108  FXint maxhits; // Maximum number of hits
109  FXdouble ax,ay; // Quick view->world coordinate mapping
110  FXdouble diameter; // Size of model diameter ( always > 0)
111  FXdouble distance; // Distance of PRP to target
112  FXVec4f background[2]; // Background colors
113  FXVec4f ambient; // Global ambient light
114  FXLight light; // Light source
115  FXMaterial material; // Base material properties
116  FXint dial[3]; // Dial positions
117  FXString help; // Status help
118  FXString tip; // Tooltip for background
119  FXGLObject *dropped; // Object being dropped on
120  FXGLObject *selection; // Current object
121  FXZSortFunc zsortfunc; // Routine to sort feedback buffer
122  FXGLObject *scene; // What we're looking at
123  FXbool doesturbo; // Doing turbo mode
124  FXbool turbomode; // Turbo mode
125  FXuchar mode; // Mode the widget is in
126 public:
127 
128  // Common DND types
129  static FXDragType objectType; // GL Object type
130 
131 protected:
132 
133  // Mouse actions when in viewing window
134  enum {
135  HOVERING, // Hovering mouse w/o doing anything
136  PICKING, // Pick mode
137  ROTATING, // Rotating camera around target
138  POSTING, // Posting right-mouse menu
139  TRANSLATING, // Translating camera
140  ZOOMING, // Zooming
141  FOVING, // Change field-of-view
142  DRAGGING, // Dragging objects
143  TRUCKING, // Trucking camera
144  GYRATING, // Rotation of camera around eye
145  DO_LASSOSELECT, // Lasso select when mouse pressed
146  LASSOSELECT, // Anchor of lasso rectangle
147  DO_LASSOZOOM, // Zoom when mouse pressed
148  LASSOZOOM // Zoom rectangle
149  };
150 
151 protected:
152  FXGLViewer();
153  void glsetup();
154  virtual void updateProjection();
155  virtual void updateTransform();
156  FXVec3f spherePoint(FXint px,FXint py);
157  FXQuatf turn(FXint fx,FXint fy,FXint tx,FXint ty);
158  void drawWorld(FXViewport& wv);
159  void drawAnti(FXViewport& wv);
160  void drawLasso(FXint x0,FXint y0,FXint x1,FXint y1);
161  FXint selectHits(FXuint*& hits,FXint& nhits,FXint x,FXint y,FXint w,FXint h);
162  FXint renderFeedback(FXfloat *buffer,FXint x,FXint y,FXint w,FXint h,FXint maxbuffer);
163  void drawFeedback(FXDCPrint& pdc,const FXfloat* buffer,FXint used);
164  virtual FXGLObject* processHits(FXuint *pickbuffer,FXint nhits);
165  void setOp(FXuint o);
166 private:
167  FXGLViewer(const FXGLViewer&);
168  FXGLViewer &operator=(const FXGLViewer&);
169  void initialize();
170 public:
171 
172  // Events
173  long onPaint(FXObject*,FXSelector,void*);
174  long onEnter(FXObject*,FXSelector,void*);
175  long onLeave(FXObject*,FXSelector,void*);
176  long onMotion(FXObject*,FXSelector,void*);
177  long onMouseWheel(FXObject*,FXSelector,void*);
178  long onChanged(FXObject*,FXSelector,void*);
179  long onPick(FXObject*,FXSelector,void*);
180  long onClicked(FXObject*,FXSelector,void*);
181  long onDoubleClicked(FXObject*,FXSelector,void*);
182  long onTripleClicked(FXObject*,FXSelector,void*);
183  long onLassoed(FXObject*,FXSelector,void*);
184  long onSelected(FXObject*,FXSelector,void*);
185  long onDeselected(FXObject*,FXSelector,void*);
186  long onInserted(FXObject*,FXSelector,void*);
187  long onDeleted(FXObject*,FXSelector,void*);
188  long onLeftBtnPress(FXObject*,FXSelector,void*);
189  long onLeftBtnRelease(FXObject*,FXSelector,void*);
190  long onMiddleBtnPress(FXObject*,FXSelector,void*);
191  long onMiddleBtnRelease(FXObject*,FXSelector,void*);
192  long onRightBtnPress(FXObject*,FXSelector,void*);
193  long onRightBtnRelease(FXObject*,FXSelector,void*);
194  long onSpaceBallMotion(FXObject*,FXSelector,void*);
195  long onUngrabbed(FXObject*,FXSelector,void*);
196  long onKeyPress(FXObject*,FXSelector,void*);
197  long onKeyRelease(FXObject*,FXSelector,void*);
198  long onFocusIn(FXObject*,FXSelector,void*);
199  long onFocusOut(FXObject*,FXSelector,void*);
200  long onClipboardLost(FXObject*,FXSelector,void*);
201  long onClipboardGained(FXObject*,FXSelector,void*);
202  long onClipboardRequest(FXObject*,FXSelector,void*);
203 
204  // Commands
205  long onCmdPerspective(FXObject*,FXSelector,void*);
206  long onUpdPerspective(FXObject*,FXSelector,void*);
207  long onCmdParallel(FXObject*,FXSelector,void*);
208  long onUpdParallel(FXObject*,FXSelector,void*);
209  long onCmdFront(FXObject*,FXSelector,void*);
210  long onUpdFront(FXObject*,FXSelector,void*);
211  long onCmdBack(FXObject*,FXSelector,void*);
212  long onUpdBack(FXObject*,FXSelector,void*);
213  long onCmdLeft(FXObject*,FXSelector,void*);
214  long onUpdLeft(FXObject*,FXSelector,void*);
215  long onCmdRight(FXObject*,FXSelector,void*);
216  long onUpdRight(FXObject*,FXSelector,void*);
217  long onCmdTop(FXObject*,FXSelector,void*);
218  long onUpdTop(FXObject*,FXSelector,void*);
219  long onCmdBottom(FXObject*,FXSelector,void*);
220  long onUpdBottom(FXObject*,FXSelector,void*);
221  long onCmdResetView(FXObject*,FXSelector,void*);
222  long onCmdFitView(FXObject*,FXSelector,void*);
223  long onDNDEnter(FXObject*,FXSelector,void*);
224  long onDNDLeave(FXObject*,FXSelector,void*);
225  long onDNDMotion(FXObject*,FXSelector,void*);
226  long onDNDDrop(FXObject*,FXSelector,void*);
227  long onTipTimer(FXObject*,FXSelector,void*);
228  long onCmdXYZDial(FXObject*,FXSelector,void*);
229  long onUpdXYZDial(FXObject*,FXSelector,void*);
230  long onCmdRollPitchYaw(FXObject*,FXSelector,void*);
231  long onUpdRollPitchYaw(FXObject*,FXSelector,void*);
232  long onCmdXYZScale(FXObject*,FXSelector,void*);
233  long onUpdXYZScale(FXObject*,FXSelector,void*);
234  long onUpdCurrent(FXObject*,FXSelector,void*);
235  long onCmdCutSel(FXObject*,FXSelector,void*);
236  long onCmdCopySel(FXObject*,FXSelector,void*);
237  long onCmdPasteSel(FXObject*,FXSelector,void*);
238  long onCmdDeleteSel(FXObject*,FXSelector,void*);
239  long onUpdDeleteSel(FXObject*,FXSelector,void*);
240  long onCmdBackColor(FXObject*,FXSelector,void*);
241  long onUpdBackColor(FXObject*,FXSelector,void*);
242  long onCmdGradientBackColor(FXObject*,FXSelector,void*);
243  long onUpdGradientBackColor(FXObject*,FXSelector,void*);
244  long onCmdAmbientColor(FXObject*,FXSelector,void*);
245  long onUpdAmbientColor(FXObject*,FXSelector,void*);
246  long onCmdLighting(FXObject*,FXSelector,void*);
247  long onUpdLighting(FXObject*,FXSelector,void*);
248  long onCmdFog(FXObject*,FXSelector,void*);
249  long onUpdFog(FXObject*,FXSelector,void*);
250  long onCmdDither(FXObject*,FXSelector,void*);
251  long onUpdDither(FXObject*,FXSelector,void*);
252  long onCmdFov(FXObject*,FXSelector,void*);
253  long onUpdFov(FXObject*,FXSelector,void*);
254  long onCmdZoom(FXObject*,FXSelector,void*);
255  long onUpdZoom(FXObject*,FXSelector,void*);
256  long onCmdLightAmbient(FXObject*,FXSelector,void*);
257  long onUpdLightAmbient(FXObject*,FXSelector,void*);
258  long onCmdLightDiffuse(FXObject*,FXSelector,void*);
259  long onUpdLightDiffuse(FXObject*,FXSelector,void*);
260  long onCmdLightSpecular(FXObject*,FXSelector,void*);
261  long onUpdLightSpecular(FXObject*,FXSelector,void*);
262  long onCmdTurbo(FXObject*,FXSelector,void*);
263  long onUpdTurbo(FXObject*,FXSelector,void*);
264  long onCmdPrintImage(FXObject*,FXSelector,void*);
265  long onCmdPrintVector(FXObject*,FXSelector,void*);
266  long onCmdLassoZoom(FXObject*,FXSelector,void*);
267  long onCmdLassoSelect(FXObject*,FXSelector,void*);
268  long onQueryHelp(FXObject*,FXSelector,void*);
269  long onQueryTip(FXObject*,FXSelector,void*);
270  virtual long onDefault(FXObject*,FXSelector,void*);
271 
272 public:
273 
274  // Projection modes
275  enum {
276  PARALLEL, // Parallel projection
277  PERSPECTIVE // Perspective projection
278  };
279 
280  // Messages
281  enum {
282  ID_PERSPECTIVE=FXGLCanvas::ID_LAST,
283  ID_PARALLEL,
284  ID_FRONT,
285  ID_BACK,
286  ID_LEFT,
287  ID_RIGHT,
288  ID_TOP,
289  ID_BOTTOM,
290  ID_RESETVIEW,
291  ID_FITVIEW,
292  ID_TOP_COLOR,
293  ID_BOTTOM_COLOR,
294  ID_BACK_COLOR,
295  ID_AMBIENT_COLOR,
296  ID_LIGHT_AMBIENT,
297  ID_LIGHT_DIFFUSE,
298  ID_LIGHT_SPECULAR,
299  ID_LIGHTING,
300  ID_TURBO,
301  ID_FOG,
302  ID_DITHER,
303  ID_SCALE_X,
304  ID_SCALE_Y,
305  ID_SCALE_Z,
306  ID_DIAL_X,
307  ID_DIAL_Y,
308  ID_DIAL_Z,
309  ID_ROLL,
310  ID_PITCH,
311  ID_YAW,
312  ID_FOV,
313  ID_ZOOM,
314  ID_CUT_SEL,
315  ID_COPY_SEL,
316  ID_PASTE_SEL,
317  ID_DELETE_SEL,
318  ID_PRINT_IMAGE,
319  ID_PRINT_VECTOR,
320  ID_LASSO_ZOOM,
321  ID_LASSO_SELECT,
322  ID_LAST
323  };
324 
325 public:
326 
327  // Common DND type names
328  static const FXchar objectTypeName[];
329 
330 public:
331 
333  FXGLViewer(FXComposite* p,FXGLVisual *vis,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
334 
336  FXGLViewer(FXComposite* p,FXGLVisual *vis,FXGLCanvas* share,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
337 
339  FXGLViewer(FXComposite* p,FXGLContext* ctx,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
340 
342  virtual void create();
343 
345  virtual void detach();
346 
348  virtual void layout();
349 
351  FXdouble worldPix() const { return worldpx; }
352 
354  FXdouble modelPix() const { return modelpx; }
355 
357  FXGLObject** lasso(FXint x1,FXint y1,FXint x2,FXint y2);
358 
360  virtual FXGLObject** select(FXint x,FXint y,FXint w,FXint h);
361 
363  virtual FXGLObject* pick(FXint x,FXint y);
364 
366  virtual FXbool setBounds(const FXRangef& box);
367 
369  FXbool fitToBounds(const FXRangef& box);
370 
372  void getViewport(FXViewport& v) const;
373 
375  void eyeToScreen(FXint& sx,FXint& sy,FXVec3f e);
376 
378  FXVec3f screenToEye(FXint sx,FXint sy,FXfloat eyez=0.0f);
379 
381  FXVec3f screenToTarget(FXint sx,FXint sy);
382 
384  FXVec3f worldToEye(FXVec3f w);
385 
387  FXfloat worldToEyeZ(FXVec3f w);
388 
390  FXVec3f eyeToWorld(FXVec3f e);
391 
393  FXVec3f worldVector(FXint fx,FXint fy,FXint tx,FXint ty);
394 
396  void setMaterial(const FXMaterial &mtl);
397 
399  void getMaterial(FXMaterial &mtl) const;
400 
402  void setFieldOfView(FXdouble fv);
403 
405  FXdouble getFieldOfView() const { return fov; }
406 
408  void setZoom(FXdouble zm);
409 
411  FXdouble getZoom() const { return zoom; }
412 
414  void setDistance(FXdouble ed);
415 
417  FXdouble getDistance() const { return distance; }
418 
420  void setScale(FXVec3f s);
421 
423  const FXVec3f& getScale() const { return scale; }
424 
426  void setOrientation(const FXQuatf& rot);
427 
429  const FXQuatf& getOrientation() const { return rotation; }
430 
432  void setCenter(FXVec3f cntr);
433 
435  const FXVec3f& getCenter() const { return center; }
436 
438  void translate(FXVec3f vec);
439 
441  FXbool getBoreVector(FXint sx,FXint sy,FXVec3f& point,FXVec3f& dir);
442 
444  FXVec3f getEyeVector() const;
445 
447  FXVec3f getEyePosition() const;
448 
450  void setHelpText(const FXString& text);
451 
453  const FXString& getHelpText() const { return help; }
454 
456  void setTipText(const FXString& text);
457 
459  const FXString& getTipText() const { return tip; }
460 
462  const FXMat4f& getTransform() const { return transform; }
463 
465  const FXMat4f& getInvTransform() const { return itransform; }
466 
468  void setScene(FXGLObject* sc);
469 
471  FXGLObject* getScene() const { return scene; }
472 
474  void setSelection(FXGLObject* sel);
475 
477  FXGLObject* getSelection() const { return selection; }
478 
480  void setProjection(FXuint proj);
481 
483  FXuint getProjection() const { return projection; }
484 
486  void setBackgroundColor(const FXVec4f& clr);
487 
489  void setBackgroundColor(const FXVec4f& clr,FXbool bottom);
490 
492  const FXVec4f& getBackgroundColor(FXbool bottom) const { return background[bottom]; }
493 
495  void setAmbientColor(const FXVec4f& clr);
496 
498  const FXVec4f& getAmbientColor() const { return ambient; }
499 
505  FXbool readPixels(FXColor*& buffer,FXint x,FXint y,FXint w,FXint h);
506 
511  FXbool readFeedback(FXfloat*& buffer,FXint& used,FXint& size,FXint x,FXint y,FXint w,FXint h);
512 
517  void setZSortFunc(FXZSortFunc func){ zsortfunc=func; }
518 
520  FXZSortFunc getZSortFunc() const { return zsortfunc; }
521 
526  void setMaxHits(FXint maxh) { maxhits=maxh; }
527 
529  FXint getMaxHits() const { return maxhits; }
530 
537  FXbool doesTurbo() const { return doesturbo; }
538 
540  FXbool getTurboMode() const { return turbomode; }
541 
543  void setTurboMode(FXbool turbo=true);
544 
546  void getLight(FXLight& lite) const;
547 
549  void setLight(const FXLight& lite);
550 
552  virtual void save(FXStream& store) const;
553 
555  virtual void load(FXStream& store);
556 
558  virtual ~FXGLViewer();
559  };
560 
561 }
562 
563 #endif
564 
OpenGL Viewer Viewport.
Definition: FXGLViewer.h:48
OpenGL Material Description.
Definition: FXGLViewer.h:76
Basic OpenGL object.
Definition: FXGLObject.h:37
FXdouble worldPix() const
Return size of pixel in world coordinates.
Definition: FXGLViewer.h:351
FXint getMaxHits() const
Return maximum pickbuffer size.
Definition: FXGLViewer.h:529
FXbool getTurboMode() const
Return turbo mode setting.
Definition: FXGLViewer.h:540
FXdouble getFieldOfView() const
Return camera field of view angle.
Definition: FXGLViewer.h:405
FXfloat l_attn
Constant attenuation factor.
Definition: FXGLViewer.h:70
const FXString & getHelpText() const
Return help text.
Definition: FXGLViewer.h:453
const FXVec4f & getBackgroundColor(FXbool bottom) const
Return top or bottom window background color.
Definition: FXGLViewer.h:492
FXdouble right
World left.
Definition: FXGLViewer.h:52
const FXVec3f & getCenter() const
Return object center.
Definition: FXGLViewer.h:435
FXZSortFunc getZSortFunc() const
Return hidden surface sorting function.
Definition: FXGLViewer.h:520
FXdouble modelPix() const
Return size of pixel in model coordinates.
Definition: FXGLViewer.h:354
FXGLObject * getSelection() const
Return selection.
Definition: FXGLViewer.h:477
FXVec4f position
Specular light color.
Definition: FXGLViewer.h:65
OpenGL viewer widget.
Definition: FXGLViewer.h:93
Postscript Printer Device Context.
Definition: FXDCPrint.h:98
FXdouble left
Viewport height.
Definition: FXGLViewer.h:51
const FXQuatf & getOrientation() const
Return current camera orientation quaternion.
Definition: FXGLViewer.h:429
FXfloat c_attn
Spotlight cutoff angle.
Definition: FXGLViewer.h:69
void setMaxHits(FXint maxh)
Change the maximum hits, i.e.
Definition: FXGLViewer.h:526
Base composite.
Definition: FXComposite.h:32
const FXVec4f & getAmbientColor() const
Return global ambient light color.
Definition: FXGLViewer.h:498
FXuint getProjection() const
Return the projection mode.
Definition: FXGLViewer.h:483
const FXVec3f & getScale() const
Return current scaling factors.
Definition: FXGLViewer.h:423
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
FXbool doesTurbo() const
When drawing a GL object, if doesTurbo() is true, the object may choose to perform a reduced complexi...
Definition: FXGLViewer.h:537
FXdouble getZoom() const
Return camera zoom factor.
Definition: FXGLViewer.h:411
FXint h
Viewport width.
Definition: FXGLViewer.h:50
Definition: FX4Splitter.h:28
void setZSortFunc(FXZSortFunc func)
Change hidden-surface feedback buffer sorting algorithm.
Definition: FXGLViewer.h:517
OpenGL Light Source.
Definition: FXGLViewer.h:61
GL Context.
Definition: FXGLContext.h:32
const FXMat4f & getInvTransform() const
Return the inverse of the current transformation matrix.
Definition: FXGLViewer.h:465
Single-precision quaternion.
Definition: FXQuatf.h:32
GLCanvas, an area drawn by another object.
Definition: FXGLCanvas.h:42
Single-precision 3-element vector.
Definition: FXVec3f.h:28
Visual describes pixel format of a drawable.
Definition: FXGLVisual.h:40
Single-precision 4x4 matrix.
Definition: FXMat4f.h:32
FXfloat q_attn
Linear attenuation factor.
Definition: FXGLViewer.h:71
const FXMat4f & getTransform() const
Return the current transformation matrix.
Definition: FXGLViewer.h:462
FXfloat shininess
Emissive material color.
Definition: FXGLViewer.h:81
FXdouble top
World bottom.
Definition: FXGLViewer.h:54
Bounds.
Definition: FXRangef.h:32
FXVec4f specular
Diffuse material color.
Definition: FXGLViewer.h:79
FXVec4f specular
Diffuse light color.
Definition: FXGLViewer.h:64
FXdouble bottom
World right.
Definition: FXGLViewer.h:53
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:134
FXdouble hither
World top.
Definition: FXGLViewer.h:55
FXVec3f direction
Light position.
Definition: FXGLViewer.h:66
const FXString & getTipText() const
Return tip text.
Definition: FXGLViewer.h:459
FXVec4f diffuse
Ambient material color.
Definition: FXGLViewer.h:78
FXfloat cutoff
Spotlight exponent.
Definition: FXGLViewer.h:68
FXGLObject * getScene() const
Return the current scene object.
Definition: FXGLViewer.h:471
FXVec4f emission
Specular material color.
Definition: FXGLViewer.h:80
FXdouble yon
World hither (near)
Definition: FXGLViewer.h:56
FXVec4f diffuse
Ambient light color.
Definition: FXGLViewer.h:63
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42
FXdouble getDistance() const
Return target point distance.
Definition: FXGLViewer.h:417
Single-precision 4-element vector.
Definition: FXVec4f.h:28
FXfloat exponent
Spot direction.
Definition: FXGLViewer.h:67

Copyright © 1997-2022 Jeroen van der Zijp