VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtOsgChannel.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 <vrvOsg/vrvOsg.h>
13 
14 #include <vrvCore/DtChannel.h>
15 #include <vrvOsg/DtOsgRenderer.h>
16 #include <vrvOsg/DtCameraNode.h>
17 
18 #include <osg/ref_ptr>
19 #include <osgViewer/View>
20 
21 #include <boost/signals.hpp>
22 
23 namespace osg
24 {
25  class Matrixd;
26 }
27 
28 namespace osgViewer
29 {
30  class StatsHandler;
31 }
32 
33 
34 namespace makVrv
35 {
36  class DtLight;
37  class DtChannelSpecificGroup;
38  class DtOsgWindow;
39  class DtOsgChannelCreator;
40  class DtChannelManager;
41  class DtWindowConfiguration;
42  class DtSensorModule;
43  class DtSensor;
44  class DtOsgObserverObject;
45  class DtOsgCullVisitorParameters;
46 
54  {
55  protected:
56  friend class DtOsgChannelCreator;
57 
61  DtOsgChannel(DtDe& de, DtOsgWindow* window, DtChannelConfiguration& config);
62 
64 
65 
70  virtual bool initialize();
71 
73 
74  virtual void initializeNormalized2DCamera();
75  virtual void initialize2DCamera( int w, int h );
76  virtual void initializeSceneCamera( );
77  virtual void initializeRenderTexture( int format, int sourceFormat = GL_RGBA, int sourceType = GL_UNSIGNED_BYTE);
78  virtual void initializeRTTCamera( );
79 
80  void clearRttCamera();
81 
82  virtual void recreateRTTCamera( );
83 
85 
87  void setShadowState(bool enable);
88 
90  virtual void addOverlayDrawablesToCameras();
91 
93  virtual void initializeStatsHandler();
94 
100  virtual void initializeSignalConnections();
102 
103  public:
105  virtual ~DtOsgChannel();
106 
111  void setSensorName( const std::string& sensorName );
112 
114  virtual void setClearColor(float r,float g,float b, float a);
115 
119  virtual void setWindow(DtWindow* view);
120 
122  virtual const DtWindow* window() const;
123 
125  virtual void setViewport(int x,int y,int width, int height);
126 
128  virtual void getViewport(int& x,int& y, int& width,int& height) const;
129 
131  virtual void setCameraPosition(double x, double y, double z);
132 
134  virtual void setCameraOrientation( double psi, double theta, double phi );
135 
140  virtual void setCameraPositionAndOrientation( double x, double y,
141  double z, double psi, double theta, double phi );
142  virtual void setCameraPositionAndOrientation( osg::Vec3d& pos,
143  osg::Quat& orient );
144 
146  virtual void getCameraPositionAndOrientation( osg::Vec3d& position,
147  osg::Quat& rotation ) const;
148 
149  virtual void update();
150 
152  virtual void connectToObserver();
153 
156  virtual void setProjectionMatrixAsPerspective(double fovy,
157  double aspectRatio, double zNear, double zFar);
158 
160  virtual void setProjectionMatrixAsFrustum (double left, double right,
161  double bottom, double top, double zNear, double zFar);
162 
164  virtual osgViewer::View& view();
165 
167  virtual DtCameraNode* sceneCamera();
168  virtual const DtCameraNode* sceneCamera() const;
169 
171  virtual DtCameraNode* rttCamera();
172 
174  virtual DtCameraNode* overlayCamera();
175 
176 
178  virtual DtCameraNode* normalizedOverlayCamera();
179 
181  virtual void setRenderToTexture(bool enabled, int format = GL_RGBA, int sourceFormat = GL_RGBA, int sourceType = GL_UNSIGNED_BYTE);
182 
185  virtual osg::ref_ptr<osg::Texture2D> getRenderTexture();
186 
188  virtual osg::ref_ptr<osg::Texture2D> getDepthTexture() const;
189 
191  int shadowQuality() const;
192 
195  virtual void setProjectionResizePolicy(
197 
200  virtual void updateProjection();
201 
202  void projectionUnitsToFrustum( DtChannelConfiguration::ProjectionUnits units,
203  double &left, double zNear, double &right, double &top, double &bottom );
204 
206  virtual void connectChannelToScene();
207 
209  virtual bool processMouseEvent( const DtMouseEvent& ev);
210 
212  virtual bool processKeyboardEvent(const DtKeyEvent & ev);
213 
215  //virtual DtDynamicOverlay* overlay();
216 
218  void getWorldToWindowMatrix( osg::Matrix& worldToWindowMatrix ) const;
219 
221  virtual void moveMouseToScreenLocation(float screenX, float screenY);
222 
226  virtual void projectToScreen( double dbX, double dbY, double dbZ,
227  double& screenX, double& screenY, double& screenZ );
228 
230  virtual void projectToWorld( double screenX, double screenY,
231  double& dbX, double& dbY, double& dbZ );
232 
234  virtual const std::string& name();
235 
240  boost::signal<void (int, int, int, int)> signal_viewportChanged;
241 
242  typedef std::list<std::string> PostProcessorEffectList;
243 
247  virtual void addPostProcessEffect(std::string postProcessorEffect);
248 
252  virtual void removePostProcessEffect(std::string postProcessorEffect);
253 
255  virtual void set3DCullVisitorParams( DtOsgCullVisitorParameters* params );
256  virtual void set2DCullVisitorParams( DtOsgCullVisitorParameters* params );
258 
260  virtual void toggleOnScreenStats();
261 
263  virtual void printStats();
264 
265  virtual void setEnablePostProcessors(bool enable);
266 
267  virtual bool getEnablePostProcessors();
268 
269  protected:
270  void makeObserverToCameraMatrix( osg::Vec3d& orient,
271  osg::Matrixd& offsetObserverToCamera );
272  void makeObserverToCameraMatrix( osg::Quat& qObserverToWorld,
273  osg::Matrixd& offsetObserverToCamera );
274 
276  virtual void calculateNearFar(double& zNear, double& zFar);
277 
281  virtual bool useAttachedForNearClip( double alt );
282 
284  virtual double calculateNearClip( double alt, double zFar );
285 
287  virtual double calculateFarClip( double alt );
288 
290  virtual void projectFor3D();
291 
293  virtual void projectFor2D();
294 
298  virtual void stopUsingModelSet( int modelSet );
299 
303  virtual void startUsingModelSet( int modelSet );
304 
306  virtual void stopUsingSensor( DtSensor* sensor );
307 
309  virtual void startUsingSensor( DtSensor* sensor );
310 
312  virtual void slot_sensorRemoved( DtSensor* sensor );
313 
315  virtual void slot_visualizerRootAdded( int modelSet, int visualType );
316 
318  virtual void slot_observerModelSetChanged( DtObserverObject* observer,
319  int modelSet );
320 
322  virtual void slot_observerSettingChanged( DtObserverObject* observer,
323  int setting, bool value );
324 
326  virtual void slot_observerSettingRemoved( DtObserverObject* observer,
327  int setting );
328 
330  virtual void slot_channelAdded(DtChannelManager* mgr, DtChannel* channel);
331 
333  virtual void slot_channelDestroyed(DtChannelManager* mgr, DtChannel* channel);
334 
336  virtual void slot_windowConfigurationModified( const std::string& deName,
337  const std::string& oldWindowName, const DtWindowConfiguration& config);
338 
340  virtual void slot_onCoordinateSystemChanged();
341 
345  virtual void throttleDatabasePager(DtChannelManager* mgr, DtChannel* channel);
346 
347 
348 
349  protected:
351  void stopUsingModelSetWork( int modelSet );
352 
354  void startUsingModelSetWork( int modelSet );
355 
357  void initializeRenderTextureColor(int format, int sourceFormat, int sourceType);
358 
360  void initializeRenderTextureDepth();
361 
362  void enableLighting(osg::ref_ptr<osg::Camera> camera, bool enable);
363 
364 
365 
366  protected:
367  typedef std::map< int, DtChannelSpecificGroup*> VisualTypeMap;
368 
369  osg::ref_ptr<osgViewer::View> myView;
372 
374 
376 
378 
380 
381  osg::ref_ptr<osg::Group> myRoot;
382 
383  //The master 3D camera
384  osg::ref_ptr<DtCameraNode> mySceneCamera;
385 
386  //The 2D camera in screen space(0,0 - w,h)
387  osg::ref_ptr<DtCameraNode> my2DCamera;
388 
389  //The 2D camera in normalize screen space (0,0 - 1,1)
390  osg::ref_ptr<DtCameraNode> myNormalized2DCamera;
391 
393  osg::ref_ptr<osg::Texture2D> myRenderTexture;
394  osg::ref_ptr<osg::Texture2D> myDepthTexture;
395 
397  osg::ref_ptr<DtCameraNode> myRTTCamera;
398 
403 
404  // ex. { "dof", "rainsplash", "oceanspray" }
405  // list of post processor effect names to enable on update
407 
408  osg::Node::NodeMask myOldSceneCameraNodeMask;
409 
411 
412  osg::ref_ptr<osgViewer::StatsHandler> myStatsHandler;
413  //keep track of the current stats handler state so it can be set correctly when it is recreated.
415 
417 
418  };
419 
423  {
424  public:
426  virtual DtChannel* create(DtDe& de, DtWindow* window, DtChannelConfiguration& config);
427  };
428 }

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)