i did an other solution reproducing this problem, with a viewer reproducing
same simplified graph with only one camera and result is the good.
Code is :
GraphComplet.h
Code:
#pragma once
#include <osg\Switch>
#include <osg\Camera>
#include <osg\PositionAttitudeTransform>
class GraphComplet{
public:
GraphComplet();
osg::Node * getMainNode();
void moveObject(int obj, osg::Vec3 newPos);
private:
osg::ref_ptr<osg::Group> root;
osg::ref_ptr<osg::Camera> cam1;
osg::ref_ptr<osg::Camera> cam2;
osg::ref_ptr<osg::Camera> cam3;
osg::ref_ptr<osg::Camera> cam4;
osg::Switch * createSousGraph(std::string modelFilePath,osg::Vec3 pos);
};
GraphComplet.cpp
Code:
#include "GraphComplet.h"
#include <osgDB\readFile>
#include <assert.h>
GraphComplet::GraphComplet()
{
root = new osg::Group;
root->addChild(new osg::Group);
cam1 = new osg::Camera();
cam2 = new osg::Camera();
cam3 = new osg::Camera();
cam4 = new osg::Camera();
root->getChild(0)->asGroup()->addChild(new osg::Group);
root->getChild(0)->asGroup()->addChild(new osg::Group);
root->getChild(0)->asGroup()->getChild(0)->asGroup()->addChild(cam2);
root->getChild(0)->asGroup()->getChild(0)->asGroup()->addChild(cam1);
root->getChild(0)->asGroup()->getChild(1)->asGroup()->addChild(cam4);
root->getChild(0)->asGroup()->getChild(1)->asGroup()->addChild(cam3);
cam1->addChild(new osg::Group);
cam1->addChild(createSousGraph("data\\model.3DS",
osg::Vec3(0.0,0.0,0.0)));
cam3->addChild(new osg::Group);
cam3->addChild(createSousGraph("data\\model.3DS",
osg::Vec3(10.0,0.0,0.0)));
cam1->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cam2->setClearMask(0);
cam3->setClearMask(0);
cam4->setClearMask(0);
cam1->setRenderOrder(osg::Camera::PRE_RENDER,1);
cam2->setRenderOrder(osg::Camera::PRE_RENDER,2);
cam3->setRenderOrder(osg::Camera::PRE_RENDER,3);
cam4->setRenderOrder(osg::Camera::PRE_RENDER,4);
}
osg::Node * GraphComplet::getMainNode()
{
return root.get();
}
osg::Switch * GraphComplet::createSousGraph(std::string modelFilePath,osg::Vec3
pos)
{
osg::Switch * retour = new osg::Switch;
retour->setAllChildrenOn();
osg::PositionAttitudeTransform * pat = new
osg::PositionAttitudeTransform;
retour->addChild(pat);
pat->setPosition(pos);
pat->addChild(osgDB::readNodeFile(modelFilePath));
return retour;
}
void GraphComplet::moveObject(int obj, osg::Vec3 newPos)
{
osg::PositionAttitudeTransform * toMove = NULL;
if(obj == 1)
{
toMove =
cam1->getChild(1)->asGroup()->getChild(0)->asTransform()->asPositionAttitudeTransform();
}
else if(obj == 2)
{
toMove =
cam3->getChild(1)->asGroup()->getChild(0)->asTransform()->asPositionAttitudeTransform();
}
if(toMove == NULL) return;
toMove->setPosition(newPos);
}
main.cpp
Code:
#include <iostream>
#include <osgViewer\Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include "GraphComplet.h"
#include <math.h>
#define PI 3.14159265
#include <osgDB\readFile>
int main(int,char**)
{
osgViewer::Viewer v2;
v2.setCameraManipulator(new osgGA::TrackballManipulator());
v2.addEventHandler(new osgViewer::StatsHandler);
osg::Group * root = new osg::Group;
osg::PositionAttitudeTransform * patObjet1 = new
osg::PositionAttitudeTransform;
osg::PositionAttitudeTransform * patObjet2 = new
osg::PositionAttitudeTransform;
root->addChild(patObjet1);
root->addChild(patObjet2);
patObjet1->addChild(osgDB::readNodeFile("data\\3d-isuzu-bighorn.3DS"));
patObjet2->addChild(osgDB::readNodeFile("data\\3d-isuzu-bighorn.3DS"));
v2.setUpViewInWindow(600,10,600,600);
v2.setSceneData(root);
v2.realize();
GraphComplet * gc = new GraphComplet();
osgViewer::Viewer v;
v.setCameraManipulator(new osgGA::TrackballManipulator());
v.addEventHandler(new osgViewer::StatsHandler);
v.setSceneData(gc->getMainNode());
osg::Camera * cam = v.getCamera();
cam->setClearMask(0);
v.setUpViewInWindow(0,10,600,600);
v.realize();
osg::Vec3 pos(0,0,0);
double angle = 0;//angle en RAD
while(!v.done() && !v2.done())
{
gc->moveObject(2,pos);
patObjet2->setPosition(pos);
v.frame();
v2.frame();
angle+=0.003;
if(angle>=2*PI)
angle = 0;
pos.x() = 2000*cos(angle);
pos.y() = 20000*sin(angle);
}
v.setDone(true);
v2.setDone(true);
return 0;
}
In left view their is the original result i must make it run with this Graph.
Right i have the same model in simple scene with same position for all items.
I must have miss one thing for get good result as in windows on right!
"Please help !"
Thanks for reading me.
------------------------
(http://www.hordes.fr?ref=litllechicken)
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45008#45008
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org