osg::SimpleSceneManager Class Reference
[Window]

A helper class to simplify managing simple applications. More...

#include <OSGSimpleSceneManager.h>

List of all members.

Member



WindowPtr _win
NodePtr _root
ImageForegroundPtr _foreground
StatisticsForegroundPtr _statforeground
bool _statstate
NodePtr _highlight
NodePtr _highlightNode
GeoPositions3fPtr _highlightPoints
NodePtr _internalRoot
DirectionalLightPtr _headlight
RenderAction_action
RenderAction_ownAction
TransformPtr _cart
PerspectiveCameraPtr _camera
Navigator _navigator
Int16 _lastx
Int16 _lasty
UInt16 _mousebuttons
static SimpleMaterialPtr _highlightMaterial

Public Types

Enums


enum  {
  MouseLeft = 0, MouseMiddle = 1, MouseRight = 2, MouseUp = 3,
  MouseDown = 4, NoButton = -1
}

Public Member Functions

Constructors


 SimpleSceneManager (void)
SimpleSceneManagercreate (void)
Destructor


virtual ~SimpleSceneManager (void)
Get


virtual NodePtr getRoot (void)
virtual WindowPtr getWindow (void)
virtual NodePtr getHighlight (void)
virtual DrawActionBasegetAction (void)
virtual NavigatorgetNavigator (void)
virtual bool getHeadlightState (void)
virtual DirectionalLightPtr getHeadlight (void)
virtual PerspectiveCameraPtr getCamera (void)
Set


virtual void setAction (RenderAction *action)
virtual void setRoot (NodePtr root)
virtual void setWindow (WindowPtr win)
virtual void setHighlight (NodePtr obj)
virtual void setHeadlight (bool on)
virtual void turnHeadlightOn (void)
virtual void turnHeadlightOff (void)
virtual void setCamera (PerspectiveCameraPtr camera)
virtual void showAll (void)
virtual void useOpenSGLogo (void)
void setNavigationMode (Navigator::Mode new_mode)
bool setClickCenter (bool mode)
virtual void setStatistics (bool on)
Interaction handling


virtual void resize (UInt16 width, UInt16 height)
virtual void mouseMove (Int16 x, Int16 y)
virtual void mouseButtonPress (UInt16 button, Int16 x, Int16 y)
virtual void mouseButtonRelease (UInt16 button, Int16 x, Int16 y)
virtual void key (UChar8 key, Int16 x, Int16 y)
Line calcViewRay (Int16 x, Int16 y)
Actions


virtual void redraw (void)
virtual void idle (void)
Comparison


bool operator< (const SimpleSceneManager &other) const

Protected Member Functions

Updates


void initialize (void)
virtual void highlightChanged (void)
virtual void updateHighlight (void)

Private Member Functions

 SimpleSceneManager (const SimpleSceneManager &source)
void operator= (const SimpleSceneManager &source)


Detailed Description

SimpleSceneManager manages the OpenSG components that are needed to do simple applications that just want to display some geometry. It takes the window to render into and the root node of the graph to display and takes care of creating the necessary additional OpenSG objects, like a viewport for the window,

Definition at line 68 of file OSGSimpleSceneManager.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
MouseLeft  The constant for the left mouse button.
MouseMiddle  The constant for the middle mouse button.
MouseRight  The constant for the right mouse button.
MouseUp  The constant for the mouse wheel up (away from the hand) motion.
MouseDown  The constant for the mouse wheel down (towards the hand) motion.
NoButton 

Definition at line 76 of file OSGSimpleSceneManager.h.

00076          {  MouseLeft   =  0,
00077             MouseMiddle =  1, 
00078             MouseRight  =  2,
00079             MouseUp     =  3,
00080             MouseDown   =  4,
00081             NoButton    =  -1
00082          };


Constructor & Destructor Documentation

SimpleSceneManager::SimpleSceneManager ( void   ) 

Constructor

Definition at line 189 of file OSGSimpleSceneManager.cpp.

00189                                            :
00190     _win            (NullFC),
00191     _root           (NullFC),
00192     _foreground     (NullFC),
00193     _statforeground (NullFC),
00194     _statstate      (false),
00195 
00196     _highlight      (NullFC),
00197     _highlightNode  (NullFC),
00198     _highlightPoints(NullFC),
00199 
00200     _internalRoot   (NullFC),
00201     _headlight      (NullFC),
00202     _action         (NULL  ),
00203     _ownAction      (NULL  ),
00204     _cart           (NullFC),
00205     _camera         (NullFC),
00206     _navigator      (      ),
00207 
00208     _lastx          (TypeTraits<Int16>::getMax()),
00209     _lasty          (TypeTraits<Int16>::getMax()),
00210     _mousebuttons   (0                             )
00211 {
00212 }

SimpleSceneManager::~SimpleSceneManager ( void   )  [virtual]

Destructor

Definition at line 225 of file OSGSimpleSceneManager.cpp.

References _camera, _internalRoot, _ownAction, osg::NullFC, setRoot(), and osg::subRefCP().

00226 {
00227     delete _ownAction;
00228 
00229     setRoot(NullFC); // sub root
00230     if(_internalRoot != NullFC)
00231         subRefCP(_internalRoot);
00232     if(_camera != NullFC)
00233         subRefCP(_camera);
00234 }

