[osg-users] Recommended way to render a scene from multiple independent viewpoints
Riccardo Corsi
riccardo.corsi at kairos3d.it
Tue Apr 11 05:25:44 PDT 2017
Hi Hannes,
for the camera setup you're after I recommend using a SlaveUpdateCallback,
which will be called once per frame for each slave camera, allowing you to
manipulate the camera position/orientation at will.
Here's a code snippet:
// implement a slave callback to place the camera as you want
class MySlaveCallback : public osg::View::Slave::UpdateSlaveCallback
{
// implement update method
virtual void updateSlave(osg::View& view, osg::View::Slave& slave){ ... }
}
// add the camera as slave
slaveCam->setGraphicsContext(gc);
viewer.addSlave(slaveCam, true);
// install your callback
osg::View::Slave* slave = viewer.findSlaveForCamera(slaveCam);
slave->_updateSlaveCallback = pMirrorCallback;
Ricky
On Tue, Apr 11, 2017 at 2:11 PM, Hannes Naude <naude.jj at gmail.com> wrote:
> I think I solved my own problem. I was planning to use
>
> viewer.addSlave(cam,...)
>
>
> and then use
>
> cam->setReferenceFrame(osg::Transform::ABSOLUTE_RF)
>
>
> to decouple the slave camera from the master. (If this is not the best
> approach, I would still like to hear, but it seems pretty clean)
>
> It turned out that I did not even need the second call. I think this is
> because I have an update callback attached to each of the slave cameras
> that explicitly sets the view matrix to match the world-to-local matrix of
> some node in the scenegraph and thereby overrides the slaving.
>
> By the way, this is something else that has bothered me. The requirement
> for a camera to track a node in the scenegraph seems like it should be
> extremely common. But in order to implement this I had to write my own
> little NodeTracker Callback as follows:
>
> class NodeTracker : public NodeCallback
>
> {
>
> public:
>
> NodePath _nodepath;
>
>
> NodeTracker(Node* node):_nodepath(node->getParentalNodePaths()[0]){}
>
>
> virtual void operator()(Node* node, NodeVisitor* nv)
>
> {
>
> ref_ptr<Camera> cam=node->asCamera();
>
> if(cam)
>
> {
>
> Matrix mat2=cam->getViewMatrix();
>
> Matrix mat=computeWorldToLocal(_nodepath);
>
> cam->setViewMatrix(mat);
>
> }
>
> traverse(node, nv);
>
> }
>
> };
>
> It feels like this is such a common requirement that something like it
> should be built into OSG. I had a look at the tutorial on the subject :
>
> http://trac.openscenegraph.org/projects/osg//wiki/Support/Tutorials/
> CameraControlNodeFollowing
>
> but it recommends a solution that seems even more generally useful and is
> quite verbose, yet is not included in osg. What am I missing here?
>
> Regards
> Hannes Naude
>
>
> On Tue, Apr 11, 2017 at 1:08 PM, Hannes Naude <naude.jj at gmail.com> wrote:
>
>> Hi all
>>
>> I am trying to render a single scene from multiple viewpoints. I
>> initially implemented this with a compositeviewer as per the
>> osgthirdpersonview example. This worked fine except that my update
>> callbacks appeared to be getting called more than once per render cycle. I
>> assumed that the update traversal was being done for each view separately
>> and therefore nodes that are present in multiple views will have their
>> update callbacks called multiple times. So, at this point I tried to do the
>> same thing but with a single View, somewhat similar to the osgCamera
>> example. But, I do not want to add my cameras with viewer.addSlave as I
>> want them to move independently of one another. So I tried adding them into
>> the scene graph and giving each their own GraphicsContext, but even though
>> the windows corresponding to these GraphicsContexts get created, it appears
>> as if all rendering is done in a single window with multiple viewpoints
>> being rendered over one another.
>>
>> Obviously there are many ways to skin this cat, but I would appreciate
>> some guidance on the recommended approach. To recap my requirements are :
>> - Multiple cameras viewing the same scene.
>> - Camera positions and orientations must be independently controlled.
>> - Node update callbacks should be called only once per Node per render
>> cycle.
>>
>> Any help will be appreciated
>>
>> Regards
>> Hannes Naude
>>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170411/3423c4eb/attachment-0003.htm>
More information about the osg-users
mailing list