VR-Forces Development_Version 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 <osg/BoundingBox>
17 #include <osg/BoundingSphere>
18 #include <osg/Vec2>
19 #include <osgUtil/CullVisitor>
20 
22 
24 
25 #include <algorithm>
26 #include <math.h>
27 
28 #ifdef min
29 #undef min
30 #endif
31 
32 namespace makVrv
33 {
37  class DT_DLL_VRVOSG DtOsgCullVisitorParameters : public osg::Referenced
38  {
39  public:
40 
43  : osg::Referenced()
44  , mySkyFlag(true)
45  , myDynamicLightsFlag(true)
46  , myDynamicOceanFlag(true)
47  , myOrthoFlag(false)
48  , myCameraResolution( 1.0 )
49  , myTerrainRadius( 1.0 )
50  , myScalingFlag( true )
51  , myScaleFactor( 1.0 )
52  , myClampedPixelSize( 1.0 )
53  , myCameraMagnification( 1.0 )
54  , myScaleType( DtObserverObject::XRScale )
55  , myCoordinateSystemChanged( false )
56  , myAltitude2D( 0. )
57  , myAltitude3D( 0. )
58  , myDynamicWaterVisibilityEnable(true)
59  , myDynamicWaterVisibilityMax(75.)
60  , myNodeXRScaler( 0 )
61  , myPagedLodMagnificationScaleFactor(1.)
62  , myCameraVelocity( 0 )
63  , myModelSet(0)
64  {
65  }
66 
68  inline void setCameraMagnification( double mag )
69  {
70  myCameraMagnification = mag;
71  }
72 
74  inline double cameraMagnification() const
75  {
76  return myCameraMagnification;
77  }
78 
80  void setCameraResolution(double factor)
81  {
82  myCameraResolution = factor;
83  }
84 
86  inline double cameraResolution() const
87  {
88  return myCameraResolution;
89  }
91  void setCameraVelocity(double velocity)
92  {
93  myCameraVelocity = velocity;
94  }
95 
97  inline double cameraVelocity() const
98  {
99  return myCameraVelocity;
100  }
101 
103  void setTerrainRadius(double rad)
104  {
105  myTerrainRadius = rad;
106  }
107 
109  void setAltitude2D( double altitude )
110  {
111  myAltitude2D = altitude;
112  }
113 
115  double altitude2D() const
116  {
117  return myAltitude2D;
118  }
119 
121  inline unsigned int modelSet() const
122  {
123  return myModelSet;
124  }
125 
127  void setModelSet(unsigned int modelSet)
128  {
129  myModelSet = modelSet;
130  }
131 
133  inline double terrainRadius() const
134  {
135  return myTerrainRadius;
136  }
137 
139  void setOrthoCulling(bool ortho)
140  {
141  myOrthoFlag = ortho;
142  }
143 
145  inline bool orthoCulling() const
146  {
147  return myOrthoFlag;
148  }
149 
151  inline void setSkyRendering(bool renderSky)
152  {
153  mySkyFlag = renderSky;
154 
155  }
156 
158  inline bool skyRendering() const
159  {
160  return mySkyFlag;
161  }
162 
164  inline void setDynamicLights(bool enabled)
165  {
166  myDynamicLightsFlag = enabled;
167  }
168 
170  inline bool dynamicLights() const
171  {
172  return myDynamicLightsFlag;
173  }
174 
176  inline void setDynamicOcean(bool enabled)
177  {
178  myDynamicOceanFlag = enabled;
179  }
180 
182  inline bool dynamicOcean() const
183  {
184  return myDynamicOceanFlag;
185  }
186 
188  void setScaling( bool scaling )
189  {
190  myScalingFlag = scaling;
191  }
192 
194  inline bool scaling() const
195  {
196  return myScalingFlag;
197  }
198 
200  void setScaleFactor( double scaleFactor )
201  {
202  myScaleFactor = scaleFactor;
203  }
204 
206  inline double scaleFactor() const
207  {
208  return myScaleFactor;
209  }
210 
212  void setCoordinateSystemChanged( bool changed )
213  {
214  myCoordinateSystemChanged = changed;
215  }
216 
218  inline bool coordinateSystemChanged() const
219  {
220  return myCoordinateSystemChanged;
221  }
222 
225  inline void setNodeXRScaler( DtOsgNodeXRScaler* scaler )
226  {
227  myNodeXRScaler = scaler;
228  }
229 
231  inline double calculateXRScale( const osg::Camera& camera,
232  const osg::Node& node )
233  {
234  if ( myNodeXRScaler.valid() )
235  {
236  return myNodeXRScaler->calculateXRScale( *this, camera, node );
237  }
238  else
239  {
240  return 1.;
241  }
242  }
243 
245  void setScaleType( DtObserverObject::ScaleType scaleType )
246  {
247  myScaleType = scaleType;
248  }
249 
251  inline DtObserverObject::ScaleType scaleType() const
252  {
253  return myScaleType;
254  }
255 
260  void setClampedPixelSize(double d)
261  {
262  myClampedPixelSize = d;
263  }
264 
266  double clampedPixelSize() const
267  {
268  return myClampedPixelSize;
269  }
270 
274  inline void setDynamicWaterVisibilityEnable( bool enable )
275  {
276  myDynamicWaterVisibilityEnable = enable;
277  }
278 
280  inline bool dynamicWaterVisibilityEnable() const
281  {
282  return myDynamicWaterVisibilityEnable;
283  }
284 
287  inline void setDynamicWaterVisibilityMax( double visMax )
288  {
289  myDynamicWaterVisibilityMax = visMax;
290  }
291 
294  inline double dynamicWaterVisibilityMax() const
295  {
296  return myDynamicWaterVisibilityMax;
297  }
298 
301  inline void setPagedLodMagnificationScaleFactor(float factor)
302  {
303  myPagedLodMagnificationScaleFactor = factor;
304  }
305 
308  inline float pagedLodMagnificationScaleFactor() const
309  {
310  return myPagedLodMagnificationScaleFactor;
311  }
312 
313  protected:
314 
318  double myAltitude2D;
319  double myAltitude3D;
320  bool mySkyFlag;
331  osg::ref_ptr<DtOsgNodeXRScaler> myNodeXRScaler;
334  unsigned int myModelSet;
335  };
336 
339  class DT_DLL_VRVOSG DtOsgFixedScaleParameters : public osg::Referenced
340  {
341  public:
343  : myFixedPixelSize( 1.0 )
344  , myLength( 0.0 )
345  , myWidth( 0.0 )
346  , myHeight( 0.0 )
347  , myScaleX(true)
348  , myScaleY(true)
349  , myScaleZ(true)
350  {
351 }
352 
354  {
355  }
356 
357  void setFixedPixelSize(double d)
358  {
359  myFixedPixelSize = d;
360  }
361 
362  double fixedPixelSize() const
363  {
364  return myFixedPixelSize;
365  }
366 
367  void setDimensions(double length, double width, double height)
368  {
369  myLength = length; myWidth = width; myHeight = height;
370  }
371 
372  inline double length() const
373  {
374  return myLength;
375  }
376 
377  inline double width() const
378  {
379  return myWidth;
380  }
381 
382  inline double height() const
383  {
384  return myHeight;
385  }
386 
387  inline void calculateScaleFactors(const osgUtil::CullVisitor& visitor,
388  const osg::BoundingSphere& sphere, DtOsgCullVisitorParameters* info,
389  double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
390  {
391  double clampedSize =
392  visitor.clampedPixelSize( sphere.center(), info->terrainRadius() );
393  info->setClampedPixelSize(clampedSize);
394 
395  calculateScaleFactors( sphere, *info, scaleFactorX,
396  scaleFactorY, scaleFactorZ );
397  }
398 
399  inline void calculateScaleFactors(const osg::BoundingSphere& sphere, const DtOsgCullVisitorParameters& info,
400  double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
401  {
402  scaleFactorX = scaleFactorY = scaleFactorZ = 1.0;
403 
404  double metersPerPixel = info.terrainRadius() / info.clampedPixelSize(); // Meters per pixel
405  double curPixels = myWidth / metersPerPixel; // Pixels needed to draw
406 
407  if (myScaleX)
408  {
409  scaleFactorX = myFixedPixelSize / curPixels;
410  }
411 
412  if (myScaleY)
413  {
414  scaleFactorY = scaleFactorX;
415  }
416 
417  if (myScaleX)
418  {
419  scaleFactorZ = 1.0;
420  }
421  }
422 
423  void setScaleX(bool b)
424  {
425  myScaleX = b;
426  }
427 
428  inline bool scaleX() const
429  {
430  return myScaleX;
431  }
432 
433  void setScaleXY(bool b)
434  {
435  myScaleY = b;
436  }
437 
438  inline bool scaleY() const
439  {
440  return myScaleY;
441  }
442 
443  void setScaleZ(bool b)
444  {
445  myScaleZ = b;
446  }
447 
448  inline bool scaleZ() const
449  {
450  return myScaleZ;
451  }
452 
453  protected:
455  double myLength, myWidth, myHeight;
456  bool myScaleX, myScaleY, myScaleZ;
457  };
458 
459 }
460 
461 

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)