osg::SimpleSceneManager::SimpleSceneManager ( const SimpleSceneManager source  )  [private]


Member Function Documentation

SimpleSceneManager * SimpleSceneManager::create ( void   ) 

pseudo constructor. Standard interface for OpenSG object creation.

Definition at line 217 of file OSGSimpleSceneManager.cpp.

00218 {
00219     return new SimpleSceneManager;
00220 }

NodePtr SimpleSceneManager::getRoot ( void   )  [virtual]

get the root of the displayed tree

Definition at line 246 of file OSGSimpleSceneManager.cpp.

References _root.

00247 {
00248     return _root;
00249 }

WindowPtr SimpleSceneManager::getWindow ( void   )  [virtual]

get the window to be used for display

Definition at line 239 of file OSGSimpleSceneManager.cpp.

References _win.

Referenced by osg::OSGQGLManagedWidget::initializeGL(), and osg::OSGQGLManagedWidget::paintGL().

00240 {
00241     return _win;
00242 }

NodePtr SimpleSceneManager::getHighlight ( void   )  [virtual]

get the highlight object

Definition at line 290 of file OSGSimpleSceneManager.cpp.

References _highlight.

Referenced by highlightChanged().

00291 {
00292     return _highlight;
00293 }

DrawActionBase * SimpleSceneManager::getAction ( void   )  [virtual]

get the action used to render the scene

Definition at line 297 of file OSGSimpleSceneManager.cpp.

References _action.

00298 {
00299     return _action;
00300 }

Navigator * SimpleSceneManager::getNavigator ( void   )  [virtual]

get the navigator

Definition at line 253 of file OSGSimpleSceneManager.cpp.

References _navigator.

00254 {
00255     return &_navigator;
00256 }

bool SimpleSceneManager::getHeadlightState ( void   )  [virtual]

get the headlight state

Definition at line 260 of file OSGSimpleSceneManager.cpp.

References _headlight.

00261 {
00262     return _headlight->getOn();
00263 }

DirectionalLightPtr SimpleSceneManager::getHeadlight ( void   )  [virtual]

get the headlight

Definition at line 267 of file OSGSimpleSceneManager.cpp.

References _headlight.

00268 {
00269     return _headlight;
00270 }

PerspectiveCameraPtr SimpleSceneManager::getCamera ( void   )  [virtual]

get the camera

Definition at line 274 of file OSGSimpleSceneManager.cpp.

References _camera.

00275 {
00276     return _camera;
00277 }

void SimpleSceneManager::setAction ( RenderAction action  )  [virtual]

set the action used to render the scene. Use NULL to set to internally created action.

Definition at line 305 of file OSGSimpleSceneManager.cpp.

References _action, _ownAction, _statstate, and setStatistics().

00306 {
00307     bool statstate = _statstate;
00308 
00309     if(_action != NULL && statstate)
00310         setStatistics(false);
00311 
00312     if(action == NULL)
00313     {
00314         _action = _ownAction;
00315     }
00316     else
00317     {
00318         _action = action;
00319     }
00320     
00321     if(statstate)
00322         setStatistics(true);
00323 }

void SimpleSceneManager::setRoot ( NodePtr  root  )  [virtual]

set the root of the displayed tree

Definition at line 327 of file OSGSimpleSceneManager.cpp.

References _internalRoot, _root, osg::beginEditCP(), osg::Node::ChildrenFieldMask, osg::endEditCP(), initialize(), and osg::NullFC.

Referenced by ~SimpleSceneManager().

00328 {
00329     if(_internalRoot == NullFC)
00330     {
00331         initialize();
00332     }
00333 
00334     if(_root != root)
00335     {
00336         if(_root != NullFC)
00337         {
00338             beginEditCP(_internalRoot, Node::ChildrenFieldMask);
00339             _internalRoot->subChild(_root);
00340             endEditCP(_internalRoot, Node::ChildrenFieldMask);
00341         }
00342 
00343         _root = root;
00344         if(_root != NullFC)
00345         {
00346             beginEditCP(_internalRoot, Node::ChildrenFieldMask);
00347             _internalRoot->addChild(_root);
00348             endEditCP(_internalRoot, Node::ChildrenFieldMask);
00349         }
00350     }
00351 }

void SimpleSceneManager::setWindow ( WindowPtr  win  )  [virtual]

set the window to be used for display

Definition at line 281 of file OSGSimpleSceneManager.cpp.

References _navigator, _win, osg::NullFC, and osg::Navigator::setViewport().

Referenced by osg::OSGQGLManagedWidget::OSGQGLManagedWidget().

00282 {
00283     _win = win;
00284     if(_win->getMFPort()->size() > 0 && _win->getPort(0) != NullFC)
00285         _navigator.setViewport(_win->getPort(0));
00286 }

void SimpleSceneManager::setHighlight ( NodePtr  highlight  )  [virtual]

set the highlight object

Definition at line 412 of file OSGSimpleSceneManager.cpp.

References _highlight, and highlightChanged().

00413 {
00414     _highlight = highlight;
00415     highlightChanged();
00416 }

