[osg-users] Setting camera Viewmatrix with TrackBallManipulator Matrix gives nothing but black screen

2010-12-15 Thread Bart Jan Schuit
Hi,

I'm trying to setup some cameras without a manipulator. When I assign a 
Trackballmanipulator on the vies, I get the cow projected on the screen. But as 
soon as I manually setup the cameras, I get a completely black screen.
I extract eye, center and up from Tman (Trackballmanipulator) by 
Tman->getMatrix().lookat(eye, center, up).

This gives some nice coordinates, but when I put these in a camera without a 
manipulator like Tman, I just get a black screen. What am I doing wrong here?


Code:

int main( int argc, char **argv )
{

// use an ArgumentParser object to manage the program arguments.
   osg::ArgumentParser arguments(&argc,argv);



osg::Group* scene = new osg::Group();
osg::Node* groundNode = NULL;
groundNode = osgDB::readNodeFile("cow.osg");

scene->addChild(groundNode);

osgViewer::CompositeViewer viewer(arguments);

if (arguments.read("-2"))
{

// view one
{

osg::Vec3d eye = osg::Vec3d(0,0,250);
osg::Vec3d center = osg::Vec3d(0,0,250);
osg::Vec3d up = osg::Vec3d(0,0,-1);
osg::Quat rotation;
osg::Matrixd viewmat;

osg::Camera* camera = new osg::Camera;
osgViewer::View* view = new osgViewer::View;
view->setName("View one");
viewer.addView(view);
//camera->setProjectionMatrix( osg::Matrix::ortho2D(0,512,0,512) );  //not 
doing anything 
//camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
//camera->setViewMatrix( osg::Matrix::identity() );
view->setCameraManipulator(Tman);
//Tman->setAutoComputeHomePosition(false);
view->setUpViewOnSingleScreen(0);
view->setSceneData(scene);
//view->setCamera(camera);

}

// view two
{
osg::Matrixd viewmat;
osg::Camera* camera = new osg::Camera;
osgViewer::View* view = new osgViewer::View;
view->setName("View two");
viewer.addView(view);
view->setUpViewOnSingleScreen(1);
view->setSceneData(scene);
//view->setCamera(camera);
view->setCameraManipulator(Tman);
view->setName("right");
osg::Vec3d eye = osg::Vec3d(0,0,25);
osg::Vec3d center = osg::Vec3d(0,0,25);
osg::Vec3d up = osg::Vec3d(0,0,-1);
}
}
viewer.realize();



while(!viewer.done())
{   

osg::Vec3d eye = osg::Vec3d(0,0,50);
osg::Vec3d center = osg::Vec3d(0,0,50);
osg::Vec3d up = osg::Vec3d(0,0,-1);
Tman->setHomePosition(eye,center,up); //not working. Doesn't 
matter how I set eye, center etc.
viewer.frame();
}
}




--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=34890#34890





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Setting camera Viewmatrix with TrackBallManipulator Matrix gives nothing but black screen

2010-12-16 Thread Trajce (Nick) Nikolov
if this is your code (with all the comments) then here is what you should
do:

- forget about your osg::Camera* camera = new Camera; // there is already a
Camera attached to the View
- use view.getCamera()->setProjectionMatrixAsPerspective(45,1,1,1000);
- no need to attach any CameraManipulator if you want to set the view matrix
by your own (although that is the purpose of the CameraManipulator, to
change the view matrix - probably you do it this way when you get more
familiar with the code)
- in your loop you do
viewer.getView(0)->getCamera()->setViewMatrixAsLookAt(eye,center,up)

-Nick


On Wed, Dec 15, 2010 at 7:02 PM, Bart Jan Schuit  wrote:

> Hi,
>
> I'm trying to setup some cameras without a manipulator. When I assign a
> Trackballmanipulator on the vies, I get the cow projected on the screen. But
> as soon as I manually setup the cameras, I get a completely black screen.
> I extract eye, center and up from Tman (Trackballmanipulator) by
> Tman->getMatrix().lookat(eye, center, up).
>
> This gives some nice coordinates, but when I put these in a camera without
> a manipulator like Tman, I just get a black screen. What am I doing wrong
> here?
>
>
> Code:
>
> int main( int argc, char **argv )
> {
>
>// use an ArgumentParser object to manage the program arguments.
>   osg::ArgumentParser arguments(&argc,argv);
>
>
>
>osg::Group* scene = new osg::Group();
>osg::Node* groundNode = NULL;
>groundNode = osgDB::readNodeFile("cow.osg");
>
>scene->addChild(groundNode);
>
>osgViewer::CompositeViewer viewer(arguments);
>
>if (arguments.read("-2"))
>{
>
>// view one
>{
>
>osg::Vec3d eye = osg::Vec3d(0,0,250);
>osg::Vec3d center = osg::Vec3d(0,0,250);
>osg::Vec3d up = osg::Vec3d(0,0,-1);
>osg::Quat rotation;
>osg::Matrixd viewmat;
>
>osg::Camera* camera = new osg::Camera;
>osgViewer::View* view = new osgViewer::View;
>view->setName("View one");
>viewer.addView(view);
>//camera->setProjectionMatrix( osg::Matrix::ortho2D(0,512,0,512) );
>  //not doing anything
>//camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
>//camera->setViewMatrix( osg::Matrix::identity() );
>view->setCameraManipulator(Tman);
>//Tman->setAutoComputeHomePosition(false);
>view->setUpViewOnSingleScreen(0);
>view->setSceneData(scene);
>//view->setCamera(camera);
>
>}
>
>// view two
>{
>osg::Matrixd viewmat;
>osg::Camera* camera = new osg::Camera;
>osgViewer::View* view = new osgViewer::View;
>view->setName("View two");
>viewer.addView(view);
>view->setUpViewOnSingleScreen(1);
>view->setSceneData(scene);
>//view->setCamera(camera);
>view->setCameraManipulator(Tman);
>view->setName("right");
>osg::Vec3d eye = osg::Vec3d(0,0,25);
>osg::Vec3d center = osg::Vec3d(0,0,25);
>osg::Vec3d up = osg::Vec3d(0,0,-1);
>}
>}
>viewer.realize();
>
>
>
>while(!viewer.done())
>{
>
>osg::Vec3d eye = osg::Vec3d(0,0,50);
>osg::Vec3d center = osg::Vec3d(0,0,50);
>osg::Vec3d up = osg::Vec3d(0,0,-1);
>Tman->setHomePosition(eye,center,up); //not working. Doesn't
> matter how I set eye, center etc.
>viewer.frame();
>}
> }
>
>
>
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=34890#34890
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org