28 #include <osg/ShapeDrawable>
32 #include <osgGA/FlightManipulator>
33 #include <osgGA/DriveManipulator>
34 #include <osgGA/UFOManipulator>
35 #include <osgGA/KeySwitchMatrixManipulator>
36 #include <osgGA/StateSetManipulator>
37 #include <osgGA/AnimationPathManipulator>
38 #include <osgGA/TerrainManipulator>
39 #include <osgViewer/ViewerEventHandlers>
40 #include <osgViewer/View>
42 #include <osgDB/ReadFile>
44 #include "exceptions/WGEInitFailed.h"
45 #include "WGE2DManipulator.h"
46 #include "WGEGroupNode.h"
47 #include "WGENoOpManipulator.h"
48 #include "WGEZoomTrackballManipulator.h"
49 #include "WPickHandler.h"
51 #include "../common/WConditionOneShot.h"
52 #include "../common/WThreadedRunner.h"
54 #include "WGEViewer.h"
56 WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata,
int x,
int y,
int width,
int height,
59 boost::enable_shared_from_this<
WGEViewer >(),
64 m_inAnimationMode( false ),
71 #ifdef WGEMODE_MULTITHREADED
72 m_View = osg::ref_ptr<osgViewer::View>(
new osgViewer::View );
75 m_View = osg::ref_ptr<osgViewer::Viewer>(
new osgViewer::Viewer );
78 osg::ref_ptr< WGECamera > cam(
new WGECamera( width, height, projectionMode ) );
79 m_View->setCamera( cam );
84 #ifdef WGEMODE_MULTITHREADED
90 switch( projectionMode )
92 case( WGECamera::ORTHOGRAPHIC ):
95 if( name != std::string(
"Main View" ) )
97 case( WGECamera::PERSPECTIVE ):
101 m_View->setLightingMode( osg::View::HEADLIGHT );
104 case( WGECamera::TWO_D ):
107 case( WGECamera::TWO_D_UNIT ):
112 throw WGEInitFailed( std::string(
"Unknown projection mode" ) );
116 m_View->addEventHandler(
new osgViewer::StatsHandler );
120 m_bgColor =
m_properties->addProperty(
"Background Color",
"Default background color if not overwritten by a camera effect.",
123 m_throwing =
m_properties->addProperty(
"Throwing",
"If checked, you can grab the scene and throw it. It will keep the rotation impulse.",
127 WPropGroup effects =
m_properties->addPropertyGroup(
"Camera Effects",
"Several effects that to not depend on any scene content." );
133 m_View->setSceneData(
m_scene );
145 throw WGEInitFailed( std::string(
"Initialization of WGEViewer failed" ) );
155 #ifdef WGEMODE_SINGLETHREADED
156 osg::ref_ptr<osgViewer::Viewer>
158 osg::ref_ptr<osgViewer::View>
169 m_View->setCameraManipulator( manipulator );
175 return m_View->getCameraManipulator();
180 m_View->setCamera( camera );
234 #ifdef WGEMODE_SINGLETHREADED
241 m_View->getEventQueue()->windowResize( 0, 0, width, height );
246 m_View->getCamera()->setViewport( 0, 0, width, height );
305 const GLubyte* vendor = glGetString( GL_VENDOR );
306 m_vendor =
reinterpret_cast< const char*
>( vendor );
309 m_camera->setInitialDrawCallback( NULL );
337 m_View->setCameraManipulator( anim );
393 getVignette()->setEnabledByDefault( activeByDefault );
osg::ref_ptr< osgViewer::GraphicsWindow > m_GraphicsWindow
OpenSceneGraph render window.
WGEViewerEffectVignette::SPtr m_effectVignette
Vignette effect.
osg::ref_ptr< WGEViewerEffectVignette > SPtr
Convenience typedef for a boost::shared_ptr< WGEViewerEffectVignette >.
osg::ref_ptr< WGEViewerEffectHorizon > SPtr
Convenience typedef for a boost::shared_ptr< WGEViewerEffectHorizon >.
virtual ~WGEViewer()
Destructor.
New OSG manipulator: AnimationManipulator.
This class is a screen recorder.
virtual void close()
Initiates a close event for this viewer.
WBoolFlag::SPtr m_rendered
This flag is true and notifies after the first rendered frame.
std::string getVendor() const
Returns the queried vendor string.
void setEffectsActiveDefault(bool activeByDefault=true)
Activate viewer effects by default.
osg::ref_ptr< WPickHandler > getPickHandler()
Getter for the pick handler.
osg::ref_ptr< const WGEViewerEffectImageOverlay > ConstSPtr
Convenience typedef for a boost::shared_ptr< const WGEViewerEffectImageOverlay >. ...
WGEScreenCapture::RefPtr m_screenCapture
The screen capture callback.
virtual void close()
Close the viewer, but wait for the rendering thread to finish.
virtual void resize(int width, int height)
Updates size information.
WGEScreenCapture::RefPtr getScreenCapture() const
Returns the main cameras screen capture callback.
osg::ref_ptr< osgViewer::View > getView()
Getter for OpenSceneGraph View instance.
osg::ref_ptr< osgGA::MatrixManipulator > m_animationModeManipulatorBackup
The manipulator that was set before entering animation mode.
Implements a WCondition, but can be fired only ONCE.
osg::ref_ptr< osg::GraphicsContext > m_GraphicsContext
OpenSceneGraph render context.
void reset()
Resets the view using the installed manipulator.
boost::shared_ptr< WFlag< T > > SPtr
Convenience typedef for a boost::shared_ptr.
ProjectionMode
List of possible camera modes.
virtual void operator()(osg::RenderInfo &renderInfo) const
Query operator.
osg::ref_ptr< WGEGroupNode > getScene()
Returns the currently set OSG node.
osg::ref_ptr< WGEScreenCapture > RefPtr
Convenience typedef.
std::string getName() const
Returns the name of the viewer.
WPropBool m_throwing
The switch to enable the throw- functionality of some OSG manipulators.
osg::ref_ptr< WGEAnimationManipulator > RefPtr
Convenience typedef.
Class to handle events with a pick.
void setCameraManipulator(osg::ref_ptr< osgGA::MatrixManipulator > manipulator)
Sets the camera manipulator to use.
osg::ref_ptr< QueryCallback > m_queryCallback
The callback used for querying OpenGL features.
Class managing a single graphics context and OSG GraphicsWindow.
void updateBgColor()
Update the default clear color (bg color).
WGEAnimationManipulator::RefPtr animationMode(bool on=true)
The (de-)activates the animation mode.
WProperties::SPtr getProperties() const
Return a pointer to the properties object of the view.
virtual void paint()
Repaints the contents.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
Exception thrown if initialization of the graphics engine fails.
osg::ref_ptr< WGEGroupNode > m_scene
reference to the scene which is displayed by viewer
osg::ref_ptr< osgGA::MatrixManipulator > getCameraManipulator()
Returns current active camera manipulator.
Class for wrapping around the OSG Camera class.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
osg::ref_ptr< const WGEViewerEffectHorizon > ConstSPtr
Convenience typedef for a boost::shared_ptr< const WGEViewerEffectHorizon >.
WGEViewerEffectVignette::SPtr getVignette()
Return the vignette render effect for modification.
WBoolFlag::SPtr isFrameRendered() const
Returns the flag which denotes whether a frame was rendered.
void setCamera(osg::ref_ptr< WGECamera > camera)
Sets the current camera.
osg::ref_ptr< WGEGroupNode > m_sceneMainNode
Keep the currently set scene node.
bool m_inAnimationMode
True -> animation mode on.
Class for managing one view to the scene.
This is an OSG Manipulator implementation which does nothing.
osg::ref_ptr< WPickHandler > m_pickHandler
Pointer to the pick handler of the viewer.
std::string m_name
The name of the viewer.
Small class used for querying glGet info during rendering.
void setScene(osg::ref_ptr< WGEGroupNode > node)
Sets the scene graph node to be used for rendering.
boost::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
QueryCallback(osg::ref_ptr< WGECamera > camera, WBoolFlag::SPtr run)
Constructor.
void setThrow(bool allowThrow=true)
En-/Disables throwing.
WGEViewerEffectHorizon::SPtr getBackground()
Return the background render effect for modification.
void updateThrowing()
Update throw setting of the manipulator (if supported).
void resize()
Change camera parameters which should be changed on a resize.
WGEViewerEffectImageOverlay::SPtr m_effectImageOverlay
Image overlay effect.
virtual ~QueryCallback()
Destructor.
WProperties::SPtr m_properties
The property object for the view.
virtual void resize(int width, int height)
Updates size information.
WColor getBgColor() const
Returns the current default background color.
WGEViewerEffectImageOverlay::SPtr getImageOverlay()
Return the overlay render effect for modification.
osg::ref_ptr< WGECamera > getCamera()
Returns the camera currently in use.
WGEViewer(std::string name, osg::ref_ptr< osg::Referenced > wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode=WGECamera::ORTHOGRAPHIC)
Default constructor.
osg::ref_ptr< WGEViewerEffectImageOverlay > SPtr
Convenience typedef for a boost::shared_ptr< WGEViewerEffectImageOverlay >.
WPropColor m_bgColor
The default clear color (bg color).
New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
boost::shared_ptr< WGEViewer > SPtr
Convenience typedef.
WGEViewerEffectHorizon::SPtr m_effectHorizon
Horizon effect.
void setBgColor(const WColor &bgColor)
Determine the color of the viewer's background.
std::string getOpenGLVendor() const
Queries the OpenGL vendor info.
osg::ref_ptr< const WGEViewerEffectVignette > ConstSPtr
Convenience typedef for a boost::shared_ptr< const WGEViewerEffectVignette >.
osg::ref_ptr< osgViewer::View > m_View
The OpenSceneGraph view used in this (Composite)Viewer.
bool isAnimationMode() const
Checks if the viewer is in animation mode.