void SimpleSceneManager::setHeadlight ( bool  on  )  [virtual]

set the headlight setting

Definition at line 355 of file OSGSimpleSceneManager.cpp.

References _headlight, _internalRoot, osg::beginEditCP(), osg::endEditCP(), initialize(), osg::NullFC, and osg::LightBase::OnFieldMask.

Referenced by turnHeadlightOff(), and turnHeadlightOn().

00356 {
00357     if(_internalRoot == NullFC)
00358     {
00359         initialize();
00360     }
00361 
00362     beginEditCP(_headlight, LightBase::OnFieldMask);
00363     _headlight->setOn(on);
00364     endEditCP(_headlight, LightBase::OnFieldMask);
00365 }

void SimpleSceneManager::turnHeadlightOn ( void   )  [virtual]

turn headlight on.

Definition at line 369 of file OSGSimpleSceneManager.cpp.

References setHeadlight().

00370 {
00371     setHeadlight(true);
00372 }

void SimpleSceneManager::turnHeadlightOff ( void   )  [virtual]

turn headlight off.

Definition at line 376 of file OSGSimpleSceneManager.cpp.

References setHeadlight().

00377 {
00378     setHeadlight(false);
00379 }

void SimpleSceneManager::setCamera ( PerspectiveCameraPtr  camera  )  [virtual]

set the action used to render the scene. Use NULL to set to internally created action.

Definition at line 381 of file OSGSimpleSceneManager.cpp.

References _camera, _win, osg::addRefCP(), osg::beginEditCP(), osg::endEditCP(), osg::NullFC, and osg::subRefCP().

00382 {
00383     if(camera == NullFC)
00384         return;
00385 
00386     beginEditCP(camera);
00387         camera->setBeacon(_camera->getBeacon());
00388         camera->setFov   (_camera->getFov());
00389         camera->setNear  (_camera->getNear());
00390         camera->setFar   (_camera->getFar());
00391     endEditCP(camera);
00392 
00393     for(UInt32 i=0;i<_win->getPort().size();++i)
00394     {
00395         ViewportPtr vp = _win->getPort()[i];
00396         if(vp != NullFC)
00397         {
00398             beginEditCP(vp);
00399                 vp->setCamera(camera);
00400             endEditCP(vp);
00401         }
00402     }
00403 
00404     // destroy old camera.
00405     subRefCP(_camera);
00406     _camera = camera;
00407     addRefCP(_camera);
00408 }

void SimpleSceneManager::showAll ( void   )  [virtual]

show the whole scene: move out far enough to see everything

Definition at line 587 of file OSGSimpleSceneManager.cpp.

References _camera, _navigator, _root, osg::beginEditCP(), osg::endEditCP(), osg::Eps, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::NullFC, osg::osgMax(), osg::osgtan(), osg::Navigator::set(), and osg::Navigator::setMotionFactor().

Referenced by redraw().

00588 {
00589     if(_root == NullFC)
00590         return;
00591 
00592     _root->updateVolume();
00593 
00594     Vec3f min,max;
00595     _root->getVolume().getBounds( min, max );
00596     Vec3f d = max - min;
00597 
00598     if(d.length() < Eps) // Nothing loaded? Use a unity box
00599     {
00600         min.setValues(-1.f,-1.f,-1.f);
00601         max.setValues( 1.f, 1.f, 1.f);
00602         d = max - min;
00603     }
00604 
00605     Real32 dist = osgMax(d[0],d[1]) / (2 * osgtan(_camera->getFov() / 2.f));
00606 
00607     Vec3f up(0,1,0);
00608     Pnt3f at((min[0] + max[0]) * .5f,(min[1] + max[1]) * .5f,(min[2] + max[2]) * .5f);
00609     Pnt3f from=at;
00610     from[2]+=(dist+fabs(max[2]-min[2])*0.5f); 
00611 
00612     _navigator.set(from,at,up);
00613 
00614     // adjust the translation factors so that motions are sort of scaled
00615     _navigator.setMotionFactor((d[0] + d[1] + d[2]) / 100.f);
00616 
00617     // set the camera to go from 1% of the object to twice its size
00618     Real32 diag = osgMax(osgMax(d[0], d[1]), d[2]);
00619     beginEditCP(_camera);
00620     _camera->setNear (diag / 100.f);
00621     _camera->setFar  (10 * diag);
00622     endEditCP(_camera);
00623 }

void SimpleSceneManager::useOpenSGLogo ( void   )  [virtual]

add the "Powered by OpenSG" logo to the lower left corner

Definition at line 627 of file OSGSimpleSceneManager.cpp.

References _foreground, osg::beginEditCP(), osg::ImageBase::create(), osg::endEditCP(), osg::LogoData, and osg::ImageFileType::restore().

00628 {
00629     ImagePtr lo = Image::create();
00630     ImageFileType::restore( lo, (UChar8*)LogoData, -1 );
00631 
00632     beginEditCP(_foreground);
00633     _foreground->addImage( lo, Pnt2f( 0,0 ) );
00634     endEditCP  (_foreground);
00635 }

void SimpleSceneManager::setNavigationMode ( Navigator::Mode  new_mode  ) 

Sets the navigation mode

Definition at line 639 of file OSGSimpleSceneManager.cpp.

