[osg-users] slave camera result in a distort result

2012-05-22 Thread GeeKer Wang
Hi, all,

I want to use two cameras to composite result in the same window,
so two slave cameras are used with an projection offset .
However, there is a distortion, e.g, a ball looks like an ellipse.

And I find that osgViewer::Viewer::adSlave(.) doesn't work properly by
itself.
Here is simple example to demo this problem, it's obvious that a ball is
distorted.

==
#include osgViewer/Viewer
#include osgDB/ReadFile
#include osg/GraphicsContext
#include osg/Camera
#include osg/ShapeDrawable
#include iostream


osg::GraphicsContext* createGraphicsContext(int x, int y,
int width, int height ){
osg::ref_ptrosg::GraphicsContext::Traits traits =
new osg::GraphicsContext::Traits;
traits-x = x;
traits-y = y;
traits-width = width;
traits-height = height;
traits-windowDecoration = true;
traits-doubleBuffer = true;
traits-sharedContext = 0;

osg::ref_ptrosg::GraphicsContext gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
if(gc.valid()){
gc-setClearColor(osg::Vec4(0.2f,0.2f,0.0f,1.0f));
gc-setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
return gc.release();
}


osg::Camera* setupCamera(osg::GraphicsContext* gc) {
int width,height;
width = gc-getTraits()-width;
height = gc-getTraits()-height;
GLenum buffer = gc-getTraits()-doubleBuffer ? GL_BACK : GL_FRONT;

osg::ref_ptrosg::Camera camera = new osg::Camera;
camera-setGraphicsContext(gc);

camera-setViewport(0,0,width,height);

camera-setDrawBuffer(buffer);
camera-setReadBuffer(buffer);

return camera.release();
}

osg::Node* createBall() {
osg::ref_ptrosg::ShapeDrawable drawable = new osg::ShapeDrawable;
drawable-setShape(new osg::Sphere(osg::Vec3f(0,0,0), 10));
osg::ref_ptrosg::Geode geode = new osg::Geode;
geode-addDrawable(drawable.get());
return geode.release();
}


int main(int argc, char* argv[]){
osgViewer::Viewer viewer;
viewer.addSlave(setupCamera(createGraphicsContext(0,0,800,600)));
//viewer.setCamera(setupCamera(createGraphicsContext(0,0,800,600)));
viewer.setSceneData(createBall());
viewer.run();
return 0;
}
===

So, where is the problem? And how to handle it?

Any advice will  be appreciated.


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


Re: [osg-users] slave camera result in a distort result

2012-05-22 Thread Trystan Larey-Williams
I don't see a projection matrix being explicitly set. I think OSG does a 
perspective projection be default. Especially depending on the default FOV, 
this can produce a pronounced distortion. See the camera methods 
setProjectionMatrixAsPerspective and setProjectionMatrixAsOrtho. If you want no 
distortion then you probably want the latter. 

-Trystan

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





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


Re: [osg-users] slave camera result in a distort result

2012-05-22 Thread GeeKer Wang
No projection is set in my example. What I want to know is why main camera
and slave camera produce different result.

When you use setCamera(.) rather than addSlave(.), the result is perfect by
default.

On Wed, May 23, 2012 at 1:17 AM, Trystan Larey-Williams trys...@trystan.org
 wrote:

 I don't see a projection matrix being explicitly set. I think OSG does a
 perspective projection be default. Especially depending on the default FOV,
 this can produce a pronounced distortion. See the camera methods
 setProjectionMatrixAsPerspective and setProjectionMatrixAsOrtho. If you
 want no distortion then you probably want the latter.

 -Trystan

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





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




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