This tutorial demonstrates how simple it is to setup a stereo rendering using red/cyan anaglyphs with Visualization Library.
#include "BaseDemo.hpp"
class App_Stereo: public BaseDemo
{
public:
{
return BaseDemo::appletInfo();
}
void updateScene()
{
mStereoCamera->updateLeftRightCameras();
mRootTransform->computeWorldMatrixRecursive();
}
void initEvent()
{
mMainRendering->
subRenderings()->push_back(mLeftRendering.get());
mMainRendering->subRenderings()->push_back(mRightRendering.get());
setRendering(mMainRendering.get());
mLeftRendering->sceneManagers()->push_back(sceneManager());
mRightRendering->sceneManagers()->push_back(sceneManager());
mLeftRendering->renderer()->setFramebuffer(gl_context->
framebuffer());
mRightRendering->renderer()->setFramebuffer(gl_context->
framebuffer());
mStereoCamera->setLeftCamera(mLeftRendering->camera());
mStereoCamera->setRightCamera(mRightRendering->camera());
mStereoCamera->setConvergence(20);
mStereoCamera->setEyeSeparation(1);
mLeftRendering->renderer()->overriddenDefaultRenderStates().push_back(
RenderStateSlot(
new ColorMask(
false,
true,
true),-1));
mRightRendering->renderer()->overriddenDefaultRenderStates().push_back(
RenderStateSlot(
new ColorMask(
true,
false,
false),-1));
setupScene();
}
void setupScene()
{
sceneManager()->tree()->addActor( sphere.
get(), sphere_fx.
get(), mRootTransform.get());
float count = 10;
for(size_t i=0; i<count; ++i)
{
sceneManager()->tree()->addActor( satellite.
get(), fx.
get(), child_transform.
get());
}
}
void resizeEvent(int w, int h)
{
mMonoCamera->viewport()->setWidth ( w );
mMonoCamera->viewport()->setHeight( h );
mStereoCamera->updateLeftRightCameras();
}
void loadModel(const std::vector<String>& files)
{
sceneManager()->tree()->actors()->clear();
for(unsigned int ifile=0; ifile<files.size(); ++ifile)
{
if (!resource_db || resource_db->
count<
Actor>() == 0)
{
continue;
}
std::vector< ref<Actor> > actors;
for(unsigned iact=0; iact<actors.size(); ++iact)
{
sceneManager()->tree()->addActor( actor.
get() );
}
}
sceneManager()->computeBounds();
real convergence = sceneManager()->boundingSphere().radius() / 2;
real eye_separation = convergence/20;
mStereoCamera->setConvergence(convergence);
mStereoCamera->setEyeSeparation(eye_separation);
}
void fileDroppedEvent(const std::vector<String>& files) { loadModel(files); }
protected:
};