References _navigator, osg::Navigator::getMatrix(), osg::Navigator::set(), and osg::Navigator::setMode().

00640 {
00641     Matrix m=_navigator.getMatrix();
00642     _navigator.setMode(new_mode);
00643     _navigator.set(m);
00644 }

bool osg::SimpleSceneManager::setClickCenter ( bool  mode  )  [inline]

set the click center mode of the navigator

Definition at line 46 of file OSGSimpleSceneManager.inl.

References _navigator, and osg::Navigator::setClickCenter().

00047 {
00048     return _navigator.setClickCenter(mode);
00049 }

void SimpleSceneManager::setStatistics ( bool  on  )  [virtual]

set the statistics setting. Only works after the window has been created.

Definition at line 420 of file OSGSimpleSceneManager.cpp.

References _action, _statforeground, _statstate, _win, osg::NullFC, and osg::DrawActionBase::setStatistics().

Referenced by setAction().

00421 {
00422     if(_statforeground != NullFC && on != _statstate)
00423     {
00424         ViewportPtr vp = _win->getPort()[0];
00425 
00426         if(on)
00427         {
00428             vp->getForegrounds().push_back(_statforeground);
00429 
00430             _action->setStatistics(&_statforeground->getCollector());
00431         }
00432         else
00433         {
00434             MFForegroundPtr::iterator it;
00435 
00436             it = vp->getForegrounds().find(_statforeground);
00437             vp->getForegrounds().erase(it);
00438 
00439             _action->setStatistics(NULL);
00440         }
00441 
00442         _statstate = on;
00443     }
00444 }

void SimpleSceneManager::resize ( UInt16  width,
UInt16  height 
) [virtual]

resize

Definition at line 815 of file OSGSimpleSceneManager.cpp.

References _win.

Referenced by osg::OSGQGLManagedWidget::resizeGL().

00816 {
00817     _win->resize(width, height);
00818 }

void SimpleSceneManager::mouseMove ( Int16  x,
Int16  y 
) [virtual]

motion

Definition at line 822 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, and osg::Navigator::moveTo().

Referenced by osg::OSGQGLManagedWidget::mouseMoveEvent().

00823 {
00824     if ( _mousebuttons) _navigator.moveTo(x,y);
00825     _lastx = x;
00826     _lasty = y;
00827 
00828 }

void SimpleSceneManager::mouseButtonPress ( UInt16  button,
Int16  x,
Int16  y 
) [virtual]

call when a mouse button is pressed. button is the number of the pressed button, starting at 0, ordered from left to right. A wheel should be mapped to buttons 3 and 4. The position is in pixel, starting at the upper left corner.

Definition at line 836 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, osg::Navigator::buttonPress(), osg::Navigator::DOWN_MOUSE, osg::Navigator::LEFT_MOUSE, osg::Navigator::MIDDLE_MOUSE, MouseDown, MouseLeft, MouseMiddle, MouseRight, MouseUp, osg::Navigator::RIGHT_MOUSE, and osg::Navigator::UP_MOUSE.

Referenced by osg::OSGQGLManagedWidget::mousePressEvent(), and osg::OSGQGLManagedWidget::wheelEvent().

00837 {
00838     switch (button)
00839     {
00840     case MouseLeft:    _navigator.buttonPress(Navigator::LEFT_MOUSE,x,y);
00841       break;
00842     case MouseMiddle:  _navigator.buttonPress(Navigator::MIDDLE_MOUSE,x,y);
00843       break;
00844     case MouseRight:   _navigator.buttonPress(Navigator::RIGHT_MOUSE,x,y);
00845       break;
00846     case MouseUp:      _navigator.buttonPress(Navigator::UP_MOUSE,x,y);
00847       break;
00848     case MouseDown:    _navigator.buttonPress(Navigator::DOWN_MOUSE,x,y);
00849       break;
00850     }
00851     
00852     _mousebuttons |= 1 << button;
00853     _lastx = x;
00854     _lasty = y;
00855 }

void SimpleSceneManager::mouseButtonRelease ( UInt16  button,
Int16  x,
Int16  y 
) [virtual]

call when a mouse button is released. button is the number of the pressed button, starting at 0, ordered from left to right. A wheel should be mapped to buttons 3 and 4. The position is in pixel, starting at the upper left corner.

Definition at line 863 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, osg::Navigator::buttonRelease(), osg::Navigator::DOWN_MOUSE, osg::Navigator::LEFT_MOUSE, osg::Navigator::MIDDLE_MOUSE, MouseDown, MouseLeft, MouseMiddle, MouseRight, MouseUp, osg::Navigator::RIGHT_MOUSE, and osg::Navigator::UP_MOUSE.

Referenced by osg::OSGQGLManagedWidget::mouseReleaseEvent().

00864 {
00865     switch (button)
00866     {
00867     case MouseLeft:     _navigator.buttonRelease(Navigator::LEFT_MOUSE,x,y);
00868                         break;
00869     case MouseMiddle:   _navigator.buttonRelease(Navigator::MIDDLE_MOUSE,x,y);
00870                         break;
00871     case MouseRight:    _navigator.buttonRelease(Navigator::RIGHT_MOUSE,x,y);
00872                         break;
00873     case MouseUp:       _navigator.buttonRelease(Navigator::UP_MOUSE,x,y);
00874                         break;
00875     case MouseDown:     _navigator.buttonRelease(Navigator::DOWN_MOUSE,x,y);
00876                         break;
00877     }
00878     _mousebuttons &= ~(1 << button);
00879     _lastx = x;
00880     _lasty = y;
00881 }

