VR-Forces 4.1 Class Documentation
DtOsgCullVisitorParameters.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2011 MAK Technologies, Inc.
3  * All rights reserved.
4  *****************************************************************************/
5 /*****************************************************************************
6  * $RCSfile: DtOsgCullVisitorParameters.h,v $ $Revision: 1.51 $ $State: Exp $
7  *****************************************************************************/
8 
14 
15 #pragma once
16 
17 #include <vrvOsg/vrvOsg.h>
18 #include <osg/Referenced>
19 #include <osg/BoundingBox>
20 #include <osg/BoundingSphere>
21 #include <osg/Vec2>
22 #include <osgUtil/CullVisitor>
23 
25 
26 #include <algorithm>
27 #include <math.h>
28 
29 #ifdef min
30 #undef min
31 #endif
32 
33 namespace makVrv
34 {
38  class DT_DLL_VRVOSG DtOsgCullVisitorParameters : public osg::Referenced
39  {
40  public:
41 
44  : osg::Referenced()
45  , mySkyFlag(true)
46  , myOrthoFlag(false)
47  , myCameraResolution( 1.0 )
48  , myTerrainRadius( 1.0 )
49  , myScalingFlag( true )
50  , myScaleFactor( 1.0 )
51  , myClampedPixelSize( 1.0 )
52  , myCameraMagnification( 1.0 )
53  , myScaleType( DtObserverObject::XRScale )
54  , myCoordinateSystemChanged( false )
55  , myAltitude2D( 0. )
56  {
57  }
58 
60  void setCameraMagnification( double mag )
61  {
62  myCameraMagnification = mag;
63  }
64 
65  inline double cameraMagnification() const
66  {
67  return myCameraMagnification;
68  }
69 
71  void setCameraResolution(double factor)
72  {
73  myCameraResolution = factor;
74  }
75 
77  inline double cameraResolution() const
78  {
79  return myCameraResolution;
80  }
81 
83  void setTerrainRadius(double rad)
84  {
85  myTerrainRadius = rad;
86  }
87 
89  void setAltitude2D( double altitude )
90  {
91  myAltitude2D = altitude;
92  }
93 
94  double altitude2D() const
95  {
96  return myAltitude2D;
97  }
98 
100  inline double terrainRadius() const
101  {
102  return myTerrainRadius;
103  }
104 
106  void setOrthoCulling(bool ortho)
107  {
108  myOrthoFlag = ortho;
109  }
110 
112  inline bool orthoCulling() const
113  {
114  return myOrthoFlag;
115  }
116 
117  inline void setSkyRendering(bool renderSky)
118  {
119  mySkyFlag = renderSky;
120 
121  }
122 
123  inline bool skyRendering() const
124  {
125  return mySkyFlag;
126  }
127 
129  void setScaling( bool scaling )
130  {
131  myScalingFlag = scaling;
132  }
133 
135  inline bool scaling() const
136  {
137  return myScalingFlag;
138  }
139 
141  void setScaleFactor( double scaleFactor )
142  {
143  myScaleFactor = scaleFactor;
144  }
145 
147  inline double scaleFactor() const
148  {
149  return myScaleFactor;
150  }
151 
153  void setCoordinateSystemChanged( bool changed )
154  {
155  myCoordinateSystemChanged = changed;
156  }
157 
159  inline bool coordinateSystemChanged() const
160  {
161  return myCoordinateSystemChanged;
162  }
163 
165  void setScaleType( DtObserverObject::ScaleType scaleType )
166  {
167  myScaleType = scaleType;
168  }
169 
171  inline DtObserverObject::ScaleType scaleType() const
172  {
173  return myScaleType;
174  }
175 
176  inline double calculateFixedScale(double basempp, double mpp )
177  {
178  return mpp / basempp;
179  }
180 
181  inline double calculateScaleFromDistance(double distance, double r )
182  {
183  double distsqr = distance * distance;
184  double scaleDistRatio = 250 - 2.0 * myScaleFactor;
185  double scaleBasedOnDistance = sqrt(distsqr)/scaleDistRatio;
186 
187  // Calculate a scale for the entity based on its size.
188  // Scale the scale so that big entities are scaled less and
189  // small entities are scaled more. For example, a lifeform model
190  // should be only slightly smaller than a helicopter and a large
191  // submarine should only be a few times bigger than a helicopter
192  if ( r > 0.0 )
193  {
194  //double scaleScale = 3.0 / sqrt(r);
195  double scaleScale = 6.0 / r;
196  scaleBasedOnDistance *= scaleScale;
197  }
198 
199  if (scaleBasedOnDistance < 1.0)
200  {
201  scaleBasedOnDistance = 1.0;
202  }
203 
204  return scaleBasedOnDistance;
205  }
206 
207  void setClampedPixelSize(double d)
208  {
209  myClampedPixelSize = d;
210  }
211 
212  double clampedPixelSize() const
213  {
214  return myClampedPixelSize;
215  }
216 
217  protected:
218 
222  double myAltitude2D;
223  bool mySkyFlag;
230  };
231 
234  class DT_DLL_VRVOSG DtOsgFixedScaleParameters : public osg::Referenced
235  {
236  public:
238  : myFixedPixelSize( 1.0 )
239  , myLength( 0.0 )
240  , myWidth( 0.0 )
241  , myHeight( 0.0 )
242  , myScaleX(true)
243  , myScaleY(true)
244  , myScaleZ(true)
245  {
246 }
247 
249  {
250  }
251 
252  void setFixedPixelSize(double d)
253  {
254  myFixedPixelSize = d;
255  }
256 
257  double fixedPixelSize() const
258  {
259  return myFixedPixelSize;
260  }
261 
262  void setDimensions(double length, double width, double height)
263  {
264  myLength = length; myWidth = width; myHeight = height;
265  }
266 
267  inline double length() const
268  {
269  return myLength;
270  }
271 
272  inline double width() const
273  {
274  return myWidth;
275  }
276 
277  inline double height() const
278  {
279  return myHeight;
280  }
281 
282  inline void calculateScaleFactors(const osgUtil::CullVisitor& visitor,
283  const osg::BoundingSphere& sphere, DtOsgCullVisitorParameters* info,
284  double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
285  {
286  double clampedSize =
287  visitor.clampedPixelSize( sphere.center(), info->terrainRadius() );
288  info->setClampedPixelSize(clampedSize);
289 
290  calculateScaleFactors( sphere, *info, scaleFactorX,
291  scaleFactorY, scaleFactorZ );
292  }
293 
294  inline void calculateScaleFactors(const osg::BoundingSphere& sphere, const DtOsgCullVisitorParameters& info,
295  double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
296  {
297  scaleFactorX = scaleFactorY = scaleFactorZ = 1.0;
298 
299  double metersPerPixel = info.terrainRadius() / info.clampedPixelSize(); // Meters per pixel
300  double curPixels = myWidth / metersPerPixel; // Pixels needed to draw
301 
302  if (myScaleX)
303  {
304  scaleFactorX = myFixedPixelSize / curPixels;
305  }
306 
307  if (myScaleY)
308  {
309  scaleFactorY = scaleFactorX;
310  }
311 
312  if (myScaleX)
313  {
314  scaleFactorZ = 1.0;
315  }
316  }
317 
318  void setScaleX(bool b)
319  {
320  myScaleX = b;
321  }
322 
323  inline bool scaleX() const
324  {
325  return myScaleX;
326  }
327 
328  void setScaleXY(bool b)
329  {
330  myScaleY = b;
331  }
332 
333  inline bool scaleY() const
334  {
335  return myScaleY;
336  }
337 
338  void setScaleZ(bool b)
339  {
340  myScaleZ = b;
341  }
342 
343  inline bool scaleZ() const
344  {
345  return myScaleZ;
346  }
347 
348  protected:
350  double myLength, myWidth, myHeight;
351  bool myScaleX, myScaleY, myScaleZ;
352  };
353 
354 }
355 
356 

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)