本文整理汇总了C++中osg::NodePtr::setCore方法的典型用法代码示例。如果您正苦于以下问题:C++ NodePtr::setCore方法的具体用法?C++ NodePtr::setCore怎么用?C++ NodePtr::setCore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::NodePtr
的用法示例。
在下文中一共展示了NodePtr::setCore方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makePolygon
OSG::NodePtr makePolygon(double pntData[][3], int numPoints) {
OSG::GeometryPtr geoPtr = OSG::Geometry::create();
OSG::NodePtr nodePtr = OSG::Node::create();
GeoPositions3fPtr pnts = GeoPositions3f::create();
GeoNormals3fPtr norms = GeoNormals3f::create();
GeoTexCoords2fPtr tex = GeoTexCoords2f::create();
GeoIndicesUI32Ptr indices = GeoIndicesUI32::create();
GeoPLengthsUI32Ptr lens = GeoPLengthsUI32::create();
GeoPTypesUI8Ptr types = GeoPTypesUI8::create();
//Set up the properties according to the geometry defined above
beginEditCP(pnts);
beginEditCP(norms);
for(int i = 0; i < numPoints; i++)
{
pnts->push_back(Pnt3f(pntData[i][0],
pntData[i][1],
pntData[i][2]));
indices->push_back(2*i);
norms->push_back(Vec3f(0.0, 0.0, pntData[i][2]));
indices->push_back(2*i + 1);
}
endEditCP(pnts);
endEditCP(norms);
beginEditCP(types);
beginEditCP(lens);
types->push_back(GL_POLYGON);
lens->push_back(numPoints);
endEditCP(types);
endEditCP(lens);
beginEditCP(geoPtr);
geoPtr->setMaterial(getDefaultMaterial());
geoPtr->setPositions(pnts);
geoPtr->setNormals(norms);
geoPtr->setIndices(indices);
geoPtr->editMFIndexMapping()->push_back(Geometry::MapPosition |
Geometry::MapNormal);
geoPtr->setTypes(types);
geoPtr->setLengths(lens);
endEditCP(geoPtr);
nodePtr->setCore(geoPtr);
return nodePtr;
}
示例2: main
// No arguments: batch convert all vt* files
// switch argument: batch convert all vt* files into one osb file with a switch
// file argument: convert only the specified file
int main (int argc, char const* argv[])
{
vector<string> filenames;
bool useSwitch = false;
if (argc == 2)
{
if (string(argv[1]).find("switch") != string::npos)
useSwitch = true;
else
filenames.push_back(string(argv[1]));
}
if (useSwitch || filenames.empty())
{
const boost::regex e(".+\\.vt[a-z]");
directory_iterator end;
for (directory_iterator it("./"); it != end; ++it)
{
string curFile = it->path().filename().string();
if (regex_match(curFile, e))
filenames.push_back(curFile);
}
}
OSG::osgInit(0, NULL);
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
OSG::NodePtr switchNode = OSG::Node::create();
OSG::SwitchPtr switchCore = OSG::Switch::create();
beginEditCP(switchCore);
switchCore->setChoice(0);
endEditCP(switchCore);
beginEditCP(switchNode);
switchNode->setCore(switchCore);
endEditCP(switchNode);
for (vector<string>::const_iterator it = filenames.begin(); it != filenames.end(); ++it)
{
string filename(*it);
cout << "Opening file " << filename << " ... " << endl << flush;
string fileExt = getFileExt(filename);
vtkXMLDataReader* reader = NULL;
vtkGenericDataObjectReader* oldStyleReader = NULL;
if (fileExt.find("vti") != string::npos)
{
reader = vtkXMLImageDataReader::New();
vtkSmartPointer<vtkImageDataGeometryFilter> geoFilter =
vtkSmartPointer<vtkImageDataGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
if (fileExt.find("vtr") != string::npos)
{
reader = vtkXMLRectilinearGridReader::New();
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
else if (fileExt.find("vts") != string::npos)
{
reader = vtkXMLStructuredGridReader::New();
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
else if (fileExt.find("vtp") != string::npos)
{
reader = vtkXMLPolyDataReader::New();
mapper->SetInputConnection(reader->GetOutputPort());
}
else if (fileExt.find("vtu") != string::npos)
{
reader = vtkXMLUnstructuredGridReader::New();
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(reader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
else if (fileExt.find("vtk") != string::npos)
{
oldStyleReader = vtkGenericDataObjectReader::New();
oldStyleReader->SetFileName(filename.c_str());
oldStyleReader->Update();
if(oldStyleReader->IsFilePolyData())
mapper->SetInputConnection(oldStyleReader->GetOutputPort());
else
{
vtkSmartPointer<vtkGeometryFilter> geoFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
geoFilter->SetInputConnection(oldStyleReader->GetOutputPort());
mapper->SetInputConnection(geoFilter->GetOutputPort());
}
}
else
//.........这里部分代码省略.........
示例3: main
int main( int argc, char *argv[] )
{
// parse command line options
parsecommandline( argc, argv );
// OSG init
osg::osgLog().setLogLevel(osg::LOG_WARNING);
osg::osgInit(argc, argv);
// disable display lists
osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
if ( pGeoProto != osg::NullFC )
pGeoProto->setDlistCache(false);
// create the graph
osg::NodePtr node;
// root
root = osg::Node::create();
beginEditCP(root);
root->setCore( osg::Group::create() );
// beacon for camera and light
osg::NodePtr beacon;
beacon = osg::Node::create();
beginEditCP(beacon);
beacon->setCore( osg::Group::create() );
endEditCP(beacon);
// light
light_node = osg::Node::create();
osg::DirectionalLightPtr light = osg::DirectionalLight::create();
beginEditCP( light_node );
light_node->setCore( light );
endEditCP( light_node );
root->addChild( light_node );
beginEditCP(light);
light->setAmbient( .3, .3, .3, 1 );
light->setDiffuse( 1, 1, 1, 1 );
light->setDirection(0,0,1);
light->setBeacon( beacon );
endEditCP(light);
// transformation, parent of beacon
node = osg::Node::create();
cam_trans = osg::Transform::create();
beginEditCP(node);
node->setCore( cam_trans );
node->addChild( beacon );
endEditCP(node);
root->addChild( node );
// finish scene graph
endEditCP(root);
// Camera
osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
cam->setBeacon( beacon );
cam->setFov( 50 );
cam->setNear( 0.1 );
cam->setFar( 10000 );
// Background
osg::SolidBackgroundPtr background = osg::SolidBackground::create();
// Viewport
osg::ViewportPtr vp = osg::Viewport::create();
vp->setCamera( cam );
vp->setBackground( background );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
if ( with_window )
{
// GLUT init
glutInitWindowSize( 400, 400 ); // before glutInit so user can
glutInitWindowPosition( 100, 100 ); // override with comannd line args
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("Polygon Intersection Check Test");
glutKeyboardFunc(key);
glutVisibilityFunc(vis);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(display);
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
// Window
osg::GLUTWindowPtr gwin;
GLint glvp[4];
glGetIntegerv( GL_VIEWPORT, glvp );
gwin = osg::GLUTWindow::create();
//.........这里部分代码省略.........
示例4: createChildVisualEntity
void SimulationEngine::createChildVisualEntity(osg::NodePtr parentNode,
/*osg::TransformPtr trans,*/ const opal::ShapeData* data, const std::string& name,
const std::string& materialName)
{
// Create an Ogre SceneNode for the Entity.
osg::Matrix m;
opal::Point3r offsetPos = data->offset.getPosition();
//Ogre::Vector3 translationOffset(offsetPos[0], offsetPos[1],
//offsetPos[2]);
opal::Quaternion offsetQuat = data->offset.getQuaternion();
//Ogre::Quaternion rotationOffset;
//rotationOffset.x = offsetQuat.x;
//rotationOffset.y = offsetQuat.y;
//rotationOffset.z = offsetQuat.z;
//rotationOffset.w = offsetQuat.w;
//Ogre::SceneNode* newChildNode = NULL;
//Ogre::Entity* e = NULL;
// OSG covention: we need one new node and transformation
osg::NodePtr newChildNode; //= osg::Node::create();
osg::TransformPtr newTransCore = osg::Transform::create();
osg::beginEditCP(newTransCore);
m.setIdentity();
m.setTranslate(
(osg::Real32)offsetPos[0],
(osg::Real32)offsetPos[1],
(osg::Real32)offsetPos[2]);
m.setRotate(
osg::Quaternion(
osg::Vec3f(
(osg::Real32)offsetQuat[1],
(osg::Real32)offsetQuat[2],
(osg::Real32)offsetQuat[3]),
(osg::Real32)offsetQuat[0]));
newTransCore->setMatrix(m);
osg::endEditCP(newTransCore);
switch(data->getType())
{
case opal::BOX_SHAPE:
{
//newChildNode = parentNode->createChildSceneNode(name,
//translationOffset, rotationOffset);
// Scale the object according to the given dimensions.
opal::Vec3r boxDim = static_cast<const opal::BoxShapeData*>
(data)->dimensions;
//Ogre::Vector3 dimensions(boxDim[0], boxDim[1], boxDim[2]);
//newChildNode->scale(dimensions[0], dimensions[1],
//dimensions[2]);
//create the geometry which we will assign a texture to
newChildNode = osg::makeBox((osg::Real32)boxDim[0],
(osg::Real32)boxDim[1],
(osg::Real32)boxDim[2],1,1,1);
// Create an Ogre Entity using a cube mesh. This mesh must be
// stored as a box with dimensions 1x1x1.
//e = mOgreSceneMgr->createEntity(name, "cube.mesh");
//e->setMaterialName(materialName);
// Keep the normals normalized even after scaling.
//e->setNormaliseNormals(true);
// Attach the Entity to the SceneNode.
//newChildNode->attachObject(e);
//osg::beginEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
osg::beginEditCP(parentNode);
parentNode->setCore(newTransCore);
parentNode->addChild(newChildNode);
osg::endEditCP(parentNode);
//osg::endEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
break;
}
case opal::SPHERE_SHAPE:
{
//newChildNode = parentNode->createChildSceneNode(name,
//translationOffset, rotationOffset);
// Scale the object according to the given dimensions.
//Ogre::Real radius = static_cast<const opal::SphereShapeData*>
//(data)->radius;
//newChildNode->scale(radius, radius, radius);
opal::real radius = static_cast<const opal::SphereShapeData*>
(data)->radius;
newChildNode = osg::makeSphere(3, (osg::Real32)radius);
// Create an Ogre Entity using a sphere mesh. This mesh must be
//.........这里部分代码省略.........
示例5: main
int main( int argc, char *argv[] )
{
// OSG init
osg::osgLog().setLogLevel(osg::LOG_WARNING);
osg::osgInit(argc, argv);
// parse command line options
parsecommandline( argc, argv );
// disable display lists
osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
if ( pGeoProto != osg::NullFC )
pGeoProto->setDlistCache(false);
// create the graph
osg::NodePtr node;
// root
root = osg::Node::create();
beginEditCP(root);
root->setCore( osg::Group::create() );
// beacon for camera and light
osg::NodePtr beacon;
beacon = osg::Node::create();
beginEditCP(beacon);
beacon->setCore( osg::Group::create() );
endEditCP(beacon);
// light
light_node = osg::Node::create();
osg::DirectionalLightPtr light = osg::DirectionalLight::create();
beginEditCP( light_node );
light_node->setCore( light );
root->addChild( light_node );
beginEditCP(light);
light->setAmbient( .3, .3, .3, 1 );
light->setDiffuse( 1, 1, 1, 1 );
light->setDirection(0,0,1);
light->setBeacon( beacon );
endEditCP(light);
// transformation, parent of beacon
node = osg::Node::create();
cam_trans = osg::Transform::create();
beginEditCP(node);
node->setCore( cam_trans );
node->addChild( beacon );
endEditCP(node);
root->addChild( node );
// Camera
osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
cam->setBeacon( beacon );
cam->setFov( 50 );
cam->setNear( 0.1 );
cam->setFar( 10000 );
// Background
osg::SolidBackgroundPtr background = osg::SolidBackground::create();
if ( White_background )
{
beginEditCP( background );
background->setColor(osg::Color3f(1,1,1));
endEditCP( background );
}
// Viewport
osg::ViewportPtr vp = osg::Viewport::create();
vp->setCamera( cam );
vp->setBackground( background );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
if ( With_window )
{
// GLUT init
glutInitWindowSize( 400, 400 ); // before glutInit so user can
glutInitWindowPosition( 100, 100 ); // override with comannd line args
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("Collision Benchmark");
glutKeyboardFunc(key);
glutVisibilityFunc(vis);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(display);
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
// Window
osg::GLUTWindowPtr gwin;
//.........这里部分代码省略.........
示例6: init
CameraPtr Camera::init()
{
// Create a transform to contain the location and orientation of the camera.
mTransform = OSG::Transform::create();
OSG::NodePtr beacon = OSG::Node::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor be(beacon, OSG::Node::CoreFieldMask);
#endif
beacon->setCore(mTransform);
mLeftTexture = tex_chunk_t::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor lte(mLeftTexture);
mLeftTexture->setEnvMode(GL_MODULATE);
#else
mLeftTexEnv = OSG::TextureEnvChunk::create();
mLeftTexEnv->setEnvMode(GL_MODULATE);
#endif
mRightTexture = tex_chunk_t::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor rte(mRightTexture);
mRightTexture->setEnvMode(GL_MODULATE);
#else
mRightTexEnv = OSG::TextureEnvChunk::create();
mRightTexEnv->setEnvMode(GL_MODULATE);
#endif
mCurrentTexture = mLeftTexture;
#if OSG_MAJOR_VERSION >= 2
mCurrentTexEnv = mLeftTexEnv;
#endif
// setup camera
mCamera = OSG::PerspectiveCamera::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor ce(mCamera);
#endif
mCamera->setFov(
#if OSG_MAJOR_VERSION < 2
OSG::osgdegree2rad(60.0)
#else
OSG::osgDegree2Rad(60.0)
#endif
);
mCamera->setNear(0.01);
mCamera->setFar(10000);
mCamera->setBeacon(beacon);
mLeftImage = OSG::Image::create();
mRightImage = OSG::Image::create();
OSG::ImagePtr img;
// Set up FBO textures.
img = mLeftImage;
mLeftTexture->setMinFilter(GL_LINEAR);
mLeftTexture->setMagFilter(GL_LINEAR);
mLeftTexture->setTarget(GL_TEXTURE_2D);
mLeftTexture->setInternalFormat(GL_RGBA8);
mLeftTexture->setImage(img);
img = mRightImage;
mRightTexture->setMinFilter(GL_LINEAR);
mRightTexture->setMagFilter(GL_LINEAR);
mRightTexture->setTarget(GL_TEXTURE_2D);
mRightTexture->setInternalFormat(GL_RGBA8);
mRightTexture->setImage(img);
mCurrentImage = mLeftImage;
return shared_from_this();
}
示例7: createScoreBoards
NodePtr createScoreBoards()
{
GeometryPtr geo;
NodePtr bg;
SimpleMaterialPtr m;
ScoreBoard1 = new TextStuff() ;
ScoreBoard2 = new TextStuff() ;
// First get the global group node
OSG::NodePtr scoreBoardsNodePtr = OSG::Node::create();
scoreBoardsNodePtr->setCore(OSG::Group::create());
// Setup text 1
ScoreBoard1->initialize();
ScoreBoard1->updateFace();
ScoreBoard1->updateScore(0,0);
// Setup text 2
ScoreBoard2->initialize();
ScoreBoard2->updateFace();
ScoreBoard2->updateScore(0,0);
////////// 1 /////////
// make its transform
TransformPtr trans1;
NodePtr trans_node1 = makeCoredNode<Transform>(&trans1);
beginEditCP(trans1);
trans1->getMatrix().setTransform(Vec3f(0,4,-10.5),Quaternion( Vec3f(0,1,0),deg2rad(0)));
endEditCP(trans1);
// make geometry
bg = makePlane(9.3, 1, 8,2);
m= SimpleMaterial::create();
beginEditCP(m);
{
m->setAmbient (Color3f(0,0,0));
m->setDiffuse (Color3f(0.0,0.0,0.0));
}
endEditCP (m);
geo = GeometryPtr::dcast(bg->getCore());
beginEditCP(geo);
geo->setMaterial(m);
beginEditCP(geo);
beginEditCP(bg);
bg->addChild(ScoreBoard1->mRootNode);
endEditCP(bg);
beginEditCP(trans_node1);
trans_node1->addChild(bg);
endEditCP(trans_node1);
////////// 2 /////////
// make its transform
TransformPtr trans2;
NodePtr trans_node2 = makeCoredNode<Transform>(&trans2);
beginEditCP(trans2);
trans2->getMatrix().setTransform(Vec3f(0,4,10.5),Quaternion( Vec3f(0,1,0),deg2rad(180)));
endEditCP(trans2);
// make geometry
bg = makePlane(9.3, 1, 8,2);
m = SimpleMaterial::create();
beginEditCP(m);
{
m->setAmbient (Color3f(0,0,0));
m->setDiffuse (Color3f(0.0,0.0,0.0));
}
endEditCP (m);
geo = GeometryPtr::dcast(bg->getCore());
beginEditCP(geo);
geo->setMaterial(m);
beginEditCP(geo);
beginEditCP(bg);
bg->addChild(ScoreBoard2->mRootNode);
endEditCP(bg);
beginEditCP(trans_node2);
trans_node2->addChild(bg);
endEditCP(trans_node2);
beginEditCP(scoreBoardsNodePtr);
scoreBoardsNodePtr->addChild(trans_node1);
scoreBoardsNodePtr->addChild(trans_node2);
endEditCP(scoreBoardsNodePtr);
return scoreBoardsNodePtr;
}