void SimpleSceneManager::key ( UChar8  key,
Int16  x,
Int16  y 
) [virtual]

resize

Definition at line 883 of file OSGSimpleSceneManager.cpp.

References _navigator, osg::Navigator::BACKWARDS, osg::Navigator::FORWARDS, osg::Navigator::keyPress(), osg::Navigator::LEFT, osg::Navigator::LEFTROT, osg::Navigator::RIGHT, and osg::Navigator::RIGHTROT.

00884 {
00885     switch ( key )
00886     {
00887         case 'j': _navigator.keyPress(Navigator::LEFT,x,y); break;
00888         case 'g': _navigator.keyPress(Navigator::RIGHT,x,y); break;
00889         case 'u': _navigator.keyPress(Navigator::LEFTROT,x,y); break;
00890         case 't': _navigator.keyPress(Navigator::RIGHTROT,x,y); break;
00891         case 'y': _navigator.keyPress(Navigator::FORWARDS,x,y); break;
00892         case 'h': _navigator.keyPress(Navigator::BACKWARDS,x,y); break;
00893     }
00894 }

Line SimpleSceneManager::calcViewRay ( Int16  x,
Int16  y 
)

Calculate a ray that starts at the eye and goes through the position on the screen given by x,y.

Definition at line 900 of file OSGSimpleSceneManager.cpp.

References _camera, and _win.

00901 {
00902     Line l;
00903 
00904     _camera->calcViewRay( l, x, y, *_win->getPort()[0]);
00905 
00906     return l;
00907 }

void SimpleSceneManager::redraw ( void   )  [virtual]

Draw the next frame, update if needed.

Definition at line 656 of file OSGSimpleSceneManager.cpp.

References _action, _internalRoot, _navigator, _win, initialize(), osg::NullFC, showAll(), osg::Navigator::updateCameraTransformation(), and updateHighlight().

Referenced by osg::OSGQGLManagedWidget::paintGL().

00657 {
00658     if (_internalRoot == NullFC)
00659     {
00660         initialize();
00661         showAll();
00662     }
00663 
00664 //    _cart->getSFMatrix()->setValue(_navigator.getMatrix());
00665     _navigator.updateCameraTransformation();
00666 
00667     updateHighlight();
00668 
00669     _win->render(_action);
00670 }

void SimpleSceneManager::idle ( void   )  [virtual]

Draw the next frame, update if needed.

Definition at line 649 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, and osg::Navigator::idle().

00650 {
00651   _navigator.idle(_mousebuttons,_lastx, _lasty);
00652 }

bool SimpleSceneManager::operator< ( const SimpleSceneManager other  )  const

less

Definition at line 922 of file OSGSimpleSceneManager.cpp.

00923 {
00924     return this < &other;
00925 }

void SimpleSceneManager::initialize ( void   )  [protected]

create the parts that the app needs: viewport, camera, base graph etc.

Definition at line 451 of file OSGSimpleSceneManager.cpp.

References _action, _camera, _cart, _foreground, _headlight, _internalRoot, _navigator, _ownAction, _statforeground, _win, osg::addRefCP(), osg::beginEditCP(), osg::ViewportBase::create(), osg::SimpleStatisticsForegroundBase::create(), osg::ImageForegroundBase::create(), osg::SolidBackgroundBase::create(), osg::PerspectiveCameraBase::create(), osg::DirectionalLightBase::create(), osg::TransformBase::create(), osg::Node::create(), osg::RenderAction::create(), osg::deg2rad(), osg::endEditCP(), FWARNING, osg::StatCollector::getElem(), osg::NullFC, osg::Navigator::setCameraTransformation(), osg::Navigator::setMode(), osg::Navigator::setViewport(), osg::DrawActionBase::statCulledNodes, osg::DrawActionBase::statCullTestedNodes, osg::DirectionalLight::statNDirectionalLights, osg::RenderAction::statNGeometries, osg::Drawable::statNLines, osg::RenderAction::statNMaterials, osg::RenderAction::statNMatrices, osg::RenderAction::statNOcclusionCulled, osg::RenderAction::statNOcclusionMode, osg::RenderAction::statNOcclusionTests, osg::PointLight::statNPointLights, osg::Drawable::statNPoints, osg::SpotLight::statNSpotLights, osg::RenderAction::statNTexBytes, osg::RenderAction::statNTextures, osg::RenderAction::statNTransGeometries, osg::Drawable::statNTriangles, osg::Drawable::statNVertices, osg::DrawActionBase::statTravTime, and osg::Navigator::TRACKBALL.

Referenced by redraw(), setHeadlight(), and setRoot().

