VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtTritonDrawable.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <osg/Camera>
13 #include <osg/Drawable>
14 #include <osg/TextureCubeMap>
17 #include <vrvOsg/DtOsgRenderer.h>
20 #include <matrix/vlVector.h>
21 #include <osg/StateSet>
22 
24 
25 #include <vrvTriton/vrvTriton.h>
26 
27 #include <map>
28 
29 
30 //this is based on the enum Shaders in Ocean.h
31 #define NUM_TRITON_SHADER_TYPES 4
32 
33 namespace Triton
34 {
35  class Ocean;
36  class Environment;
37  class ResourceLoader;
38 }
39 
40 namespace makVrv
41 {
42  class DtPlanarReflection;
43  class DtObserverObject;
44  class DtTritonManager;
45 
47  struct TritonUpdateCallback : public virtual osg::Drawable::UpdateCallback
48  {
50  TritonUpdateCallback(Triton::Ocean *ocean, makVrv::DtDe& de) : myOcean(ocean), myDe(de) {}
51 
54  virtual void update(osg::NodeVisitor* nv, osg::Drawable*);
55 
56  Triton::Ocean *myOcean;
58  };
59 
61  class DtTritonDrawable : public osg::Drawable
62  {
63  public:
65  DtTritonDrawable( makVrv::DtDe& de, const DtTritonManager& tritonManager,
66  DtEnvironmentInfo& environmentInfo, bool geocentric,
67  osg::TextureCubeMap * cubeMap = NULL );
68 
69  virtual bool isSameKindAs(const Object* obj) const {
70  return dynamic_cast<const DtTritonDrawable*>(obj)!=NULL;
71  }
72  virtual Object* cloneType() const
73  {
76  }
77  virtual Object* clone(const osg::CopyOp& copyop) const
78  {
81  }
82 
84  virtual Triton::Ocean* ocean() { return myOcean; }
85 
87  virtual Triton::Environment* environment() { return myEnvironment; }
88 
90  virtual void setBeach(osg::Vec3 beachOrigin, osg::Vec3 normal);
91 
93  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
94 
96  virtual void setPlanarReflections(bool enabled);
97  virtual bool planarReflections() const;
98 
100  virtual void setBreakingWaveAmplitude(float meters);
101  virtual float getBreakingWaveAmplitude() const;
102 
106  virtual void setHeightMap(bool enabled);
107  virtual bool heightMap() const;
108 
113  };
114 
118  virtual void setQuality(TritonQuality quality);
119  virtual TritonQuality getQuality() const;
120 
124  virtual void setBreakingWavesMap(bool enabled);
125  virtual bool breakingWavesMap() const;
126 
128  virtual void setWaveDampingDistance(float meters);
129  virtual float waveDampingDistance() const;
130 
133  virtual void setMaxReflectionWindSpeed(double metersPerSecond)
134  {
135  myMaxWindForReflections = metersPerSecond;
136  }
137 
139  virtual void setUnderwaterFogColor(const osg::Vec4& color)
140  {
141  myUnderwaterFogColor = color;
142  }
143 
144  virtual const osg::Vec4& getUnderwaterFogColor() const
145  {
146  return myUnderwaterFogColor;
147  }
148 
150  virtual void setUnderwaterVisibility(double visibility)
151  {
152  myUnderwaterVisibility = visibility;
153  }
154 
155  virtual double getUnderwaterVisibility() const
156  {
157  return myUnderwaterVisibility;
158  }
159 
162  virtual void setWaterVisibility(double visibility)
163  {
164  myDefaultVisibility = visibility;
165  }
166 
167  virtual double getWaterVisibility() const
168  {
169  return myDefaultVisibility;
170  }
171 
173  virtual void setSurgeDepth(float depth)
174  {
175  mySurgeDepth = std::max( 0.2f, depth );
176  }
177 
178  virtual float getSurgeDepth() const
179  {
180  return mySurgeDepth;
181  }
182 
184  virtual bool getIsInitialized() const
185  {
187  }
188 
191  virtual void setHeightMapResolution(float metersPerTexel);
192 
193  virtual float getHeightMapResolution() const;
194 
197  virtual void setBreakingWavesMapResolution(float metersPerTexel);
198 
199  virtual float getBreakingWavesMapResolution() const;
200 
202  virtual void enableReflections(bool enabled);
203 
205  boost::signal<void ()> signal_postInitialize;
206 
208  virtual void releaseGLObjects(osg::State* state=0) const;
209 
211  void heightMapChanged();
212 
215 
216  protected:
217  void shaderUpdateLightUniforms(osg::RenderInfo& info, osg::State &state, GLint shader, int shaderType) const;
218 
219  void shaderUpdateViewMatrices(osg::State &state, GLint shader, int shaderType
220  , const Matrix4_32& view_matrix_32
221  , const Matrix4_32& view_inverse_transpose_matrix_32) const;
222 
223  void updateCloudShadows(osg::State &state, GLint shader, int shaderType
224  , GLboolean bIsCloudShadowActive
225  , unsigned int cloudshadowTextureUnit
226  , unsigned int cloudshadowTextureIndex
227  , osg::Matrixf textureViewProjMatrix) const;
228 
229  void GetShaderUniformHandles(GLint shader, int shaderType) const;
230 
231  osg::ref_ptr<DtPlanarReflection> getOrCreatePlanarReflection(osg::RenderInfo& renderInfo);
232 
233  osg::ref_ptr<DtPlanarReflection> setupPlanarReflections( osg::RenderInfo &renderInfo );
234 
235  DtTritonHeightMapManager *getOrCreateHeightMapManager(osg::RenderInfo& renderInfo);
236 
238 
239  void setup( void );
240  void cleanup( void );
241 
242  osg::Node * createMirroredWorldGraph( makVrv::DtOsgRenderer& osgRenderer,
243  const osg::Matrix & localToWorld, const osg::Vec3 currentPos );
244 
245  void computeReflectionMatrix( const osg::Vec3& currentPosition );
246 
247  void GetShaderUniformHandles() const;
248 
249  void applyLighting(osg::RenderInfo& info) const;
250 
251  void applyQuality() const;
252 
253  void updateShader(osg::Node *node, const osg::State& state) const;
254 
255  void computeReflectionBlend( const osg::Vec3& currentPosition );
256 
258 
259  virtual ~DtTritonDrawable();
260 
261  osg::ref_ptr< osg::TextureCubeMap > myCubeMap;
262  osg::ref_ptr< osg::MatrixTransform > myMirrorMatrixTransform;
263 
264  Triton::ResourceLoader *myResourceLoader;
265  Triton::Environment *myEnvironment;
266  Triton::Ocean *myOcean;
267 
284 
285  // This boolean indicates whether or not planar reflections have been requested,
286  // regardless of the internal state of the drawable. When it finally gets around
287  // to setting up planar reflections, this flag is checked
289 
292 
294 
296 
298 
299  std::map<osg::Camera *, osg::ref_ptr<makVrv::DtPlanarReflection> > myPlanarReflectionCameraMap;
300  std::map<osg::Camera *, makVrv::DtTritonHeightMapManager *> myHeightMapManagerMap;
301  std::map<osg::Camera *, makVrv::DtTritonBreakingWavesMapManager *> myBreakingWavesMapManagerMap;
302 
303  osg::ref_ptr< osg::ClipNode > myClipNode;
304  osg::Plane myReflectionPlane;
305  osg::Matrix myReflectionMatrix;
307 
309 
314 
317 
320 
324 
325  mutable std::vector<unsigned int> myUserShaderVector;
326 
328 
330 
332 
333  };
334 }

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)