本文整理汇总了C++中NodeRefPtr类的典型用法代码示例。如果您正苦于以下问题:C++ NodeRefPtr类的具体用法?C++ NodeRefPtr怎么用?C++ NodeRefPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeRefPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare
void
Tree::search_recursive(const ResourceName &resName,
const NodeRefPtr node,
std::vector<PDRefCntPtr> &results,
bool usePatterns) const {
am_resource_match_t compRes;
compRes = compare(node->getPolicyDecision()->getName(),
resName,
usePatterns);
std::list<NodeRefPtr>::const_iterator iter;
switch(compRes) {
case AM_EXACT_MATCH:
results.push_back(node->getPolicyDecision());
break;
case AM_EXACT_PATTERN_MATCH:
results.push_back(node->getPolicyDecision());
// fall through to the following
case AM_SUB_RESOURCE_MATCH:
case AM_NO_MATCH:
for(iter = node->begin(); iter != node->end(); iter++) {
search_recursive(resName, *iter, results, usePatterns);
}
break;
default:
break;
}
return;
}
示例2: MakeChain
static
NodeRefPtr MakeChain(size_t n) {
if (n == 0)
return TfNullPtr;
else {
NodeRefPtr root = Node::New();
root->SetChild(MakeChain(n-1));
return root;
}
}
示例3: find
bool
Tree::markStale(const ResourceName & resName, bool recursive) {
SearchResult result = find(rootNode, resName, false);
if(result.first == AM_EXACT_MATCH) {
NodeRefPtr delNode = result.second;
delNode->markNodeStale(recursive);
return true;
}
return false;
}
示例4: removeNode
void SceneGraphTreeModel::removeNode(NodeUnrecPtr nodeToBeRemoved)
{
NodeRefPtr parent = nodeToBeRemoved->getParent();
TreePath pathOfNode = createPath(nodeToBeRemoved);
if(parent!=NULL)
{
UInt32 ChildIndex(parent->findChild(nodeToBeRemoved));
produceTreeNodesWillBeRemoved(pathOfNode.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeRemoved));
parent->subChild(nodeToBeRemoved);
produceTreeNodesRemoved(pathOfNode.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeRemoved));
if(parent->getNChildren() == 0)
{
if(parent->getParent() != NULL)
{
std::vector<UInt32> childIndices;
childIndices.push_back(parent->getParent()->findChild(parent));
std::vector<boost::any> ChildUserObjects;
for(UInt32 i(0) ; i< childIndices.size() ; ++i)
{
ChildUserObjects.push_back(boost::any(NodeUnrecPtr(parent->getParent()->getChild(childIndices[i]))));
}
produceTreeNodesChanged(createPath(parent->getParent()), childIndices, ChildUserObjects);
}
}
}
}
示例5: showAll
void showAll(PerspectiveCameraRefPtr TheCamera, NodeRefPtr Scene, Vec3f Up)
{
//Make sure the volume is up to date for the Scene
Scene->updateVolume();
//Get the Minimum and Maximum bounds of the volume
Vec3f min,max;
Scene->getVolume().getBounds( min, max );
Vec3f d = max - min;
if(d.length() < Eps) //The volume is 0
{
//Default to a 1x1x1 box volume
min.setValues(-0.5f,-0.5f,-0.5f);
max.setValues( 0.5f, 0.5f, 0.5f);
d = max - min;
}
Real32 dist = osgMax(d[0],d[1]) / (2 * osgTan(TheCamera->getFov() / 2.f));
Pnt3f at((min[0] + max[0]) * .5f,(min[1] + max[1]) * .5f,(min[2] + max[2]) * .5f);
Pnt3f from=at;
from[2]+=(dist+fabs(max[2]-min[2])*0.5f);
//If the Camera Beacon is a node with a transfrom core
if(TheCamera->getBeacon() != NULL &&
TheCamera->getBeacon()->getCore() != NULL &&
TheCamera->getBeacon()->getCore()->getType().isDerivedFrom(Transform::getClassType()))
{
Matrix m;
if(!MatrixLookAt(m, from, at, Up))
{
dynamic_cast<Transform*>(TheCamera->getBeacon()->getCore())->setMatrix(m);
}
}
//Set the camera to go from 1% of the object to 10 times its size
Real32 diag = osgMax(osgMax(d[0], d[1]), d[2]);
TheCamera->setNear (diag / 100.f);
TheCamera->setFar (10 * diag);
}
示例6: buildBox
//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
void buildBox(void)
{
Vec3f Lengths((Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0, (Real32)(rand()%2)+1.0);
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
NodeRefPtr boxNode = makeBox(Lengths.x(), Lengths.y(), Lengths.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialRefPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(0.0,1.0 ,0.0));
box->setMaterial(box_mat);
TransformRefPtr boxTrans;
NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 10.0);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyRefPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(randX, randY, 10.0));
boxBody->setBoxMass(1.0, Lengths.x(), Lengths.y(), Lengths.z());
//std::cout << "mass: " << boxBody->getMass() << std::endl
//<< "massCenterOfGravity: " << boxBody->getMassCenterOfGravity().x() << ", " << boxBody->getMassCenterOfGravity().y() << ", " << boxBody->getMassCenterOfGravity().z() << std::endl
//<< "massInertiaTensor: " << std::endl
//<< boxBody->getMassInertiaTensor()[0][0] << " "<< boxBody->getMassInertiaTensor()[0][1] << " "<< boxBody->getMassInertiaTensor()[0][2] << " " << boxBody->getMassInertiaTensor()[0][3] << std::endl
//<< boxBody->getMassInertiaTensor()[1][0] << " "<< boxBody->getMassInertiaTensor()[1][1] << " "<< boxBody->getMassInertiaTensor()[1][2] << " " << boxBody->getMassInertiaTensor()[1][3] << std::endl
//<< boxBody->getMassInertiaTensor()[2][0] << " "<< boxBody->getMassInertiaTensor()[2][1] << " "<< boxBody->getMassInertiaTensor()[2][2] << " " << boxBody->getMassInertiaTensor()[2][3] << std::endl
//<< boxBody->getMassInertiaTensor()[3][0] << " "<< boxBody->getMassInertiaTensor()[3][1] << " "<< boxBody->getMassInertiaTensor()[3][2] << " " << boxBody->getMassInertiaTensor()[3][3] << std::endl
//<< std::endl;
PhysicsBoxGeomRefPtr boxGeom = PhysicsBoxGeom::create();
boxGeom->setBody(boxBody);
boxGeom->setSpace(physicsSpace);
boxGeom->setLengths(Lengths);
//add attachments
boxNode->addAttachment(boxGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
}
示例7: buildTriMesh
//////////////////////////////////////////////////////////////////////////
//! trimesh defined by filenode will be loaded
//////////////////////////////////////////////////////////////////////////
void buildTriMesh(void)
{
NodeRefPtr tri = cloneTree(TriGeometryBase);
if(tri!=NULL)
{
GeometryRefPtr triGeo = dynamic_cast<Geometry*>(tri->getCore());
Matrix m;
SimpleMaterialRefPtr tri_mat = SimpleMaterial::create();
tri_mat->setAmbient(Color3f(0.1,0.1,0.2));
tri_mat->setDiffuse(Color3f(1.0,0.1,0.7));
triGeo->setMaterial(tri_mat);
TransformRefPtr triTrans;
NodeRefPtr triTransNode = makeCoredNode<Transform>(&triTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 18.0);
triTrans->setMatrix(m);
//create ODE data
Vec3f GeometryBounds(calcMinGeometryBounds(triGeo));
PhysicsBodyRefPtr triBody = PhysicsBody::create(physicsWorld);
triBody->setPosition(Vec3f(randX, randY, 18.0));
triBody->setLinearDamping(0.0001);
triBody->setAngularDamping(0.0001);
triBody->setBoxMass(1.0,GeometryBounds.x(), GeometryBounds.y(), GeometryBounds.z());
PhysicsGeomRefPtr triGeom;
if(true)
{
triGeom = PhysicsTriMeshGeom::create();
triGeom->setBody(triBody);
//add geom to space for collision
triGeom->setSpace(physicsSpace);
//set the geometryNode to fill the ode-triMesh
NodeRefPtr TorusGeometryNode(makeTorus(0.55, 1.05, 6, 6));
dynamic_pointer_cast<PhysicsTriMeshGeom>(triGeom)->setGeometryNode(TorusGeometryNode);
}
//add attachments
tri->addAttachment(triGeom);
triTransNode->addAttachment(triBody);
//add to SceneGraph
triTransNode->addChild(tri);
spaceGroupNode->addChild(triTransNode);
}
else
{
SLOG << "Could not read MeshData!" << endLog;
}
commitChanges();
}
示例8: buildShip
//////////////////////////////////////////////////////////////////////////
//! build a ship
//////////////////////////////////////////////////////////////////////////
PhysicsBodyRefPtr buildShip(Vec3f Dimensions, Pnt3f Position)
{
Real32 Radius(osgMax(Dimensions.x(), Dimensions.y())/2.0f);
Real32 Length(Dimensions.z() - 2.0f*Radius);
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
NodeRefPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialRefPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(1.0,1.0 ,0.0));
box->setMaterial(box_mat);
TransformRefPtr boxTrans;
NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position - Vec3f(0.0f,0.0f,0.5f*Dimensions.z()));
boxTrans->setMatrix(m);
for(UInt32 i(0) ; i<box->getPositions()->size() ; ++i)
{
box->getPositions()->setValue<Pnt3f>(box->getPositions()->getValue<Pnt3f>(i) + Vec3f(0.0,0.0,Dimensions.z()/2.0f),i);
}
//create ODE data
PhysicsBodyRefPtr CapsuleBody = PhysicsBody::create(physicsWorld);
CapsuleBody->setPosition(Vec3f(Position - Vec3f(0.0f,0.0f,0.5f*Dimensions.z())));
CapsuleBody->setLinearDamping(0.01);
CapsuleBody->setMaxAngularSpeed(0.0);
CapsuleBody->setCapsuleMass(1.0,3,Radius, Length);
PhysicsCapsuleGeomRefPtr CapsuleGeom = PhysicsCapsuleGeom::create();
CapsuleGeom->setBody(CapsuleBody);
CapsuleGeom->setOffsetPosition(Vec3f(0.0f,0.0f,0.5f*Dimensions.z()));
CapsuleGeom->setSpace(hashSpace);
CapsuleGeom->setRadius(Radius);
CapsuleGeom->setLength(Length);
//add attachments
boxNode->addAttachment(CapsuleGeom);
boxTransNode->addAttachment(CapsuleBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return CapsuleBody;
}
示例9: buildSphere
//////////////////////////////////////////////////////////////////////////
//! build a sphere
//////////////////////////////////////////////////////////////////////////
void buildSphere(void)
{
Real32 Radius((Real32)(rand()%2)*0.5+0.5);
Matrix m;
//create OpenSG mesh
GeometryRefPtr sphere;
NodeRefPtr sphereNode = makeSphere(2, Radius);
sphere = dynamic_cast<Geometry*>(sphereNode->getCore());
SimpleMaterialRefPtr sphere_mat = SimpleMaterial::create();
sphere_mat->setAmbient(Color3f(0.0,0.0,0.0));
sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0));
sphere->setMaterial(sphere_mat);
TransformRefPtr sphereTrans;
NodeRefPtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans);
m.setIdentity();
Real32 randX = (Real32)(rand()%10)-5.0;
Real32 randY = (Real32)(rand()%10)-5.0;
m.setTranslate(randX, randY, 10.0);
sphereTrans->setMatrix(m);
//create ODE data
PhysicsBodyRefPtr sphereBody = PhysicsBody::create(physicsWorld);
sphereBody->setPosition(Vec3f(randX, randY, 10.0));
sphereBody->setAngularDamping(0.0001);
sphereBody->setSphereMass(1.0,Radius);
PhysicsSphereGeomRefPtr sphereGeom = PhysicsSphereGeom::create();
sphereGeom->setBody(sphereBody);
sphereGeom->setSpace(physicsSpace);
sphereGeom->setRadius(Radius);
//add attachments
sphereNode->addAttachment(sphereGeom);
sphereTransNode->addAttachment(sphereBody);
sphereTransNode->addChild(sphereNode);
//add to SceneGraph
spaceGroupNode->addChild(sphereTransNode);
commitChanges();
}
示例10: buildCharacter
//////////////////////////////////////////////////////////////////////////
//! build a character
//////////////////////////////////////////////////////////////////////////
PhysicsBodyRefPtr buildCharacter(Vec3f Dimensions,
Pnt3f Position,
Node* const spaceGroupNode,
PhysicsWorld* const physicsWorld,
PhysicsHashSpace* const physicsSpace
)
{
Real32 Radius(osgMax(Dimensions.x(), Dimensions.y())/2.0f);
Real32 Length(Dimensions.z() - 2.0f*Radius);
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
//NodeRefPtr characterNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
NodeRefPtr characterNode = SceneFileHandler::the()->read("Data/Jack.osb");
if(characterNode == NULL)
{
characterNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
}
box = dynamic_cast<Geometry*>(characterNode->getCore());
TransformRefPtr boxTrans;
NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyRefPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(Position));
//boxBody->setLinearDamping(0.001);
//boxBody->setAngularDamping(0.001);
boxBody->setMaxAngularSpeed(0.0);
boxBody->setCapsuleMass(1.0,3,Radius, Length);
PhysicsCapsuleGeomRefPtr CapsuleGeom = PhysicsCapsuleGeom::create();
CapsuleGeom->setBody(boxBody);
CapsuleGeom->setSpace(physicsSpace);
CapsuleGeom->setRadius(Radius);
CapsuleGeom->setLength(Length);
//add attachments
characterNode->addAttachment(CapsuleGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(characterNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return boxBody;
}
示例11: invalid_argument
/* Throws std::invalid_argument if any argument is invalid */
void
Tree::addSubNodes(NodeRefPtr parent, XMLElement &thisNode,
KVMRefCntPtr env)
{
string resName;
if(thisNode.isNamed(RESOURCE_RESULT) &&
thisNode.getAttributeValue(NAME, resName)) {
XMLElement decn;
NodeRefPtr newNode;
if(thisNode.getSubElement(POLICY_DECISION, decn)) {
PDRefCntPtr decision =
PolicyDecision::construct_policy_decision(resName, decn,
env);
newNode = new Node(parent, decision);
// If the parent is NULL, then this is the root Node.
if(parent != NULL) {
parent->addNode(newNode);
} else {
rootNode = newNode;
}
} else {
throw std::invalid_argument("Tree:addSubNodes(...) Cannot find "
"Policy Decision node under resource "
"result.");
}
XMLElement subElems;
if(thisNode.getSubElement(RESOURCE_RESULT, subElems)) {
for(;subElems.isValid(); subElems.nextSibling(RESOURCE_RESULT)) {
addSubNodes(newNode, subElems, env);
}
}
} else {
throw std::invalid_argument("Tree::addSubNodes(...) has an invalid XML as input.");
}
}
示例12: buildBox
//////////////////////////////////////////////////////////////////////////
//! build a box
//////////////////////////////////////////////////////////////////////////
PhysicsBodyRefPtr buildBox(Vec3f Dimensions, Pnt3f Position)
{
Matrix m;
//create OpenSG mesh
GeometryRefPtr box;
NodeRefPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1);
box = dynamic_cast<Geometry*>(boxNode->getCore());
SimpleMaterialRefPtr box_mat = SimpleMaterial::create();
box_mat->setAmbient(Color3f(0.0,0.0,0.0));
box_mat->setDiffuse(Color3f(0.0,1.0 ,1.0));
box->setMaterial(box_mat);
TransformRefPtr boxTrans;
NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans);
m.setIdentity();
m.setTranslate(Position);
boxTrans->setMatrix(m);
//create ODE data
PhysicsBodyRefPtr boxBody = PhysicsBody::create(physicsWorld);
boxBody->setPosition(Vec3f(Position));
boxBody->setLinearDamping(0.001);
boxBody->setAngularDamping(0.001);
boxBody->setBoxMass(1.0,Dimensions.x(), Dimensions.y(), Dimensions.z());
PhysicsBoxGeomRefPtr boxGeom = PhysicsBoxGeom::create();
boxGeom->setBody(boxBody);
boxGeom->setSpace(hashSpace);
boxGeom->setLengths(Dimensions);
//add attachments
boxNode->addAttachment(boxGeom);
boxTransNode->addAttachment(boxBody);
boxTransNode->addChild(boxNode);
//add to SceneGraph
spaceGroupNode->addChild(boxTransNode);
commitChanges();
return boxBody;
}
示例13: newNode
bool
Tree::insertBelow(NodeRefPtr parent, PDRefCntPtr &elem) {
std::list<NodeRefPtr>::iterator iter;
NodeRefPtr newNode(new Node(parent, elem));
// add the subordinate nodes of newNode under
// new node. In the next loop, we iterate nodes
// under new node and remove them from parent.
// Reason: if we remove nodes under parent in this
// loop, iterator becomes invalid.
ScopeLock myLock(treeLock);
for(iter = parent->begin(); iter != parent->end(); iter++) {
NodeRefPtr node = *iter;
PDRefCntPtr data = node->getPolicyDecision();
switch(compare(data->getName(), elem->getName(), false)) {
case AM_EXACT_MATCH:
case AM_SUB_RESOURCE_MATCH:
return false;
case AM_NO_MATCH:
break;
case AM_SUPER_RESOURCE_MATCH:
newNode->addNode(node);
break;
}
}
for(iter = newNode->begin(); iter != newNode->end(); iter++) {
NodeRefPtr node = *iter;
parent->remove(node);
}
parent->addNode(newNode);
return true;
}
示例14: main
// Initialize GLUT & OpenSG and set up the rootNode
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
TutorialUpdateListener TheTutorialUpdateListener;
TutorialWindow->addUpdateListener(&TheTutorialUpdateListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Make Main Scene Node
NodeRefPtr scene = makeCoredNode<Group>();
setName(scene, "scene");
rootNode = Node::create();
setName(rootNode, "rootNode");
ComponentTransformRefPtr Trans;
Trans = ComponentTransform::create();
{
rootNode->setCore(Trans);
// add the torus as a child
rootNode->addChild(scene);
}
//Make The Physics Characteristics Node
PhysicsCharacteristicsDrawableUnrecPtr PhysDrawable = PhysicsCharacteristicsDrawable::create();
PhysDrawable->setRoot(rootNode);
PhysDrawableNode = Node::create();
PhysDrawableNode->setCore(PhysDrawable);
PhysDrawableNode->setTravMask(TypeTraits<UInt32>::getMin());
rootNode->addChild(PhysDrawableNode);
//Light Beacon
NodeRefPtr TutorialLightBeacon = makeCoredNode<Transform>();
//Light Node
DirectionalLightRefPtr TutorialLight = DirectionalLight::create();
TutorialLight->setDirection(0.0,0.0,-1.0);
TutorialLight->setBeacon(TutorialLightBeacon);
NodeRefPtr TutorialLightNode = Node::create();
TutorialLightNode->setCore(TutorialLight);
scene->addChild(TutorialLightNode);
scene->addChild(TutorialLightBeacon);
//Setup Physics Scene
physicsWorld = PhysicsWorld::create();
physicsWorld->setWorldContactSurfaceLayer(0.01);
physicsWorld->setAutoDisableFlag(1);
physicsWorld->setAutoDisableTime(0.75);
physicsWorld->setWorldContactMaxCorrectingVel(1.0);
//physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81));
//physicsWorld->setCfm(0.001);
//physicsWorld->setErp(0.2);
hashSpace = PhysicsHashSpace::create();
physHandler = PhysicsHandler::create();
physHandler->setWorld(physicsWorld);
physHandler->pushToSpaces(hashSpace);
physHandler->setUpdateNode(rootNode);
physHandler->attachUpdateProducer(TutorialWindow->editEventProducer());
rootNode->addAttachment(physHandler);
rootNode->addAttachment(physicsWorld);
rootNode->addAttachment(hashSpace);
/************************************************************************/
/* create spaces, geoms and bodys */
/************************************************************************/
//create a group for our space
GroupRefPtr spaceGroup;
spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
//add Attachments to nodes...
//.........这里部分代码省略.........
示例15: renderSceneToTexture
OSG_USING_NAMESPACE
void renderSceneToTexture(Scene* const TheScene,
TextureObjChunk* const ColorTexture,
Window* const TheWindow,
RenderAction* TheRenderAction)
{
//Create an FBO to render the Scene's Viewport(s) into
FrameBufferObjectRecPtr SceneFBO = FrameBufferObject::create();
TextureBufferRecPtr FBOTextureBuffer = TextureBuffer ::create();
RenderBufferRecPtr FBODepthBuffer = RenderBuffer ::create();
//Attache the Texture to the TexureBuffer
FBOTextureBuffer->setTexture(ColorTexture);
// add a depth attachment, otherwise there is no depth buffer when
// rendering to the FBO
FBODepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24);
// make the fbo render to the texture
SceneFBO->setColorAttachment(FBOTextureBuffer, 0);
SceneFBO->setDepthAttachment(FBODepthBuffer );
SceneFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
SceneFBO->setWidth (FBOTextureBuffer->getTexture()->getImage()->getWidth() );
SceneFBO->setHeight(FBOTextureBuffer->getTexture()->getImage()->getHeight());
/*
Next we set up a Stage, which renders the subtree below it to its
render target (the FBO from above).
*/
SimpleStageRefPtr SceneStage = SimpleStage::create();
NodeRefPtr SceneStageNode = makeNodeFor(SceneStage);
ViewportRecPtr SceneViewport(TheScene->getPrimaryViewport());
SceneStage->setRenderTarget(SceneFBO);
SceneStage->setLeft(SceneViewport->getLeft());
SceneStage->setRight(SceneViewport->getRight());
SceneStage->setTop(SceneViewport->getTop());
SceneStage->setBottom(SceneViewport->getBottom());
SceneStage->setCamera(SceneViewport->getCamera());
SceneStage->setBackground(SceneViewport->getBackground());
for(UInt32 i(0) ; i<SceneViewport->getMFForegrounds()->size() ; ++i)
{
SceneStage->pushToForegrounds(SceneViewport->getForegrounds(i));
}
SceneStageNode->addChild(SceneViewport->getRoot());
NodeRecPtr ThumbRootNode = makeCoredNode<Group>();
ThumbRootNode->addChild(SceneStageNode);
CameraRecPtr ThumbCamera = MatrixCamera::create();
ThumbCamera->setBeacon(ThumbRootNode);
BackgroundRecPtr ThumbBackground = PassiveBackground::create();
//Create a dummy Viewport for attaching to the window
ViewportRecPtr ThumbViewport = Viewport::create();
ThumbViewport->setBackground(ThumbBackground);
ThumbViewport->setRoot(ThumbRootNode);
ThumbViewport->setCamera(ThumbCamera);
//Get all of the original TravMasks of the Viewports on the window
//Set all of the TravMasks of the Viewports on the window to 0
std::vector<UInt32> OrigTravMasks;
OrigTravMasks.reserve(TheWindow->getMFPort()->size());
for(UInt32 i(0) ; i<TheWindow->getMFPort()->size() ; ++i)
{
OrigTravMasks.push_back(TheWindow->getPort(i)->getTravMask());
TheWindow->getPort(i)->setTravMask(0);
}
//Attach the Viewport to the Window
TheWindow->addPort(ThumbViewport);
//Draw the window
TheWindow->render(TheRenderAction);
//Detach the Viewport from the Window
TheWindow->subPortByObj(ThumbViewport);
//Reset all of the original TravMasks of the Viewports on the window
for(UInt32 i(0) ; i<TheWindow->getMFPort()->size() ; ++i)
{
TheWindow->getPort(i)->setTravMask(OrigTravMasks[i]);
}
}