Commit a58d2c86 authored by Alexander Wiebel's avatar Alexander Wiebel

[CHANGE #216] Instead of setting an initial bound we set the scene to the

maipulators home position now as soon as the first element of the scene has
been added. This improves the rotation center and space bar behavior. It
maybe fixes #216 (please check this)
parent e0b63c4f
......@@ -29,18 +29,23 @@
#include "WGEScene.h"
WGEScene::WGEScene():
WGEGroupNode()
WGEGroupNode(), firstHomePositionRequest( true )
{
WLogger::getLogger()->addLogMessage( "Initializing OpenSceneGraph Root Node", "GE", LL_INFO );
// TODO(all): we definitely need a reference coordinate system on which everybody can rely
setInitialBound( osg::BoundingSphere( osg::Vec3( 80.0, 100.0, 80.0 ), 100.0 ) );
}
WGEScene::~WGEScene()
{
WLogger::getLogger()->addLogMessage( "Shutting down OpenSceneGraph Root Node", "GE", LL_INFO );
}
// cleanup
bool WGEScene::isHomePositionRequested()
{
if( firstHomePositionRequest && getNumChildren() > 0 )
{
firstHomePositionRequest = false;
return true;
}
return false;
}
......@@ -41,6 +41,13 @@ public:
*/
WGEScene();
/**
* Indicates whether we want the widget showing the scene to be
* tranferred to its home position. This is the case if we have the
* <b>first</b> child added to the scene.
*/
bool isHomePositionRequested();
protected:
/**
......@@ -49,31 +56,7 @@ protected:
virtual ~WGEScene();
private:
// /**
// * Node callback to handle updates properly
// */
// class bbCallback : public osg::Node::ComputeBoundingSphereCallback
// {
// public: // NOLINT
// /**
// * operator ()
// *
// * \param node the osg node
// * \param nv the node visitor
// */
// virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
// {
// osg::ref_ptr< WMFiberDisplay > module = static_cast< WMFiberDisplay* > ( node->getUserData() );
//
// if ( module )
// {
// module->update();
// module->toggleTubes();
// module->toggleColoring();
// }
// traverse( node, nv );
// }
// };
bool firstHomePositionRequest; //!< Indicates whether we still have the first request for home position (isHomePositionRequested()).
};
......
......@@ -22,8 +22,9 @@
//
//---------------------------------------------------------------------------
#include "WGEZoomTrackballManipulator.h"
#include "../common/WPreferences.h"
#include "WGEZoomTrackballManipulator.h"
#include "WGraphicsEngine.h"
WGEZoomTrackballManipulator::WGEZoomTrackballManipulator():
TrackballManipulator(),
......@@ -116,7 +117,14 @@ bool WGEZoomTrackballManipulator::handle( const osgGA::GUIEventAdapter& ea, osgG
{
_thrown &= m_allowThrow; // By default we do not want the auto-rotation thingy.
if( ea.getEventType() == osgGA::GUIEventAdapter::SCROLL || ea.getKey() == 45 || ea.getKey() == 43 )
if( WGraphicsEngine::getGraphicsEngine()->getScene()->isHomePositionRequested() )
{
// We set the scene to the manipulator home position if the scene
// requests to do so. See WGEScene for more details.
home( 0 );
return true;
}
else if( ea.getEventType() == osgGA::GUIEventAdapter::SCROLL || ea.getKey() == 45 || ea.getKey() == 43 )
{
return zoom( ea, us );
}
......
#include "WGEColorMaps.glsl"
#include "WGELighting-fragment.glsl"
#include "WGEShadingTools.glsl"
// The ray's starting point in texture space
varying vec3 v_rayStart;
// The ray direction in texture space
varying vec3 v_ray;
// the Surface normal at this point
varying vec3 v_normal;
// The light source in local coordinates
varying vec3 v_lightSource;
void main()
{
vec4 col = gl_Color;
vec4 col;
vec4 ambient = vec4(0.0);
vec4 diffuse = vec4(0.0);
vec4 specular = vec4(0.0);
float light = blinnPhongIlluminationIntensity(
0.1, // material ambient
0.75, // material diffuse
1.3, // material specular
10.0, // shinines
1.0, // light diffuse
0.75, // light ambient
normalize( v_normal ), // normal
normalize( v_ray ), // view direction
normalize( v_lightSource ) // light source position
);
calculateLighting( -normal, gl_FrontMaterial.shininess, ambient, diffuse, specular );
calculateLighting( normal, gl_FrontMaterial.shininess, ambient, diffuse, specular );
col = (ambient * col / 2.0) + (diffuse * col) + (specular * col / 2.0);
col = clamp(col, 0.0, 1.0);
col = light * gl_Color;
col.a = 1.0;
gl_FragColor = col;
}
#include "WGELighting-vertex.glsl"
#include "WGETransformationTools.glsl"
// The ray's starting point in texture space
varying vec3 v_rayStart;
// The ray direction in texture space
varying vec3 v_ray;
// the Surface normal at this point
varying vec3 v_normal;
// The light source in local coordinates
varying vec3 v_lightSource;
void main()
{
prepareLight();
v_normal = gl_Normal;
// transform the ray direction to texture space, which equals object space
// Therefore use two points, as we transform a vector
vec4 camLookAt = vec4( 0.0, 0.0, -1.0, 1.0 );
vec4 camPos = vec4( 0.0, 0.0, 0.0, 1.0 );
v_ray = worldToLocal( camLookAt, camPos ).xyz;
// also get the coordinates of the light
vec4 lpos = gl_LightSource[0].position;
lpos = vec4( 0.0, 0.0, 1000.0, 1.0 );
v_lightSource = worldToLocal( lpos ).xyz;
gl_FrontColor = gl_Color;
gl_Position = ftransform();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment