VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtOsgCullVisitorParameters.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2014 MAK Technologies, Inc.
3  * All rights reserved.
4  *****************************************************************************/
5 
13 
14 #pragma once
15 
16 #include <vrvOsg/vrvOsg.h>
17 #include <osg/Referenced>
18 #include <osg/BoundingBox>
19 #include <osg/BoundingSphere>
20 #include <osg/Vec2>
21 #include <osgUtil/CullVisitor>
22 
24 
26 
28 
29 #include <algorithm>
30 #include <math.h>
31 
32 #ifdef min
33 #undef min
34 #endif
35 
36 namespace makVrv
37 {
41  class DT_DLL_VRVOSG DtOsgCullVisitorParameters : public osg::Referenced
42  {
43  public:
44 
47  : osg::Referenced()
48  , mySkyFlag(true)
49  , myDynamicLightsFlag(true)
50  , myDynamicOceanFlag(true)
51  , myOrthoFlag(false)
52  , myCameraResolution( 1.0 )
53  , myTerrainRadius( 1.0 )
54  , myScalingFlag( true )
55  , myScaleFactor( 1.0 )
56  , myClampedPixelSize( 1.0 )
57  , myCameraMagnification( 1.0 )
58  , myScaleType( DtObserverObject::XRScale )
59  , myCoordinateSystemChanged( false )
60  , myAltitude2D( 0. )
61  , myAltitude3D( 0. )
62  , myDynamicWaterVisibilityEnable(true)
63  , myDynamicWaterVisibilityMax(75.)
64  , myNodeXRScaler( 0 )
65  , myPagedLodMagnificationScaleFactor(1.)
66  , myCameraVelocity( 0 )
67  , myModelSet(0)
68  {
69  }
70 
72  inline void setCameraMagnification( double mag )
73  {
74  myCameraMagnification = mag;
75  }
76 
78  inline double cameraMagnification() const
79  {
80  return myCameraMagnification;
81  }
82 
84  void setCameraResolution(double factor)
85  {
86  myCameraResolution = factor;
87  }
88 
90  inline double cameraResolution() const
91  {
92  return myCameraResolution;
93  }
95  void setCameraVelocity(double velocity)
96  {
97  myCameraVelocity = velocity;
98  }
99 
101  inline double cameraVelocity() const
102  {
103  return myCameraVelocity;
104  }
105 
107  void setTerrainRadius(double rad)
108  {
109  myTerrainRadius = rad;
110  }
111 
113  void setAltitude2D( double altitude )
114  {
115  myAltitude2D = altitude;
116  }
117 
119  double altitude2D() const
120  {
121  return myAltitude2D;
122  }
123 
125  inline unsigned int modelSet() const
126  {
127  return myModelSet;
128  }
129 
131  void setModelSet(unsigned int modelSet)
132  {
133  myModelSet = modelSet;
134  }
135 
137  inline double terrainRadius() const
138  {
139  return myTerrainRadius;
140  }
141 
143  void setOrthoCulling(bool ortho)
144  {
145  myOrthoFlag = ortho;
146  }
147 
149  inline bool orthoCulling() const
150  {
151  return myOrthoFlag;
152  }
153 
155  inline void setSkyRendering(bool renderSky)
156  {
157  mySkyFlag = renderSky;
158 
159  }
160 
162  inline bool skyRendering() const
163  {
164  return mySkyFlag;
165  }
166 
168  inline void setDynamicLights(bool enabled)
169  {
170  myDynamicLightsFlag = enabled;
171  }
172 
174  inline bool dynamicLights() const
175  {
176  return myDynamicLightsFlag;
177  }
178 
180  inline void setDynamicOcean(bool enabled)
181  {
182  myDynamicOceanFlag = enabled;
183  }
184 
186  inline bool dynamicOcean() const
187  {
188  return myDynamicOceanFlag;
189  }
190 
192  void setScaling( bool scaling )
193  {
194  myScalingFlag = scaling;
195  }
196 
198  inline bool scaling() const
199  {
200  return myScalingFlag;
201  }
202 
204  void setScaleFactor( double scaleFactor )
205  {
206  myScaleFactor = scaleFactor;
207  }
208 
210  inline double scaleFactor() const
211  {
212  return myScaleFactor;
213  }
214 
216  void setCoordinateSystemChanged( bool changed )
217  {
218  myCoordinateSystemChanged = changed;
219  }
220 
222  inline bool coordinateSystemChanged() const
223  {
224  return myCoordinateSystemChanged;
225  }
226 
229  inline void setNodeXRScaler( DtOsgNodeXRScaler* scaler )
230  {
231  myNodeXRScaler = scaler;
232  }
233 
235  inline double calculateXRScale( const osg::Camera& camera,
236  const osg::Node& node )
237  {
238  if ( myNodeXRScaler.valid() )
239  {
240  return myNodeXRScaler->calculateXRScale( *this, camera, node );
241  }
242  else
243  {
244  return 1.;
245  }
246  }
247 
249  void setScaleType( DtObserverObject::ScaleType scaleType )
250  {
251  myScaleType = scaleType;
252  }
253 
255  inline DtObserverObject::ScaleType scaleType() const
256  {
257  return myScaleType;
258  }
259 
264  void setClampedPixelSize(double d)
265  {
266  myClampedPixelSize = d;
267  }
268 
270  double clampedPixelSize() const
271  {
272  return myClampedPixelSize;
273  }
274 
278  inline void setDynamicWaterVisibilityEnable( bool enable )
279  {
280  myDynamicWaterVisibilityEnable = enable;
281  }
282 
284  inline bool dynamicWaterVisibilityEnable() const
285  {
286  return myDynamicWaterVisibilityEnable;
287  }
288 
291  inline void setDynamicWaterVisibilityMax( double visMax )
292  {
293  myDynamicWaterVisibilityMax = visMax;
294  }
295 
298  inline double dynamicWaterVisibilityMax() const
299  {
300  return myDynamicWaterVisibilityMax;
301  }
302 
305  inline void setPagedLodMagnificationScaleFactor(float factor)
306  {
307  myPagedLodMagnificationScaleFactor = factor;
308  }
309 
312  inline float pagedLodMagnificationScaleFactor() const
313  {
314  return myPagedLodMagnificationScaleFactor;
315  }
316 
317  protected:
318 
322  double myAltitude2D;
323  double myAltitude3D;
324  bool mySkyFlag;
335  osg::ref_ptr<DtOsgNodeXRScaler> myNodeXRScaler;
338  unsigned int myModelSet;
339  };
340 
343  class DT_DLL_VRVOSG DtOsgFixedScaleParameters : public osg::Referenced
344  {
345  public:
347  : myFixedPixelSize( 1.0 )
348  , myLength( 0.0 )
349  , myWidth( 0.0 )
350  , myHeight( 0.0 )
351  , myScaleX(true)
352  , myScaleY(true)
353  , myScaleZ(true)
354  {
355 }
356 
358  {
359  }
360 
361  void setFixedPixelSize(double d)
362  {
363  myFixedPixelSize = d;
364  }
365 
366  double fixedPixelSize() const
367  {
368  return myFixedPixelSize;
369  }
370 
371  void setDimensions(double length, double width, double height)
372  {
373  myLength = length; myWidth = width; myHeight = height;
374  }
375 
376  inline double length() const
377  {
378  return myLength;
379  }
380 
381  inline double width() const
382  {
383  return myWidth;
384  }
385 
386  inline double height() const
387  {
388  return myHeight;
389  }
390 
391  inline void calculateScaleFactors(const osgUtil::CullVisitor& visitor,
392  const osg::BoundingSphere& sphere, DtOsgCullVisitorParameters* info,
393  double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
394  {
395  double clampedSize =
396  visitor.clampedPixelSize( sphere.center(), info->terrainRadius() );
397  info->setClampedPixelSize(clampedSize);
398 
399  calculateScaleFactors( sphere, *info, scaleFactorX,
400  scaleFactorY, scaleFactorZ );
401  }
402 
403  inline void calculateScaleFactors(const osg::BoundingSphere& sphere, const DtOsgCullVisitorParameters& info,
404  double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
405  {
406  scaleFactorX = scaleFactorY = scaleFactorZ = 1.0;
407 
408  double metersPerPixel = info.terrainRadius() / info.clampedPixelSize(); // Meters per pixel
409  double curPixels = myWidth / metersPerPixel; // Pixels needed to draw
410 
411  if (myScaleX)
412  {
413  scaleFactorX = myFixedPixelSize / curPixels;
414  }
415 
416  if (myScaleY)
417  {
418  scaleFactorY = scaleFactorX;
419  }
420 
421  if (myScaleX)
422  {
423  scaleFactorZ = 1.0;
424  }
425  }
426 
427  void setScaleX(bool b)
428  {
429  myScaleX = b;
430  }
431 
432  inline bool scaleX() const
433  {
434  return myScaleX;
435  }
436 
437  void setScaleXY(bool b)
438  {
439  myScaleY = b;
440  }
441 
442  inline bool scaleY() const
443  {
444  return myScaleY;
445  }
446 
447  void setScaleZ(bool b)
448  {
449  myScaleZ = b;
450  }
451 
452  inline bool scaleZ() const
453  {
454  return myScaleZ;
455  }
456 
457  protected:
459  double myLength, myWidth, myHeight;
460  bool myScaleX, myScaleY, myScaleZ;
461  };
462 
463 }
464 
465 

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)