u may try to set viewer's threading model as
CullThreadPerCameraDrawThreadPerContext, i think it will help u.
[quote="Pertur"]Hi Robert,
So if I have a class where I describe the scene content and where I do changes
in real time int update function like this:
[code]
DemoOSGScene.h
/*! Cidetec data osg scene class */
class DemoOSGScene: public OSGScene
{
public:
//! An DemoOSGScene constructor.
/*!
A more elaborate description of the constructor.
*/
DemoOSGScene();
//! An DemoOSGScene destructor.
/*!
A more elaborate description of the destructor.
*/
~DemoOSGScene(void);
/** \fn osgGenerals::OSGGroup* getSceneGroup()
Return the scene group
\return osgGenerals::OSGGroup
*/
osg::Group* getSceneGroup() { return _rootGroup; };
/** \fn void update()
Update scene necesary values
\return
*/
virtual void update();
void initialize();
protected:
float getDistanceBetweenObjs(osg::Vec3 obj1, osg::Vec3 obj2);
osg::MatrixTransform* _mainObject;
std::vector<SceneObject> _sceneObjectsContainer;
osg::Vec3 _mainObjectV;
//main object velocity vector
int _dificulLevel;
float _nextObject;
osg::Node* _manzana;
};
[/code]
and the cpp
[code]
DemoOSGScene::DemoOSGScene()
{
_type = DEMO;
_rootGroup = new osg::Group();
_rootGroup->setDataVariance( osg::Object::DYNAMIC );
//define scene camera positions
LookAtCamera camera0 = {osg::Vec3f(0.0, 0.0,0.0),
osg::Vec3f(0.0,100.0,100.0), osg::Vec3f(0.0,0.0,1.0)};
addCameraPos(camera0);
//lights
_rootGroup->addChild(osgGenerals::createLight(osg::Vec3(50.0,200.0,200.0),
osg::Vec4(0.9,0.9,0.9,1.0)));
//load scene models
...
_dificulLevel = 1;
_simulTime = 0.0;
}
DemoOSGScene::~DemoOSGScene(void)
{
}
void DemoOSGScene::initialize()
{
_nextObject = 3.0;
_mainObjectV.set(0.0,0.0,0.0);
_sessionScore = 0.0;
//clean object container
for(int i=0;i<_sceneObjectsContainer.size();i++)
{
_rootGroup->removeChild(_sceneObjectsContainer[i].node);
_sceneObjectsContainer.erase(_sceneObjectsContainer.begin()+i);
i--;
}
_mainObject->setMatrix(osg::Matrix::translate(osg::Vec3(mainObjectInitPos[0],mainObjectInitPos[1],mainObjectInitPos[2])));
}
void DemoOSGScene::update()
{
float delta = _simulTime - preSimulTime;
//update objects position
{
...
}
//verify scene object collisions
{
...
}
//create or delete objects
{
...
}
preSimulTime = _simulTime;
}
[/code]
So in update function I need access to _rootGroup, _sceneObjectsContainer...
I have found this solution:
[code]
class UpdateRootCallback : public osg::Drawable::UpdateCallback
{
public:
virtual void update( osg::NodeVisitor* nv,
osg::Drawable* drawable )
{
...
}
};
_rootGroup->setDataVariance( osg::Object::DYNAMIC );
_rootGroup->setUpdateCallback( new UpdateRootCallback );
[/code]
But I need to pass my objects pointers from DemoOSGScene... and I don't know
how to put thread access control for the objects...
Is this the best solution? Maybe I should redesign the system...
Thank you!
Cheers,
Aitor
Edit: I modify the code to integrate de update callback into DemoOSGScene, and
I change osg::Drawable::UpdateCallback for osg::NodeCallback (update(...) for
operator()(...)). So I have total access to members.
Assuming that I only going to modify objects in the function operate (), the
only problem I see is the variable _simulTimer, which is modified in the main
thread and read in the render thread.[/quote]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=53631#53631
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org