00452 {
00453     // Check necessary stuff
00454     if(_win == NullFC)
00455     {
00456         FWARNING(("SimpleSceneManager::initialize: window not set, "
00457                   "ignoring!\n"));
00458         return;
00459     }
00460     
00461     // the rendering action
00462     _ownAction = RenderAction::create();
00463     _action = _ownAction;
00464 
00465     // the camera and light beacon
00466     NodePtr cartN = Node::create();
00467     _cart = Transform::create();
00468 
00469     beginEditCP(cartN);
00470     cartN->setCore(_cart);
00471     endEditCP(cartN);
00472 
00473     // the headlight
00474     _internalRoot = Node::create();
00475     _headlight    = DirectionalLight::create();
00476 
00477     addRefCP(_internalRoot);
00478     beginEditCP(_internalRoot);
00479     _internalRoot->setCore(_headlight);
00480     _internalRoot->addChild(cartN);
00481     endEditCP(_internalRoot);
00482 
00483     beginEditCP(_headlight);
00484     _headlight->setAmbient  (.3, .3, .3, 1);
00485     _headlight->setDiffuse  ( 1,  1,  1, 1);
00486     _headlight->setSpecular ( 1,  1,  1, 1);
00487     _headlight->setDirection( 0,  0,  1);
00488     _headlight->setBeacon   (cartN);
00489     endEditCP(_headlight);
00490 
00491     // the camera
00492     _camera = PerspectiveCamera::create();
00493     addRefCP(_camera);
00494     beginEditCP(_camera);
00495     _camera->setBeacon(cartN);
00496     _camera->setFov   (deg2rad(60.f));
00497     _camera->setNear  (0.1f);
00498     _camera->setFar   (10000.f);
00499     endEditCP(_camera);
00500 
00501     // need a viewport?
00502     if(_win->getPort().size() == 0)
00503     {
00504         SolidBackgroundPtr bg = SolidBackground::create();
00505         beginEditCP(bg);
00506         bg->setColor(Color3f(0, 0, 0));
00507         endEditCP(bg);
00508 
00509         _foreground = ImageForeground::create();
00510 
00511         SimpleStatisticsForegroundPtr sf = SimpleStatisticsForeground::create();
00512 
00513         beginEditCP(sf);
00514         sf->setSize(25);
00515         sf->setColor(Color4f(0,1,0,0.7));
00516         sf->addElement(RenderAction::statTravTime,
00517                            "FPS:                  %r.3f");
00518         sf->addElement(DrawActionBase::statCullTestedNodes,
00519                            "Nodes culltested      %d");
00520         sf->addElement(DrawActionBase::statCulledNodes,
00521                            "Nodes culled          %d");
00522         sf->addElement(RenderAction::statNOcclusionMode,
00523                            "Occlusion culling     %s");
00524         sf->addElement(RenderAction::statNOcclusionTests,
00525                            "Occlusion tests       %d");
00526         sf->addElement(RenderAction::statNOcclusionCulled,
00527                            "Occlusion culled      %d");
00528         sf->addElement(RenderAction::statNGeometries,
00529                            "Nodes drawn           %d");
00530         sf->addElement(RenderAction::statNTransGeometries,
00531                            "Transp. Nodes drawn   %d");
00532         sf->addElement(RenderAction::statNMaterials,
00533                            "Material changes      %d");
00534         sf->addElement(RenderAction::statNMatrices,
00535                            "Matrix changes        %d");
00536 
00537 #if 0 // not ready for primetime yet
00538         sf->addElement(PointLight::statNPointLights,
00539                            "%d active point lights");
00540         sf->addElement(DirectionalLight::statNDirectionalLights,
00541                            "%d active directional lights");
00542         sf->addElement(SpotLight::statNSpotLights,
00543                            "%d active spot lights");
00544 #endif
00545         sf->addElement(Drawable::statNTriangles,
00546                            "Triangles drawn       %d");
00547         sf->addElement(Drawable::statNLines,
00548                            "Lines drawn           %d");
00549         sf->addElement(Drawable::statNPoints,
00550                            "Points drawn          %d");
00551         sf->addElement(Drawable::statNVertices,
00552                            "Vertices transformed  %d");
00553         sf->addElement(RenderAction::statNTextures,
00554                            "Textures used         %d");
00555         sf->addElement(RenderAction::statNTexBytes,
00556                            "Textures size (bytes) %d");
00557         endEditCP(sf);
00558 
00559         StatCollector *collector = &sf->getCollector();
00560 
00561         // add optional elements
00562         collector->getElem(Drawable::statNTriangles);
00563 
00564         _statforeground = sf;
00565 
00566         ViewportPtr vp = Viewport::create();
00567         beginEditCP(vp);
00568         vp->setCamera                  (_camera);
00569         vp->setRoot                    (_internalRoot);
00570         vp->setSize                    (0,0, 1,1);
00571         vp->setBackground              (bg);
00572         vp->getForegrounds().push_back(_foreground);
00573         endEditCP(vp);
00574 
00575         beginEditCP(_win);
00576         _win->addPort(vp);
00577         endEditCP(_win);
00578     }
00579 
00580     _navigator.setMode(Navigator::TRACKBALL);
00581     _navigator.setViewport(_win->getPort(0));
00582     _navigator.setCameraTransformation(cartN);
00583 }

void SimpleSceneManager::highlightChanged ( void   )  [protected, virtual]

