Re: [osg-users] Calculating variables for setProjectionMatrixAsOrtho2D

2014-06-10 Thread Marco Kliko
Hi David,

Thanks for your reply!

Yes, I have set a view matrix.

For the time being, I have created manually a matrix that works with  a 
perspective view. So I should expect this also would work with the ortho2D view.

But it still doesn't work, so maybe that's the problem?

Right now this is my viewmatrix:
Viewer-getCamera()-setViewMatrixAsLookAt(osg::Vec3d(-3254.245223,582.225235,243.433186),
 osg::Vec3d(-3253.255848,582.274344,243.296343), 
osg::Vec3d(0.136638,0.007528,0.990592));

I positioned my object the way I wanted an printed the matrix values. So that's 
how I got these variables.

Thank you!

Cheers,
Marco

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





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


Re: [osg-users] Calculating variables for setProjectionMatrixAsOrtho2D

2014-06-10 Thread David Sellin
Hi,

I made a small test application. Try it out if you want to and see it it works 
and does what you want.

Code:
int main( int argc, char **argv )
{
osg::Group *root = new osg::Group;

osg::Group *scene = GetScene(); // - Cows, planes and stuff

root-addChild( scene );

// Graphics Context and Traits
osg::ref_ptrosg::GraphicsContext::Traits traits = new 
osg::GraphicsContext::Traits;
traits-windowName = Test app;
traits-screenNum = 0;
traits-x = 0;
traits-y = 0;
traits-width = WIDTH;
traits-height = HEIGHT;
traits-windowDecoration = false;
traits-doubleBuffer = true;
traits-sharedContext = 0;
traits-samples = 8;
traits-useCursor = true;
traits-alpha = 1.0;
const std::string version( 3.1 );
traits-glContextVersion = version;

osg::ref_ptrosg::GraphicsContext gc = 
osg::GraphicsContext::createGraphicsContext( traits.get() );

// Viewer
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer();
viewer-getCamera()-setProjectionMatrixAsOrtho( -100, 100, -100, 100, 
-100, 100 );
viewer-getCamera()-setCullingMode( osg::CullSettings::NO_CULLING );
viewer-getCamera()-setComputeNearFarMode( 
osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
viewer-getCamera()-setGraphicsContext( gc.get() );
viewer-getCamera()-setViewport( new osg::Viewport( 0, 0, WIDTH, 
HEIGHT) );
viewer-setThreadingModel( osgViewer::ViewerBase::SingleThreaded );
viewer-setCameraManipulator( new osgGA::TrackballManipulator );
viewer-setSceneData( root );

viewer-realize();

while( !viewer-done() )
{
viewer-advance();
viewer-eventTraversal();
viewer-updateTraversal();
viewer-renderingTraversals();
}

return 0;
}



Thank you!

Cheers,
David

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





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


Re: [osg-users] Calculating variables for setProjectionMatrixAsOrtho2D

2014-06-10 Thread Marco Kliko
Hi,

Thanks for your help. I got it working!  8)  |-)  :D 

Looks like it forgot tyo set a viewport and cameramanipulator.
Without these, apparantly it doesn't work...  :? 

Although I stripped down the code.
I think some parts of the code aren't that important, but maybe that's just my 
opinion.

Here's the stripped down code:


Code:
int main( int argc, char **argv )
{
   osg::Node *scene = osgDB::readNodeFile(d:/openscenegraph-data/cow.osg); // 
- Cows, planes and stuff
   
   // Viewer
   osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer();
   viewer-setUpViewInWindow(50,50,640,480);
   viewer-getCamera()-setProjectionMatrixAsOrtho( -1000, 1000, -1000, 1000, 
-300, 300 );
   //viewer-getCamera()-setComputeNearFarMode( 
osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR ); //You can do it without 
computing. This is a matter of taste
   
   viewer-setCameraManipulator( new osgGA::TrackballManipulator );
   viewer-setSceneData( scene );

   viewer-realize();
   while( !viewer-done() )
   {
   viewer-frame();
   }

   return 0;
} 



Kudo's to David for giving me the great and useful example!
I'm very happy and satisfied with the result!  8)  8) 

Thank you!

Cheers,
Marco

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





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


Re: [osg-users] Calculating variables for setProjectionMatrixAsOrtho2D

2014-06-09 Thread David Sellin
Hi,

Maybe it's your near far values. Your model might be placed in origo with 
bounds smaller than 1. And your near value starts at 1.

Try:
Code:
Viewer-getCamera()-setProjectionMatrixAsOrtho(bb.xMin(),bb.xMax(),bb.yMin(),bb.yMax(),-100,100);
 



Thank you!

Cheers,
David

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





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


Re: [osg-users] Calculating variables for setProjectionMatrixAsOrtho2D

2014-06-05 Thread Marco Kliko
Hi everyone,

I found another picture that may help describe what I am looking for...

[Image: http://www.vis-sim.com/imgdp/vp_chanprojections_01.jpg ]

I am not sure if this is the same way OSG uses the given variables, but I have 
no reason to believe it is different...

I've tried to use some more variations in the variables, still no sign of the 
cessna-plane... :(

Hope this helps..!

Thank you!

Cheers,
Marco

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





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


Re: [osg-users] Calculating variables for setProjectionMatrixAsOrtho2D

2014-06-04 Thread Marco Kliko

mkliko wrote:
 Hi everyone,
 
 The setProjectionMatrixAsOrtho2D-function is not really clear to me.
 I have tried a lot of different variables to give to this funtion.
 
 But they all result in a sceen with a blue background. Not even a small part 
 of the object I am trying to see.
 
 What I have is a 3D-model (like cow.osg of cessna.osg) and I want a side view 
 in Ortho 2D.
 
 Can anyone help me with calculating suitable values?
 
 I found and tried the example below, but no luck... :( 
 
 (Source: http://osdir.com/ml/OpenSceneGraph-Users/2008-05/msg00027.html)
 
 
 Code:
 
 osg::ref_ptrosg::Node node;
 Viewer-setSceneData(node);
 
 osg::BoundingBox bb;
 bb.expandBy(node-getBound());
 
 double xMid = (bb.xMin() + bb.xMax())/2;
 double yMid = (bb.yMin() + bb.yMax())/2;
 double zMid = (bb.zMin() + bb.zMax())/2;
 double radius = bb.radius();
   
 Viewer-getCamera()-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
   
 Viewer-getCamera()-setProjectionMatrixAsOrtho(bb.xMin(),bb.xMax(),bb.yMin(),bb.yMax(),1,100+abs(bb.zMax()
  - bb.zMin()));
   
   Viewer-setUpViewInWindow(x, y, width, height);
 
 
 
 
 Thank you!
 
 Cheers,
 Marco


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





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