本文整理汇总了C++中osg::NodeRecPtr类的典型用法代码示例。如果您正苦于以下问题:C++ NodeRecPtr类的具体用法?C++ NodeRecPtr怎么用?C++ NodeRecPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeRecPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createScene
OSG::NodeTransitPtr createScene(OSG::Window *win)
{
OSG::NodeRecPtr rootN = OSG::makeNodeFor(OSG::Group::create());
// Create ground:
OSG::NodeUnrecPtr groundN = OSG::makePlane(25,25,1,1);
OSG::Matrix m;
OSG::Quaternion q;
q.setValueAsAxisDeg(OSG::Vec3f(1,0,0), -90);
m.setRotate(q);
OSG::TransformUnrecPtr groundTransC = OSG::Transform::create();
groundTransC->setMatrix(m);
OSG::NodeUnrecPtr groundTransN = OSG::makeNodeFor(groundTransC);
groundTransN->addChild(groundN);
rootN->addChild(groundTransN);
// Set ground material:
OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create();
mat->setDiffuse(OSG::Color3f(0.8,0.8,0.8));
dynamic_cast<OSG::Geometry*>(groundN->getCore())->setMaterial(mat);
// // Create figure:
// OSG::NodeUnrecPtr figure1N =
// OSG::SceneFileHandler::the()->read("../Models/Figure.obj");
// G.figure1TransC = OSG::Transform::create();
// OSG::NodeUnrecPtr trans1N = OSG::makeNodeFor(G.figure1TransC);
// trans1N->addChild(figure1N);
// rootN->addChild(trans1N);
OSG::NodeUnrecPtr figureModelA =
OSG::SceneFileHandler::the()->read("../assets/Figure.obj");
BoardGame::Figure* figureA = new BoardGame::Figure();
figureA->setModel(figureModelA);
rootN->addChild(figureA->getRoot());
OSG::NodeUnrecPtr figureModelB =
OSG::SceneFileHandler::the()->read("../assets/Figure.obj");
BoardGame::Figure* figureB = new BoardGame::Figure();
figureB->setModel(figureModelB);
rootN->addChild(figureB->getRoot());
G.selectedNode = figureModelA;
return(OSG::NodeTransitPtr(rootN));
}
示例2: createScenegraph
OSG::NodeRecPtr createScenegraph(void)
{
//create sun, planet & moon geometry
OSG::GeometryRecPtr sun = OSG::makeSphereGeo(3, 6);
OSG::NodeRecPtr planet = OSG::makeSphere (3, 3);
OSG::NodeRecPtr moon = OSG::makeSphere (2, 1);
//the root node will be the sun
OSG::NodeRecPtr root = OSG::Node::create();
root->setCore(sun);
OSG::NodeRecPtr planetTransformNode = OSG::Node::create();
OSG::NodeRecPtr moonTransformNode = OSG::Node::create();
// these were declared globally
planetTransform = OSG::Transform::create();
moonTransform = OSG::Transform::create();
// Now we need to fill it with live
// We want to have the planet some distance away from the sun,
// but initial with no rotation. The same aplies to the moon
OSG::Matrix m,n;
m.setIdentity();
n.setIdentity();
m.setTranslate(20, 0, 0);
n.setTranslate( 8, 0, 0);
planetTransform->setMatrix(m);
moonTransform ->setMatrix(n);
//Insert the cores into the apropiate nodes and add the geometry
planetTransformNode->setCore (planetTransform);
planetTransformNode->addChild(planet );
moonTransformNode->setCore (moonTransform);
moonTransformNode->addChild(moon );
//add the planet to the sun
root->addChild(planetTransformNode);
root->addChild(moonTransformNode );
//now we are done
return OSG::NodeTransitPtr(root);
}
示例3: main
int main( int argc, char **argv )
{
OSG::osgInit(argc,argv);
QApplication::setColorSpec( QApplication::CustomColor );
QApplication a( argc, argv );
if ( !QGLFormat::hasOpenGL() ) {
qWarning( "This system has no OpenGL support. Exiting." );
return -1;
}
OpenSGWidget w(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba |
QGL::DirectRendering));
// create the scene
OSG::NodeRecPtr scene;
if(argc > 1)
{
scene = OSG::Node::create();
OSG::GroupRecPtr g = OSG::Group::create();
scene->setCore(g);
for(OSG::UInt16 i = 1; i < argc; ++i)
scene->addChild(OSG::SceneFileHandler::the()->read(argv[i]));
}
else
{
scene = OSG::makeTorus(.5, 3, 16, 16);
}
w.getManager()->setRoot(scene);
w.getManager()->showAll();
w.show();
return a.exec();
}
示例4: main
int main( int argc, char **argv )
{
// OSG init
OSG::osgInit(argc, argv);
OSG::SceneFileHandler::the()->print();
// create the graph
// beacon for camera and light
OSG::NodeRecPtr b1n = OSG::Node::create();
OSG::GroupRecPtr b1 = OSG::Group::create();
b1n->setCore( b1 );
// transformation
OSG::NodeRecPtr t1n = OSG::Node::create();
OSG::TransformRecPtr t1 = OSG::Transform::create();
t1n->setCore( t1 );
t1n->addChild( b1n );
cam_trans = t1;
// light
OSG::NodeRecPtr dlight = OSG::Node::create();
OSG::DirectionalLightRecPtr dl = OSG::DirectionalLight::create();
dlight->setCore( dl );
dl->setAmbient( .3, .3, .3, 1 );
dl->setDiffuse( 1, 1, 1, 1 );
dl->setDirection(0,0,1);
dl->setBeacon( b1n);
// root
root = OSG::Node::create();
OSG::GroupRecPtr gr1 = OSG::Group::create();
root->setCore( gr1 );
root->addChild( t1n );
root->addChild( dlight );
// Load the file
OSG::NodeRecPtr file = NULL;
if ( argc > 1 )
file = OSG::SceneFileHandler::the()->read(argv[1]);
if ( file == NULL )
{
std::cerr << "Couldn't load file, ignoring" << std::endl;
file = OSG::makeTorus( .5, 2, 16, 16 );
}
OSG::commitChanges();
file->updateVolume();
OSG::Vec3f min,max;
file->getVolume().getBounds( min, max );
std::cout << "Volume: from " << min << " to " << max << std::endl;
dlight->addChild( file );
std::cerr << "Tree: " << std::endl;
root->dump();
// Camera
OSG::PerspectiveCameraRecPtr cam = OSG::PerspectiveCamera::create();
cam->setBeacon( b1n );
cam->setFov( OSG::osgDegree2Rad( 60 ) );
cam->setNear( 1 );
cam->setFar( 4000 );
// Background
OSG::SolidBackgroundRecPtr bkgnd = OSG::SolidBackground::create();
bkgnd->setColor( OSG::Color3f( 0,0,1 ) );
// Viewport
vp = OSG::Viewport::create();
vp->setCamera( cam );
vp->setBackground( bkgnd );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
// Action
ract = OSG::RenderAction::create();
// QT init
QApplication::setColorSpec( QApplication::CustomColor );
a = new QApplication( argc, argv );
if ( !QGLFormat::hasOpenGL() )
{
qWarning( "This system has no OpenGL support. Exiting." );
return -1;
}
OSG::Vec3f pos( 0, 0, max[2] + ( max[2] - min[2] ) * 1.5 );
//.........这里部分代码省略.........
示例5: main
int main (int argc, char **argv)
{
OSG::osgInit(argc, argv);
Foo foo;
OSG::Thread::getCurrentChangeList()->clear();
OSG::NodeRecPtr pNode = OSG::Node::create();
OSG::ChangedFunctor objCB = boost::bind(&Foo::testCB, &foo, _1, _2, _3);
pNode->addChangedFunctor(testCB, "");
pNode->addChangedFunctor(objCB, "");
pNode->setTravMask(0);
fprintf(stderr, "Test 1\n");
OSG::Thread::getCurrentChangeList()->commitChanges();
pNode->addChangedFunctor(testCB, "");
pNode->setTravMask(1);
fprintf(stderr, "Test 2 \n");
OSG::Thread::getCurrentChangeList()->commitChanges();
pNode->subChangedFunctor(testCB);
pNode->setTravMask(1);
fprintf(stderr, "Test 3\n");
OSG::Thread::getCurrentChangeList()->commitChanges();
pNode->addChangedFunctor(testCB, "");
pNode->setTravMask(1);
fprintf(stderr, "Test 4 \n");
OSG::Thread::getCurrentChangeList()->commitChanges();
pNode->subChangedFunctor(testCB);
pNode->setTravMask(1);
fprintf(stderr, "Test 5\n");
OSG::Thread::getCurrentChangeList()->commitChanges();
fprintf(stderr, "Delete\n");
pNode = NULL;
}
示例6: createScenegraph
OSG::NodeTransitPtr createScenegraph(void)
{
// At first we load all needed models from file
OSG::NodeRecPtr w_high =
OSG::SceneFileHandler::the()->read("Data/woman_high.wrl");
OSG::NodeRecPtr w_medium =
OSG::SceneFileHandler::the()->read("Data/woman_medium.wrl");
OSG::NodeRecPtr w_low =
OSG::SceneFileHandler::the()->read("Data/woman_low.wrl");
// we check the result
if((w_high == NULL) || (w_medium == NULL)|| (w_low == NULL))
{
std::cout << "It was not possible to load all needed models from file"
<< std::endl;
return OSG::NodeTransitPtr();
}
// now the LOD core
OSG::DistanceLODRecPtr lod = OSG::DistanceLOD::create();
lod->editSFCenter()->setValue(OSG::Pnt3f(0,0,0));
lod->editMFRange()->push_back(200);
lod->editMFRange()->push_back(500);
// the node containing the LOD core. The three models will be
// added as its children
OSG::NodeRecPtr lodNode = OSG::Node::create();
lodNode->setCore(lod);
lodNode->addChild(w_high);
lodNode->addChild(w_medium);
lodNode->addChild(w_low);
// create the node with switch core ********************
OSG::SwitchRecPtr sw = OSG::Switch::create();
//Notice: the first choice is 0
sw->setChoice(0);
OSG::NodeRecPtr switchNode = OSG::Node::create();
switchNode->setCore(sw);
switchNode->addChild(lodNode);
//end switch creation **********************************
OSG::NodeRecPtr root = OSG::Node::create();
root->setCore(OSG::Group::create());
root->addChild(switchNode);
// we know want to extract the mesh geometry out of the graph
// it is sufficent to pass the model only as root for searching
OSG::NodeRecPtr womanGeometry = checkName(w_high);
OSG::GeometryRecPtr geo =
dynamic_cast<OSG::Geometry *>(womanGeometry->getCore());
//new node with "old" geometry core referenced
OSG::NodeRecPtr woman = OSG::Node::create();
woman->setCore(geo);
//translate it a bit to see both women
OSG::NodeRecPtr womanTrans = OSG::Node ::create();
OSG::TransformRecPtr t = OSG::Transform::create();
OSG::Matrix m;
m.setIdentity();
m.setTranslate(OSG::Vec3f(0,0,200));
t->setMatrix(m);
womanTrans->setCore(t);
womanTrans->addChild(woman);
//add it to the root
root->addChild(womanTrans);
return OSG::NodeTransitPtr(root);
}
示例7: updateScene
void updateScene(const std::string &filename, OSG::Image::PixelFormat compressTo = OSG::Image::OSG_INVALID_PF)
{
// Try to create the new image
OSG::ImageRecPtr imagePtr =
OSG::ImageFileHandler::the()->read(filename.c_str());
if (imagePtr == NULL)
return;
if(compressTo != OSG::Image::OSG_INVALID_PF)
{
imagePtr->reformat(compressTo);
}
// Update information on the screen
OSG::StatStringElem *statElem =
statfg->editCollector()->getElem(textureFormatDesc);
switch (imagePtr->getPixelFormat())
{
case OSG::Image::OSG_A_PF:
statElem->set("OSG_A_PF");
break;
case OSG::Image::OSG_I_PF:
statElem->set("OSG_I_PF");
break;
case OSG::Image::OSG_L_PF:
statElem->set("OSG_L_PF");
break;
case OSG::Image::OSG_LA_PF:
statElem->set("OSG_LA_PF");
break;
case OSG::Image::OSG_RGB_PF:
statElem->set("OSG_RGB_PF");
break;
case OSG::Image::OSG_RGBA_PF:
statElem->set("OSG_RGBA_PF");
break;
case OSG::Image::OSG_BGR_PF:
statElem->set("OSG_BGRA_PF");
break;
case OSG::Image::OSG_BGRA_PF:
statElem->set("OSG_BGRA_PF");
break;
case OSG::Image::OSG_RGB_DXT1:
statElem->set("OSG_RGB_DXT1");
break;
case OSG::Image::OSG_RGBA_DXT1:
statElem->set("OSG_RGBA_DXT1");
break;
case OSG::Image::OSG_RGBA_DXT3:
statElem->set("OSG_RGBA_DXT3");
break;
case OSG::Image::OSG_RGBA_DXT5:
statElem->set("OSG_RGBA_DXT5");
break;
default:
statElem->set("???");
break;
}
statElem = statfg->editCollector()->getElem(textureDataTypeDesc);
switch (imagePtr->getDataType())
{
case OSG::Image::OSG_UINT8_IMAGEDATA:
statElem->set("OSG_UINT8_IMAGEDATA");
break;
case OSG::Image::OSG_UINT16_IMAGEDATA:
statElem->set("OSG_UINT16_IMAGEDATA");
break;
case OSG::Image::OSG_UINT32_IMAGEDATA:
statElem->set("OSG_UINT32_IMAGEDATA");
break;
case OSG::Image::OSG_FLOAT16_IMAGEDATA:
statElem->set("OSG_FLOAT16_IMAGEDATA");
break;
case OSG::Image::OSG_FLOAT32_IMAGEDATA:
statElem->set("OSG_FLOAT32_IMAGEDATA");
break;
case OSG::Image::OSG_INT16_IMAGEDATA:
statElem->set("OSG_INT16_IMAGEDATA");
break;
case OSG::Image::OSG_INT32_IMAGEDATA:
statElem->set("OSG_INT32_IMAGEDATA");
break;
default:
statElem->set("???");
break;
}
ostringstream os;
os << imagePtr->getWidth() << 'x' << imagePtr->getHeight() << 'x' << imagePtr->getDepth();
statfg->editCollector()->getElem(textureSizeDesc)->set(os.str());
statfg->editCollector()->getElem(textureDimensionDesc)->set(imagePtr->getDimension());
statfg->editCollector()->getElem(textureBPPDesc)->set(imagePtr->getBpp());
statfg->editCollector()->getElem(textureMipMapCountDesc)->set(imagePtr->getMipMapCount());
statfg->editCollector()->getElem(textureFrameCountDesc)->set(imagePtr->getFrameCount());
// Put it all together into a Geometry NodeCore.
OSG::GeometryRecPtr geo = OSG::makePlaneGeo(imagePtr->getWidth(), imagePtr->getHeight(), 1, 1);
OSG::NodeRecPtr imageNode = OSG::Node::create();
imageNode->setCore(geo);
//.........这里部分代码省略.........
示例8: doMain
// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
std::cout << "start a cluster server with './testClusterServer -w pipe0'\n"
"press 'c' to connect to the servers.\n"
"press 'd' to disconnect from the servers.\n"
"press 'n' to delete current scene.\n"
"press 't' to create a torus.\n"
"press 'l' to load scene 'tie.wrl'.\n"
<< std::endl;
// OSG init
OSG::osgInit(argc,argv);
OSG::VTKPolyDataMapper::getClassType().dump();
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
_client_win = OSG::GLUTWindow::create();
_client_win->setGlutId(winid);
_client_win->init();
_client_win->setSize(300,300);
for(OSG::Int32 i=0;i<argc-1;++i)
{
if(argv[i+1] != NULL)
_pipenames.push_back(argv[i+1]);
}
if(_pipenames.empty())
_pipenames.push_back("pipe0");
_root = OSG::Node::create();
_root->setCore(OSG::Group::create());
// create default scene
// NodePtr scene = makeTorus(.5, 2, 16, 16);
OSG::NodeUnrecPtr scene = initVTK();
_root->addChild(scene);
// create the SimpleSceneManager helper
_mgr = OSG::SimpleSceneManager::create();
// tell the manager what to manage
_mgr->setWindow(_client_win );
_mgr->setRoot (_root);
// show the whole scene
_mgr->showAll();
return 0;
}
示例9: keyboard
// react to keys
void keyboard(unsigned char k, int x, int y)
{
switch(k)
{
case 27:
{
delete _mgr;
_client_win = NULL;
_cluster_win = NULL;
_root = NULL;
OSG::osgExit();
exit(0);
}
case 'n':
while(_root->getNChildren() > 0)
_root->subChild(_root->getChild(0));
glutPostRedisplay();
break;
case 'l':
{
OSG::NodeUnrecPtr scene =
OSG::SceneFileHandler::the()->read("tie.wrl", NULL);
if(scene != NULL)
{
_root->addChild(scene);
_mgr->showAll();
glutPostRedisplay();
}
}
break;
case 't':
{
OSG::NodeUnrecPtr scene = OSG::makeTorus(.5, 2, 16, 16);
_root->addChild(scene);
_mgr->showAll();
glutPostRedisplay();
}
break;
case 'c':
connectCluster();
break;
case 'd':
disconnectCluster();
break;
}
}
示例10: doMain
// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
OSG::GLUTWindowRecPtr gwin= OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// put the geometry core into a node
scene = OSG::Node::create();
OSG::GroupRecPtr groupPtr = OSG::Group::create();
scene->setCore(groupPtr);
statfg = OSG::SimpleStatisticsForeground::create();
statfg->setSize(25);
statfg->setColor(OSG::Color4f(0,1,0,0.9f));
statfg->addElement(textureFormatDesc, "Pixel Format: %s");
statfg->addElement(textureDataTypeDesc, "Data Type: %s");
statfg->addElement(textureSizeDesc, "Texture Size: %s");
statfg->addElement(textureDimensionDesc, "Dimension: %i");
statfg->addElement(textureBPPDesc, "BPP: %i");
statfg->addElement(textureMipMapCountDesc, "MipMapCount: %i");
statfg->addElement(textureFrameCountDesc, "FrameCount: %i");
// Create the background
OSG::SolidBackgroundRecPtr bg = OSG::SolidBackground::create();
bg->setColor(OSG::Color3f(0.1f, 0.1f, 0.5f));
if (argc < 2)
{
std::cerr << "Usage: testImageLoader <filename>" << std::endl;
return EXIT_FAILURE;
}
updateScene(argv[1]);
szFilename = argv[1];
// create the SimpleSceneManager helper
mgr = new OSG::SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
// add the statistics forground
gwin->getPort(0)->addForeground(statfg);
gwin->getPort(0)->setBackground(bg);
return 0;
}
示例11: display
void display(void)
{
OSG::Real32 time = glutGet(GLUT_ELAPSED_TIME);
updateMesh(time);
// we extract the core out of the root node
// as we now this is a geometry node
OSG::GeometryRecPtr geo = dynamic_cast<OSG::Geometry *>(scene->getCore());
//now modify it's content
// first we need a pointer to the position data field
OSG::GeoPnt3fPropertyRecPtr pos =
dynamic_cast<OSG::GeoPnt3fProperty *>(geo->getPositions());
//get the data field the pointer is pointing at
OSG::GeoPnt3fProperty::StoredFieldType *posfield = pos->editFieldPtr();
//get some iterators
OSG::GeoPnt3fProperty::StoredFieldType::iterator last, it;
// set the iterator to the first data
it = posfield->begin();
//now simply run over all entires in the array
for (int x = 0; x < N; x++)
{
for (int z = 0; z < N; z++)
{
(*it) = OSG::Pnt3f(x, wMesh[x][z], z);
it++;
}
}
mgr->redraw();
}
示例12: display
void display(void)
{
OSG::Real32 time = glutGet(GLUT_ELAPSED_TIME);
updateMesh(time);
// we extract the core out of the root node
// as we now this is a geometry node
OSG::GeometryRecPtr geo = dynamic_cast<OSG::Geometry *>(scene->getCore());
//now modify it's content
// first we need a pointer to the position data field
OSG::GeoPnt3fPropertyRecPtr pos =
dynamic_cast<OSG::GeoPnt3fProperty *>(geo->getPositions());
//this loop is similar to when we generted the data during createScenegraph()
// here they all come
for (int x = 0; x < N; x++)
for (int z = 0; z < N; z++)
pos->setValue(OSG::Pnt3f(x, wMesh[x][z], z), N * x + z);
mgr->redraw();
}
示例13: main
int main (int argc, char **argv)
{
doMain(argc, argv);
fprintf(stderr, "Create hdrroot %p %d %d \n",
hdrroot.get(),
hdrroot->getRefCount(),
hdrroot->getWeakRefCount());
fprintf(stderr, "Create root %p %d %d \n",
root.get(),
root->getRefCount(),
root->getWeakRefCount());
// run...
glutMainLoop();
return 0;
}
示例14: init
void init(std::vector<std::string> &filenames)
{
size_t i;
OSG::DirectionalLightUnrecPtr dl;
OSG::Real32 x,y,z;
OSG::BoxVolume volume;
OSG::Vec3f min,max;
OSG::Vec3f size;
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
// GLint twoSide = 1;
// glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE,&twoSide);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
// create the graph
// beacon for camera and light
OSG::NodeUnrecPtr b1n = OSG::Node::create();
OSG::GroupUnrecPtr b1 = OSG::Group::create();
b1n->setCore( b1 );
// transformation
OSG::NodeUnrecPtr t1n = OSG::Node::create();
OSG::TransformUnrecPtr t1 = OSG::Transform::create();
t1n->setCore( t1 );
t1n->addChild( b1n );
cam_trans = t1;
// light
OSG::NodeUnrecPtr dlight = OSG::Node::create();
dl = OSG::DirectionalLight::create();
dlight->setCore( dl );
dl->setAmbient( .3f, .3f, .3f, 1 );
dl->setDiffuse( 1, 1, 1, 1 );
dl->setDirection(0,0,1);
dl->setBeacon( b1n);
// root
root = OSG::Node::create();
OSG::GroupUnrecPtr gr1 = OSG::Group::create();
root->setCore( gr1 );
root->addChild( t1n );
root->addChild( dlight );
// Load the file
OSG::NodeUnrecPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
OSG::NodeUnrecPtr file;
for(i=0;i<filenames.size();i++)
{
file = OSG::SceneFileHandler::the()->read(filenames[i].c_str(),0);
if(file != NULL)
scene->addChild(file);
else
std::cerr << "Couldn't load file, ignoring " << filenames[i] << std::endl;
}
if ( filenames.size()==0 )
{
file = OSG::makeTorus( .5, 2, 16, 16 );
scene->addChild(file);
// scene->addChild(makeBox(.6,.6,.6,5,5,5));
}
prepareSceneGraph(scene);
OSG::Thread::getCurrentChangeList()->commitChanges();
scene->invalidateVolume();
scene->updateVolume();
volume=scene->getVolume();
volume.getBounds(min,max);
size = max-min;
if(ca>0)
{
if(cb==-1)
cb=ca;
if(cc==-1)
cc=cb;
OSG::NodeUnrecPtr node;
OSG::NodeUnrecPtr geoNode;
OSG::TransformUnrecPtr trans;
for(x=-ca/2.0 ; x<ca/2.0 ; x++)
for(y=-cb/2.0 ; y<cb/2.0 ; y++)
for(z=-cc/2.0 ; z<cc/2.0 ; z++)
{
trans=OSG::Transform::create();
node=OSG::Node::create();
node->setCore(trans);
//.........这里部分代码省略.........
示例15: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
printf("Usage: testCGShader [normal map filename]\n");
const char *normal_map_img_name = "opensg_logoDOT3.png";
OSG::Color4f tmp;
if( argc > 1 )
normal_map_img_name = argv[1];
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->setSize( 800, 800 );
gwin->init();
// Create the shader material
// Read the image for the normal texture
OSG::ImageUnrecPtr normal_map_img = OSG::Image::create();
if(!normal_map_img->read(normal_map_img_name))
{
fprintf(stderr, "Couldn't read normalmap texture '%s'!\n", normal_map_img_name);
return 1;
}
OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();
OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();
matc->setAmbient(OSG::Color4f(0.1, 0.1, 0.1, 1.0));
matc->setDiffuse(OSG::Color4f(0.3, 0.3, 0.3, 1.0));
matc->setSpecular(OSG::Color4f(0.8, 0.8, 0.8, 1.0));
matc->setShininess(100);
matc->setLit(true);
OSG::SHLChunkUnrecPtr shl = OSG::SHLChunk::create();
shl->setVertexProgram(_vp_program);
shl->setFragmentProgram(_fp_program);
OSG::TextureObjChunkUnrecPtr tex_normal_map =
OSG::TextureObjChunk::create();
OSG::TextureEnvChunkUnrecPtr tex_normal_map_env =
OSG::TextureEnvChunk::create();
tex_normal_map->setImage(normal_map_img);
tex_normal_map->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
tex_normal_map->setMagFilter(GL_LINEAR);
tex_normal_map->setWrapS(GL_REPEAT);
tex_normal_map->setWrapT(GL_REPEAT);
tex_normal_map_env->setEnvMode(GL_MODULATE);
//cmat->addChunk(matc);
cmat->addChunk(shl);
cmat->addChunk(tex_normal_map);
cmat->addChunk(tex_normal_map_env);
// create root node
_scene = OSG::Node::create();
// create geometry
//GeometryPtr geo = makeLatLongSphereGeo (100, 100, 1.0);
OSG::GeometryUnrecPtr geo = OSG::makePlaneGeo(1.0, 1.0, 100, 100);
geo->setMaterial(cmat);
OSG::NodeUnrecPtr torus = OSG::Node::create();
torus->setCore(geo);
// add torus to scene
OSG::GroupUnrecPtr group = OSG::Group::create();
_scene->setCore(group);
_scene->addChild(torus);
// create the SimpleSceneManager helper
_mgr = new OSG::SimpleSceneManager;
// tell the manager what to manage
_mgr->setWindow(gwin );
_mgr->setRoot(_scene);
/*
// create point headlight
_mgr->turnHeadlightOff();
NodePtr headlight = _mgr->getHighlight();
PointLightPtr light = PointLight::create();
beginEditCP(light);
light->setAmbient (.3, .3, .3, 1);
light->setDiffuse ( 1, 1, 1, 1);
light->setSpecular ( 1, 1, 1, 1);
//.........这里部分代码省略.........