Adjust the highlight to a changed object. Also initializes the highlight statics if called the first time.

Definition at line 675 of file OSGSimpleSceneManager.cpp.

References _highlightMaterial, _highlightNode, _highlightPoints, _internalRoot, osg::addRefCP(), osg::beginEditCP(), osg::Node::create(), osg::GeometryBase::create(), osg::GeoProperty< GeoPropertyDesc >::create(), osg::SimpleMaterialBase::create(), osg::endEditCP(), getHighlight(), osg::NullFC, and updateHighlight().

Referenced by setHighlight().

00676 {
00677 
00678   // FDEBUG (("SimpleSceneManager::updateHightlight() called\n"));
00679 
00680     // init as needed
00681     if(_highlightMaterial == NullFC)
00682     {
00683         _highlightMaterial = SimpleMaterial::create();
00684 
00685         beginEditCP(_highlightMaterial);
00686         _highlightMaterial->setDiffuse (Color3f(0,1,0));
00687         _highlightMaterial->setLit     (false);
00688         endEditCP(_highlightMaterial);
00689     }
00690     if(_highlightNode == NullFC)
00691     {
00692         GeoPTypesPtr type = GeoPTypesUI8::create();
00693         beginEditCP(type);
00694         type->push_back(GL_LINE_STRIP);
00695         type->push_back(GL_LINES);
00696         endEditCP(type);
00697 
00698         GeoPLengthsPtr lens = GeoPLengthsUI32::create();
00699         beginEditCP(lens);
00700         lens->push_back(10);
00701         lens->push_back(6);
00702         endEditCP(lens);
00703 
00704         GeoIndicesUI32Ptr index = GeoIndicesUI32::create();
00705         beginEditCP(index);
00706         index->getFieldPtr()->push_back(0);
00707         index->getFieldPtr()->push_back(1);
00708         index->getFieldPtr()->push_back(3);
00709         index->getFieldPtr()->push_back(2);
00710         index->getFieldPtr()->push_back(0);
00711         index->getFieldPtr()->push_back(4);
00712         index->getFieldPtr()->push_back(5);
00713         index->getFieldPtr()->push_back(7);
00714         index->getFieldPtr()->push_back(6);
00715         index->getFieldPtr()->push_back(4);
00716 
00717         index->getFieldPtr()->push_back(1);
00718         index->getFieldPtr()->push_back(5);
00719         index->getFieldPtr()->push_back(2);
00720         index->getFieldPtr()->push_back(6);
00721         index->getFieldPtr()->push_back(3);
00722         index->getFieldPtr()->push_back(7);
00723         endEditCP(index);
00724 
00725         _highlightPoints = GeoPositions3f::create();
00726         beginEditCP(_highlightPoints);
00727         _highlightPoints->push_back(Pnt3f(-1, -1, -1));
00728         _highlightPoints->push_back(Pnt3f( 1, -1, -1));
00729         _highlightPoints->push_back(Pnt3f(-1,  1, -1));
00730         _highlightPoints->push_back(Pnt3f( 1,  1, -1));
00731         _highlightPoints->push_back(Pnt3f(-1, -1,  1));
00732         _highlightPoints->push_back(Pnt3f( 1, -1,  1));
00733         _highlightPoints->push_back(Pnt3f(-1,  1,  1));
00734         _highlightPoints->push_back(Pnt3f( 1,  1,  1));
00735         endEditCP(_highlightPoints);
00736 
00737         GeometryPtr geo=Geometry::create();
00738         beginEditCP(geo);
00739         geo->setTypes     (type);
00740         geo->setLengths   (lens);
00741         geo->setIndices   (index);
00742         geo->setPositions (_highlightPoints);
00743         geo->setMaterial  (_highlightMaterial);
00744         endEditCP(geo);
00745         addRefCP(geo);
00746 
00747         _highlightNode = Node::create();
00748         beginEditCP(_highlightNode);
00749         _highlightNode->setCore(geo);
00750         endEditCP(_highlightNode);
00751         addRefCP(_highlightNode);
00752     }
00753 
00754     // attach the hightlight node to the root if the highlight is active
00755     if(getHighlight() != NullFC)
00756     {
00757         if(_highlightNode->getParent() == NullFC)
00758         {
00759             beginEditCP(_internalRoot);
00760             _internalRoot->addChild(_highlightNode);
00761             endEditCP(_internalRoot);
00762         }
00763     }
00764     else
00765     {
00766         if(_highlightNode->getParent() != NullFC)
00767         {
00768             beginEditCP(_internalRoot);
00769             _internalRoot->subChild(_highlightNode);
00770             endEditCP(_internalRoot);
00771         }
00772 
00773     }
00774     // update the highlight geometry
00775     updateHighlight();
00776 }

void SimpleSceneManager::updateHighlight ( void   )  [protected, virtual]

Update the highlight for a moved object. Does not handle changing the object, this is done by highlightChanged().

Definition at line 781 of file OSGSimpleSceneManager.cpp.

References _highlight, _highlightNode, _highlightPoints, osg::beginEditCP(), osg::endEditCP(), osg::DynamicVolume::getBounds(), osg::NodePtr::getCore(), osg::NullFC, and osg::GeometryBase::PositionsFieldMask.

