PDA

View Full Version : [OT]: Has anyone done this ? Recursive Scene graphs



ToolTech
03-21-2003, 01:26 AM
I just wanted to share a new idea I have been working on for a while. It now works.

Can you see the implementation of the recursive algo in the scene graph ?

It builds trees that are the same on each x,y position where they are instantiated





gzRealXY xyfunk1(gzReal in)
{
return gzRealXY(in*(1-in)*sin(in*GZ_PI*3)*2,in*(1-in)*sin(3*in*GZ_PI)*2);
}

gzRealXY xyfunk2(gzReal in)
{
return gzRealXY(in*(1-in)*sin(in*GZ_PI)*2,in*(1-in)*sin(in*GZ_PI));
}

// A test sample of a geometry
gzNode *buildTree()
{
gzGeometry *base_1=new gzGeometryTube(20,1,10,6,GZ_TUBE_CONE,xyfunk1,10,1 0);

//base_1->useDisplayList(TRUE);

gzGeometry *base_2=new gzGeometryTube(20,1,3,6,GZ_TUBE_CONE,xyfunk2,10,10 );

//base_2->useDisplayList(TRUE);

// Base branch

gzSeedSwitch *base=new gzSeedSwitch;

base->addNode(base_1);
base->addNode(base_2);


// Build tree

gzRecursive *tree=new gzRecursive;

tree->setMaxDepth(4);

// tree=(base+T1*R1*S1*tree+T2*R2*S2*tree+SW*(T3*R3*S 3*tree.....))


// tree=base
tree->addNode(base);

// TRS1 - top striving high
gzSeedTransform *pSeedTransform_1=new gzSeedTransform();
pSeedTransform_1->setTranslation(0,19.8,0);
pSeedTransform_1->setScale(0.5,0.6,0.5);
pSeedTransform_1->setHPRSeedValue(TRUE,gzVec3(0,-10,-10),gzVec3(0,10,10));
pSeedTransform_1->addNode(tree);

// tree=base+T1*R1*S1*tree
tree->addNode(pSeedTransform_1);


// TRS2 - side winder
gzSeedTransform *pSeedTransform_2=new gzSeedTransform();
pSeedTransform_2->setTranslation(0,19.7,0);
pSeedTransform_2->setScale(0.4,0.5,0.4);
pSeedTransform_2->setHPRSeedValue(TRUE,gzVec3(0,20,20),gzVec3(360,30 ,30));
pSeedTransform_2->addNode(tree);

tree->addNode(pSeedTransform_2);


// TRS3 - optional branch
gzSeedTransform *pSeedTransform_3=new gzSeedTransform();
pSeedTransform_3->setTranslation(0,17,0);
pSeedTransform_3->setScale(0.3,0.4,0.3);
pSeedTransform_3->setHPRSeedValue(TRUE,gzVec3(0,-120,-120),gzVec3(180,120,120));
pSeedTransform_3->addNode(tree);

// TRS4 - optional branch
gzSeedTransform *pSeedTransform_4=new gzSeedTransform;
pSeedTransform_4->setTranslation(0,17,0);
pSeedTransform_4->setScale(0.3,0.6,0.3);
pSeedTransform_4->setHPRSeedValue(TRUE,gzVec3(180,30,-60),gzVec3(270,60,60));
pSeedTransform_4->addNode(tree);

// TRS5 - optional branch
gzSeedTransform *pSeedTransform_5=new gzSeedTransform;
pSeedTransform_5->setTranslation(0,15,0);
pSeedTransform_5->setScale(0.4,0.6,0.4);
pSeedTransform_5->setHPRSeedValue(TRUE,gzVec3(270,30,-60),gzVec3(360,60,60));
pSeedTransform_5->addNode(tree);


// Optional braches
gzSeedSwitch *pSeedSwitch_O=new gzSeedSwitch;
pSeedSwitch_O->useExclusive(FALSE);


pSeedSwitch_O->addNode(pSeedTransform_3);
pSeedSwitch_O->setSeedProbability(0,1);

pSeedSwitch_O->addNode(pSeedTransform_4);
pSeedSwitch_O->setSeedProbability(1,1);

pSeedSwitch_O->addNode(pSeedTransform_5);
pSeedSwitch_O->setSeedProbability(2,1);


// Add optional to tree
tree->addNode(pSeedSwitch_O);


// Fix state on overall tree

gzMaterial *material=new gzMaterial;
gzState *state=new gzState;

state->setMaterial(material);
state->setMode(GZ_STATE_MATERIAL,GZ_STATE_ON);

gzTexture *tex=new gzTexture;

tex->setImage(gzImageManager::loadImage("bark.bmp"));
tex->setWrapS(GZ_REPEAT);
tex->setWrapT(GZ_REPEAT);
tex->useMipMaps(TRUE);
tex->setMagFilter(GZ_LINEAR);
tex->setMinFilter(GZ_LINEAR_MIPMAP_LINEAR);


state->setTexture(tex);
state->setMode(GZ_STATE_TEXTURE,GZ_STATE_ON);

// Seed starter
gzSeedControl *topNode=new gzSeedControl;
//topNode->setSeedControlType(GZ_SEED_FROM_TIME);

topNode->setState(state);

// Add recursive tree

topNode->addNode(tree);

return topNode;
}

wimmer
03-21-2003, 05:23 AM
look here:
http://www.cg.tuwien.ac.at/research/vr/recursIV/

Robert Osfield
03-21-2003, 05:49 AM
I haven't tried it myself with the OpenSceneGraph, but your enthusiasn makes me tempted to try out a little traversal callback on a osg::Group node to implement a recursive subgraph.

I guess the fun part comes when the amount of recursion you do is implemented so its adaptive - so once a subgraph gets small enough w.r.t screen size you stop traversing.

Robert.

ToolTech
03-21-2003, 06:02 AM
exactly..





// ---------- Recursive ---------------------------------------------

GZ_GRAPH_EXPORT gzVoid setMaxDepth( gzULong depth );
GZ_GRAPH_EXPORT gzVoid setTransform(const gzMatrix4 &transform);
GZ_GRAPH_EXPORT gzVoid setMaxDepthNode(gzNode *node);
GZ_GRAPH_EXPORT gzVoid useDistanceDepth(gzBool on);
GZ_GRAPH_EXPORT gzVoid setDistanceDepthEquation(gzReal farDistance=100,gzReal speed=1);



Works just like LOD levels