Referenced by highlightChanged(), and redraw().

00782 {
00783     if(_highlight==NullFC)
00784         return;
00785 
00786     // FDEBUG (("SimpleSceneManager::updateHightlight() called\n"));
00787 
00788     // calc the world bbox of the highlight object
00789     DynamicVolume vol;
00790     _highlight->getWorldVolume(vol);
00791 
00792     Pnt3f min,max;
00793     vol.getBounds(min, max);
00794 
00795     beginEditCP(_highlightPoints);
00796     _highlightPoints->setValue(Pnt3f(min[0], min[1], min[2]), 0);
00797     _highlightPoints->setValue(Pnt3f(max[0], min[1], min[2]), 1);
00798     _highlightPoints->setValue(Pnt3f(min[0], max[1], min[2]), 2);
00799     _highlightPoints->setValue(Pnt3f(max[0], max[1], min[2]), 3);
00800     _highlightPoints->setValue(Pnt3f(min[0], min[1], max[2]), 4);
00801     _highlightPoints->setValue(Pnt3f(max[0], min[1], max[2]), 5);
00802     _highlightPoints->setValue(Pnt3f(min[0], max[1], max[2]), 6);
00803     _highlightPoints->setValue(Pnt3f(max[0], max[1], max[2]), 7);
00804     endEditCP(_highlightPoints);
00805 
00806     beginEditCP(_highlightNode->getCore(), Geometry::PositionsFieldMask);
00807     endEditCP  (_highlightNode->getCore(), Geometry::PositionsFieldMask);
00808 }

void osg::SimpleSceneManager::operator= ( const SimpleSceneManager source  )  [private]


Member Data Documentation

The managed window. Has to be set by the user.

Definition at line 184 of file OSGSimpleSceneManager.h.

Referenced by calcViewRay(), getWindow(), initialize(), redraw(), resize(), setCamera(), setStatistics(), and setWindow().

The root node to be rendered. Has to be set by the user.

Definition at line 185 of file OSGSimpleSceneManager.h.

Referenced by getRoot(), setRoot(), and showAll().

ImageForeground used by the logo.

Definition at line 187 of file OSGSimpleSceneManager.h.

Referenced by initialize(), and useOpenSGLogo().

The managed window. Has to be set by the user.

Definition at line 188 of file OSGSimpleSceneManager.h.

Referenced by initialize(), and setStatistics().

Bool to indicate if statistics should be displayed or not.

Definition at line 189 of file OSGSimpleSceneManager.h.

Referenced by setAction(), and setStatistics().

The Node to be highlighted (highlit? ;). Has to be set by the user. May be NullFC (which is the default), in which case nothing is highlighted.

Definition at line 191 of file OSGSimpleSceneManager.h.

Referenced by getHighlight(), setHighlight(), and updateHighlight().

The node used to hold the actual highlight geometry.

Definition at line 192 of file OSGSimpleSceneManager.h.

Referenced by highlightChanged(), and updateHighlight().

The highlight points geo property. These are adjusted to include the _highlight object for every rendered frame.

Definition at line 193 of file OSGSimpleSceneManager.h.

Referenced by highlightChanged(), and updateHighlight().

The real root used internally. It's the root for the light and has the camera beacon and the given root as children.

Definition at line 195 of file OSGSimpleSceneManager.h.

Referenced by highlightChanged(), initialize(), redraw(), setHeadlight(), setRoot(), and ~SimpleSceneManager().

The core for the light source.

Definition at line 196 of file OSGSimpleSceneManager.h.

Referenced by getHeadlight(), getHeadlightState(), initialize(), and setHeadlight().

The action used to render the scene.

Definition at line 197 of file OSGSimpleSceneManager.h.

Referenced by getAction(), initialize(), redraw(), setAction(), and setStatistics().

The action created by this SSM.

Definition at line 198 of file OSGSimpleSceneManager.h.

Referenced by initialize(), setAction(), and ~SimpleSceneManager().

The core of the camera beacon. Manipulated by the navigator.

Definition at line 199 of file OSGSimpleSceneManager.h.

Referenced by initialize().

The camera used to view the scene.

Definition at line 200 of file OSGSimpleSceneManager.h.

Referenced by calcViewRay(), getCamera(), initialize(), setCamera(), showAll(), and ~SimpleSceneManager().

The x position of the last mouse event, needed by the navigator.

Definition at line 204 of file OSGSimpleSceneManager.h.

Referenced by idle(), mouseButtonPress(), mouseButtonRelease(), and mouseMove().

The y position of the last mouse event, needed by the navigator.

Definition at line 205 of file OSGSimpleSceneManager.h.

Referenced by idle(), mouseButtonPress(), mouseButtonRelease(), and mouseMove().

Storage for the actively pressed mouse buttons. Needed to do the right thing for mouse motions, as mouseMove() doesn't get them.

Definition at line 206 of file OSGSimpleSceneManager.h.

Referenced by idle(), mouseButtonPress(), mouseButtonRelease(), and mouseMove().

The material used by the highlight object.

Definition at line 208 of file OSGSimpleSceneManager.h.

Referenced by highlightChanged().


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:19:22 2008 for OpenSG by  doxygen 1.5.5