本文整理汇总了C++中PerspectiveCameraPtr::setFov方法的典型用法代码示例。如果您正苦于以下问题:C++ PerspectiveCameraPtr::setFov方法的具体用法?C++ PerspectiveCameraPtr::setFov怎么用?C++ PerspectiveCameraPtr::setFov使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PerspectiveCameraPtr
的用法示例。
在下文中一共展示了PerspectiveCameraPtr::setFov方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
beginEditCP(root);
root->setCore( gr1 );
root->addChild( t1n );
root->addChild( dlight );
endEditCP(root);
// Load the file
NodePtr file = NullFC;
if ( argc > 1 )
file = SceneFileHandler::the().read(argv[1]);
if ( file == NullFC )
{
std::cerr << "Couldn't load file, ignoring" << std::endl;
file = makeTorus( .5, 2, 16, 16 );
}
file->updateVolume();
Vec3f min,max;
file->getVolume().getBounds( min, max );
std::cout << "Volume: from " << min << " to " << max << std::endl;
beginEditCP(dlight);
dlight->addChild( file );
endEditCP(dlight);
std::cerr << "Tree: " << std::endl;
// root->dump();
// Camera
cam = PerspectiveCamera::create();
cam->setBeacon( b1n );
cam->setFov( deg2rad( 90 ) );
cam->setNear( 0.1 );
cam->setFar( 10000 );
// Background
SolidBackgroundPtr bkgnd = SolidBackground::create();
// Foreground
GrabForegroundPtr fgnd = GrabForeground::create();
image = Image::create();
beginEditCP(image);
image->set(Image::OSG_RGB_PF, 1);
endEditCP(image);
fgnd->setImage(image);
// Viewport
vp = Viewport::create();
vp->setCamera( cam );
vp->setBackground( bkgnd );
vp->editMFForegrounds()->push_back( fgnd );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
// Window
std::cout << "GLUT winid: " << winid << std::endl;
GLUTWindowPtr gwin;
GLint glvp[4];
glGetIntegerv( GL_VIEWPORT, glvp );
gwin = GLUTWindow::create();
gwin->setId(winid);
gwin->setSize( glvp[2], glvp[3] );
win = gwin;
win->addPort( vp );
win->init();
// Action
ract = DrawAction::create();
// tball
Vec3f pos( 0, 0, max[2] + ( max[2] - min[2] ) * 1.5 );
tball.setMode( Trackball::OSGObject );
tball.setStartPosition( pos, true );
tball.setSum( true );
tball.setTranslationMode( Trackball::OSGFree );
// run...
glutMainLoop();
return 0;
}
示例2: main
int main(int argc, char **argv)
{
osgInit(argc,argv);
// GLUT init
glutInit(&argc, argv);
bool stereobuffer = false;
bool amberblue = false;
if(argc >= 2 && !strcmp(argv[1],"-s"))
{
stereobuffer = true;
--argc, ++argv;
}
if(argc >= 2 && !strcmp(argv[1],"-a"))
{
amberblue = true;
--argc, ++argv;
}
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE |
(stereobuffer?GLUT_STEREO:0) );
glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
PassiveWindowPtr pwin=PassiveWindow::create();
pwin->init();
// create the scene
NodePtr scene;
if(argc > 1)
{
scene = SceneFileHandler::the().read(argv[1]);
}
else
{
scene = makeBox(2,2,2, 1,1,1);
}
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// create the window and initial camera/viewport
mgr->setWindow(pwin );
// tell the manager what to manage
mgr->setRoot (scene);
// now create the second vp for stereo
ViewportPtr vp = pwin->getPort(0);
PerspectiveCameraPtr cam = PerspectiveCameraPtr::dcast(vp->getCamera());
beginEditCP(cam);
cam->setFov(deg2rad(90));
cam->setAspect(1);
endEditCP (cam);
Navigator *nav = mgr->getNavigator();
nav->setAt(Pnt3f(0,0,0));
nav->setDistance(1.5);
mgr->showAll();
// create the decorators and the second viewport
ViewportPtr vpleft,vpright;
decoleft = ShearedStereoCameraDecorator::create();
decoright = ShearedStereoCameraDecorator::create();
beginEditCP(decoleft);
decoleft->setEyeSeparation(ed);
decoleft->setZeroParallaxDistance(zpp);
decoleft->setLeftEye(true);
decoleft->setDecoratee(cam);
endEditCP (decoleft);
beginEditCP(decoright);
decoright->setEyeSeparation(ed);
decoright->setZeroParallaxDistance(zpp);
decoright->setLeftEye(false);
decoright->setDecoratee(cam);
endEditCP (decoright);
if(amberblue)
{
ColorBufferViewportPtr svpleft = ColorBufferViewport::create();
ColorBufferViewportPtr svpright = ColorBufferViewport::create();
beginEditCP(svpleft);
svpleft->setLeft(0);
svpleft->setRight(1);
svpleft->setBottom(0);
//.........这里部分代码省略.........
示例3: main
//.........这里部分代码省略.........
endEditCP(sroot);
// the billboard
NodePtr bnode = Node::create();
bill = Billboard::create();
beginEditCP(bnode);
bnode->setCore( bill );
endEditCP(bnode);
beginEditCP(tnode);
tnode->addChild(bnode);
endEditCP(tnode);
// a geometry to billboard
NodePtr geo = makeTorus( .2, 1, 16, 3);
beginEditCP(bnode);
bnode->addChild( geo );
endEditCP(bnode);
// a geometry to lead the render action somewhere else
geo = makePlane( 2, 2, 2, 2 );
beginEditCP(sroot);
sroot->addChild( geo );
endEditCP(sroot);
dlight->updateVolume();
Vec3f min,max;
dlight->getVolume().getBounds( min, max );
std::cout << "Volume: from " << min << " to " << max << std::endl;
//std::cerr << "Tree: " << std::endl;
//root->dump();
// Camera
PerspectiveCameraPtr cam = PerspectiveCamera::create();
cam->setBeacon( b1n );
cam->setFov( deg2rad( 60 ) );
cam->setNear( .1 );
cam->setFar( 20. );
// Background
GradientBackgroundPtr bkgnd = GradientBackground::create();
bkgnd->addLine( Color3f( 0,0,0 ), 0 );
bkgnd->addLine( Color3f( .5,.5,0 ), 0.5 );
bkgnd->addLine( Color3f( .7,.7,1 ), 0.5 );
bkgnd->addLine( Color3f( 0,0,1 ), 1 );
// Viewport
ViewportPtr vp = Viewport::create();
vp->setCamera( cam );
vp->setBackground( bkgnd );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
// Window
std::cout << "GLUT winid: " << winid << std::endl;
GLUTWindowPtr gwin;
GLint glvp[4];
glGetIntegerv( GL_VIEWPORT, glvp );
gwin = GLUTWindow::create();
gwin->setId(winid);
gwin->setSize( glvp[2], glvp[3] );
win = gwin;
win->addPort( vp );
// Actions
dact = DrawAction::create();
ract = RenderAction::create();
// tball
Vec3f pos(0,
0,
max[2] + 1.5 * (max[2] - min[2]));
tball.setMode( Trackball::OSGObject );
tball.setStartPosition( pos, true );
tball.setSum( true );
tball.setTranslationMode( Trackball::OSGFree );
tball.setTranslationScale(10.);
// run...
glutMainLoop();
return 0;
}
示例4: main
//.........这里部分代码省略.........
NodePtr medDetailNode = makeSphere( 1, 1 );
GeometryPtr medSphereCore = GeometryPtr::dcast(medDetailNode->getCore());
SimpleMaterialPtr medDetailMat = SimpleMaterial::create();
medDetailMat->setDiffuse( Color3f( 0,1,0 ) );
medDetailMat->setAmbient( Color3f( 0,1,0 ) );
medSphereCore->setMaterial( medDetailMat );
NodePtr highDetailNode = makeSphere( 2, 1 );
GeometryPtr highSphereCore = GeometryPtr::dcast(highDetailNode->getCore());
SimpleMaterialPtr highDetailMat = SimpleMaterial::create();
highDetailMat->setDiffuse( Color3f( 0,0,1 ) );
highDetailMat->setAmbient( Color3f( 0,0,1 ) );
highDetailMat->setSpecular( Color3f(1, 1, 1) );
highDetailMat->setShininess( 10 );
highSphereCore->setMaterial( highDetailMat );
NodePtr lodNode = Node::create();
DistanceLODPtr lodNodeCore = DistanceLOD::create();
beginEditCP(lodNode);
lodNode->setCore(lodNodeCore);
lodNode->addChild( highDetailNode );
lodNode->addChild( medDetailNode );
lodNode->addChild( lowDetailNode );
endEditCP(lodNode);
beginEditCP(lodNodeCore);
lodNodeCore->editSFCenter()->setValue( Pnt3f(0, 0, 2) );
lodNodeCore->editMFRange()->push_back( 4.0 );
lodNodeCore->editMFRange()->push_back( 8.0 );
lodNodeCore->editMFRange()->push_back( 11.0 );
endEditCP(lodNodeCore);
//TRANSFORM LOD
NodePtr transLODNode = Node::create();
TransformPtr transLODCore = Transform::create();
transMat.setTranslate( 1, -1, -1 );
beginEditCP(transLODCore);
transLODCore->editSFMatrix()->setValue( transMat );
endEditCP(transLODCore);
beginEditCP( transLODNode );
transLODNode->setCore( transLODCore );
transLODNode->addChild( lodNode );
endEditCP( transLODNode );
//ROOT
root = Node::create();
GroupPtr rootCore = Group::create();
beginEditCP(root);
root->setCore(rootCore);
root->addChild(transNode);
root->addChild(transLODNode);
endEditCP(root);
camera = PerspectiveCamera::create();
beginEditCP(camera);
camera->setBeacon( beaconNode );
camera->setFov( deg2rad(90) );
camera->setNear( 0.1 );
camera->setFar( 10000 );
endEditCP(camera);
SolidBackgroundPtr background = SolidBackground::create();
viewp = Viewport::create();
beginEditCP(viewp);
viewp->setCamera( camera );
viewp->setBackground( background );
viewp->setRoot( root );
viewp->setSize( 0,0, 1,1 );
endEditCP(viewp);
GLint glVP[4];
glGetIntegerv( GL_VIEWPORT, glVP );
GLUTWindowPtr gwin = GLUTWindow::create();
gwin->setId(winID);
gwin->setSize(glVP[2], glVP[3]);
window = gwin;
beginEditCP(window);
window->addPort( viewp );
window->init();
endEditCP(window);
drAct = DrawAction::create();
Vec3f pos( 0, 0, 3 );
tball.setMode( Trackball::OSGObject );
tball.setStartPosition( pos, true );
tball.setSum( true );
tball.setTranslationMode( Trackball::OSGFree );
glutMainLoop();
return 0;
}
示例5: createGLPanel
ComponentPtr createGLPanel(void)
{
//Create the nessicary parts for a viewport
//Camera Beacon
Matrix TransformMatrix;
TransformMatrix.setTranslate(0.0f,0.0f, 0.0f);
TransformPtr CameraBeaconTransform = Transform::create();
beginEditCP(CameraBeaconTransform, Transform::MatrixFieldMask);
CameraBeaconTransform->setMatrix(TransformMatrix);
endEditCP(CameraBeaconTransform, Transform::MatrixFieldMask);
NodePtr CameraBeaconNode = Node::create();
beginEditCP(CameraBeaconNode, Node::CoreFieldMask);
CameraBeaconNode->setCore(CameraBeaconTransform);
endEditCP(CameraBeaconNode, Node::CoreFieldMask);
//Light Beacon
Matrix LightTransformMatrix;
LightTransformMatrix.setTranslate(0.0f,0.0f, 0.0f);
TransformPtr LightBeaconTransform = Transform::create();
beginEditCP(LightBeaconTransform, Transform::MatrixFieldMask);
LightBeaconTransform->setMatrix(TransformMatrix);
endEditCP(LightBeaconTransform, Transform::MatrixFieldMask);
NodePtr LightBeaconNode = Node::create();
beginEditCP(LightBeaconNode, Node::CoreFieldMask);
LightBeaconNode->setCore(CameraBeaconTransform);
endEditCP(LightBeaconNode, Node::CoreFieldMask);
//Light Node
DirectionalLightPtr TheDirectionLight = DirectionalLight::create();
beginEditCP(TheDirectionLight, DirectionalLight::DirectionFieldMask);
TheDirectionLight->setDirection(0.0f,1.0f,0.0f);
endEditCP(TheDirectionLight, DirectionalLight::DirectionFieldMask);
NodePtr LightNode = Node::create();
beginEditCP(LightNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
LightNode->setCore(TheDirectionLight);
LightNode->addChild(createScene());
endEditCP(LightNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
// Make Torus Node (creates Torus in background of scene)
NodePtr GeometryNode = makeTorus(.5, 2, 32, 32);
// Make Main Scene Node and add the Torus
NodePtr DefaultRootNode = osg::Node::create();
beginEditCP(DefaultRootNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
DefaultRootNode->setCore(osg::Group::create());
DefaultRootNode->addChild(CameraBeaconNode);
DefaultRootNode->addChild(LightBeaconNode);
DefaultRootNode->addChild(LightNode);
endEditCP(DefaultRootNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
//Camera
PerspectiveCameraPtr DefaultCamera = PerspectiveCamera::create();
beginEditCP(DefaultCamera);
DefaultCamera->setBeacon(CameraBeaconNode);
DefaultCamera->setFov (deg2rad(60.f));
DefaultCamera->setNear (0.1f);
DefaultCamera->setFar (100.f);
endEditCP(DefaultCamera);
//Background
GradientBackgroundPtr DefaultBackground = GradientBackground::create();
beginEditCP(DefaultBackground, GradientBackground::ColorFieldMask | GradientBackground::PositionFieldMask);
DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f);
DefaultBackground->addLine(Color3f(0.0f,0.0f,1.0f), 1.0f);
endEditCP(DefaultBackground, GradientBackground::ColorFieldMask | GradientBackground::PositionFieldMask);
//Viewport
ViewportPtr DefaultViewport = Viewport::create();
beginEditCP(DefaultViewport);
DefaultViewport->setCamera (DefaultCamera);
DefaultViewport->setRoot (DefaultRootNode);
DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f);
DefaultViewport->setBackground (DefaultBackground);
endEditCP(DefaultViewport);
//GL Viewport Component
GLViewportPtr TheGLViewport = GLViewport::create();
beginEditCP(TheGLViewport, GLViewport::PortFieldMask | GLViewport::PreferredSizeFieldMask | GLViewport::BordersFieldMask);
TheGLViewport->setPort(DefaultViewport);
TheGLViewport->setPreferredSize(Vec2f(1024.0f,768.0f));
endEditCP(TheGLViewport, GLViewport::PortFieldMask | GLViewport::PreferredSizeFieldMask | GLViewport::BordersFieldMask);
TheGLViewport->showAll();
return TheGLViewport;
}
示例6: attachApplication
void ApplicationBuilder::attachApplication(void)
{
Inherited::attachApplication();
beginEditCP(ApplicationBuilderPtr(this) , ApplicationBuilder::EditingProjectFieldMask);
setEditingProject(MainApplication::the()->getProject());
endEditCP(ApplicationBuilderPtr(this) , ApplicationBuilder::EditingProjectFieldMask);
//Camera Beacon
Matrix TransformMatrix;
TransformPtr CameraBeaconTransform = Transform::create();
beginEditCP(CameraBeaconTransform, Transform::MatrixFieldMask);
CameraBeaconTransform->setMatrix(TransformMatrix);
endEditCP(CameraBeaconTransform, Transform::MatrixFieldMask);
NodePtr CameraBeaconNode = Node::create();
beginEditCP(CameraBeaconNode, Node::CoreFieldMask);
CameraBeaconNode->setCore(CameraBeaconTransform);
endEditCP(CameraBeaconNode, Node::CoreFieldMask);
// Make Main Scene Node empty
NodePtr DefaultRootNode = osg::Node::create();
beginEditCP(DefaultRootNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
DefaultRootNode->setCore(osg::Group::create());
DefaultRootNode->addChild(CameraBeaconNode);
endEditCP(DefaultRootNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
//Camera
PerspectiveCameraPtr DefaultCamera = PerspectiveCamera::create();
beginEditCP(DefaultCamera);
DefaultCamera->setBeacon(CameraBeaconNode);
DefaultCamera->setFov (deg2rad(60.f));
DefaultCamera->setNear (0.1f);
DefaultCamera->setFar (10000.f);
endEditCP(DefaultCamera);
//Background
SolidBackgroundPtr DefaultBackground = SolidBackground::create();
beginEditCP(DefaultBackground, SolidBackground::ColorFieldMask);
DefaultBackground->setColor(Color3f(0.0f,0.0f,0.0f));
endEditCP(DefaultBackground, SolidBackground::ColorFieldMask);
//Icon Manager
_IconManager = DefaultIconManager::create();
//User Interface
ForegroundPtr UserInterfaceForeground = createInterface();
beginEditCP(_TheBuilderInterface->getDrawingSurface(), UIDrawingSurface::EventProducerFieldMask);
_TheBuilderInterface->getDrawingSurface()->setEventProducer(MainApplication::the()->getMainWindowEventProducer());
endEditCP(_TheBuilderInterface->getDrawingSurface(), UIDrawingSurface::EventProducerFieldMask);
//Viewport
if(MainApplication::the()->getMainWindowEventProducer()->getWindow() != NullFC && MainApplication::the()->getMainWindowEventProducer()->getWindow()->getPort().size() == 0)
{
ViewportPtr DefaultViewport = Viewport::create();
beginEditCP(DefaultViewport);
DefaultViewport->setCamera (DefaultCamera);
DefaultViewport->setRoot (DefaultRootNode);
DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f);
DefaultViewport->setBackground (DefaultBackground);
DefaultViewport->getForegrounds().push_back (UserInterfaceForeground);
endEditCP(DefaultViewport);
beginEditCP(MainApplication::the()->getMainWindowEventProducer()->getWindow(), Window::PortFieldMask);
MainApplication::the()->getMainWindowEventProducer()->getWindow()->addPort(DefaultViewport);
endEditCP(MainApplication::the()->getMainWindowEventProducer()->getWindow(), Window::PortFieldMask);
}
}
示例7: main
//.........这里部分代码省略.........
scene->addChild(cylinder2_trans_node);
endEditCP(scene);
vp = ShadowViewport::create();
GradientBackgroundPtr gbg = GradientBackground::create();
SolidBackgroundPtr sbg = SolidBackground::create();
UChar8 imgdata[] = { 255,0,0, 0,255,0, 0,0,255, 255,255,0 };
ImagePtr img1 = Image::create();
img1->set(Image::OSG_RGB_PF, 2, 2, 1, 1, 1, 0, imgdata);
TextureChunkPtr tcPtr = TextureChunk::create();
beginEditCP(tcPtr);
tcPtr->setImage(img1);
endEditCP(tcPtr);
TextureBackgroundPtr bkg = TextureBackground::create();
beginEditCP(bkg);
bkg->setTexture(tcPtr);
endEditCP(bkg);
beginEditCP(sbg);
sbg->setColor(Color3f(0.2,0.4,0.6));
endEditCP(sbg);
beginEditCP(gbg);
gbg->addLine(Color3f(0.7, 0.7, 0.8), 0);
gbg->addLine(Color3f(0.1, 0.1, 0.3), 1);
endEditCP(gbg);
beginEditCP(rootNode);
rootNode->addChild(point1);
rootNode->addChild(point1_beacon);
rootNode->addChild(point2_beacon);
endEditCP(rootNode);
//FBOViewportPtr
fbo_vp = FBOViewport::create();
addRefCP(fbo_vp);
// the Camera for the map
cam = PerspectiveCamera::create();
beginEditCP(cam);
cam->setFov(osgdegree2rad(90));
cam->setAspect(1);
cam->setNear(0.001);
cam->setFar(10000);
cam->setBeacon(box_trans_node);
endEditCP(cam);
beginEditCP(fbo_vp);
fbo_vp->setBackground(bkg);
fbo_vp->setRoot(rootNode);
fbo_vp->setCamera(cam);
fbo_vp->setSize(0,0,imageWinWidth-1, imageWinHeight-1);
fbo_vp->setStorageWidth(imageWinWidth);
fbo_vp->setStorageHeight(imageWinHeight);
fbo_vp->setDirty(true);
fbo_vp->editMFTextures ()->push_back(plane_tex);
fbo_vp->editMFExcludeNodes()->push_back(plane);
fbo_vp->setFboOn(true);
endEditCP(fbo_vp);
// normal shadow viewport
beginEditCP(vp);
vp->setBackground(gbg);
vp->setRoot(rootNode);
vp->setSize(0,0,1,1);
endEditCP(vp);
beginEditCP(gwin); //Window
gwin->setId(winid);
gwin->addPort(vp);
gwin->init();
endEditCP(gwin);
Vec3f min,max;
rootNode->updateVolume();
rootNode->getVolume().getBounds( min, max );
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
mgr->setWindow(gwin);
mgr->setRoot(rootNode);
//Viewport
beginEditCP(vp);
vp->setCamera(mgr->getCamera());
endEditCP(vp);
mgr->turnHeadlightOff();
mgr->showAll();
// GLUT main loop
glutMainLoop();
return 0;
}
示例8: main
//.........这里部分代码省略.........
root->addChild(dlight);
endEditCP(root);
// Load the file
NodePtr fileRoot = Node::create();
// OSGActivateColMatPtr colMat = OSGActivateColMat::create();
GroupPtr gr = Group::create();
beginEditCP(fileRoot);
// fileRoot->setCore(colMat);
fileRoot->setCore(gr);
endEditCP(fileRoot);
beginEditCP(dlight);
dlight->addChild(fileRoot);
endEditCP(dlight);
// for(UInt32 numFiles = 1; numFiles < argc; numFiles++)
// {
// file = SceneFileHandler::the().read(argv[1]);
file = loader.getRootNode();
beginEditCP(fileRoot);
fileRoot->addChild(file);
fileRoot->invalidateVolume();
endEditCP(fileRoot);
// }
dlight->updateVolume();
Vec3f min, max;
dlight->getVolume().getBounds(min, max);
std::cout << "Volume: from " << min << " to " << max << std::endl;
//std::cerr << "Tree: " << std::endl;
//root->dump();
// Camera
PerspectiveCameraPtr cam = PerspectiveCamera::create();
cam->setBeacon(b1n);
cam->setFov(deg2rad(60));
cam->setNear(1.);
cam->setFar(100000.);
// Background
GradientBackgroundPtr bkgnd = GradientBackground::create();
bkgnd->addLine(Color3f(0, 0, 0), 0);
bkgnd->addLine(Color3f(.5, .5, 0), 0.5);
bkgnd->addLine(Color3f(.7, .7, 1), 0.5);
bkgnd->addLine(Color3f(0, 0, 1), 1);
// Viewport
ViewportPtr vp = Viewport::create();
vp->setCamera(cam);
vp->setBackground(bkgnd);
vp->setRoot(root);
vp->setSize(0, 0, 1, 1);
// Window
std::cout << "GLUT winid: " << winid << std::endl;
GLUTWindowPtr gwin;
GLint glvp[4];
glGetIntegerv(GL_VIEWPORT, glvp);
gwin = GLUTWindow::create();
gwin->setId(winid);
gwin->setSize(glvp[2], glvp[3]);
win = gwin;
win->addPort(vp);
// Actions
dact = DrawAction::create();
ract = RenderAction::create();
// tball
/*
Vec3f pos(min[0] + 0.5 * (max[0] - min[0]),
min[1] + 0.5 * (max[1] - min[1]),
max[2] + 1.5 * (max[2] - min[2]));
*/
Vec3f pos(0, 0, max[2] + 1.5 * (max[2] - min[2]));
tball.setMode(Trackball::OSGObject);
tball.setStartPosition(pos, true);
tball.setSum(true);
tball.setTranslationMode(Trackball::OSGFree);
tball.setTranslationScale(10000.);
// run...
glutMainLoop();
return 0;
}
示例9: createSceneFBO
FBOViewportPtr createSceneFBO(void)
{
//Create Camera Beacon
Matrix CameraMat;
CameraMat.setTranslate(0.0f,0.0f,4.0f);
TransformPtr CameraBeconCore = Transform::create();
beginEditCP(CameraBeconCore, Transform::MatrixFieldMask);
CameraBeconCore->setMatrix(CameraMat);
endEditCP(CameraBeconCore, Transform::MatrixFieldMask);
NodePtr CameraBeconNode = Node::create();
beginEditCP(CameraBeconNode, Node::CoreFieldMask);
CameraBeconNode->setCore(CameraBeconCore);
endEditCP(CameraBeconNode, Node::CoreFieldMask);
//Create Camera
PerspectiveCameraPtr TheCamera = PerspectiveCamera::create();
beginEditCP(TheCamera);
TheCamera->setFov(deg2rad(60.0f));
TheCamera->setAspect(1.0f);
TheCamera->setNear(0.1f);
TheCamera->setFar(100.0f);
TheCamera->setBeacon(CameraBeconNode);
endEditCP(TheCamera);
//Make the Material
BlinnMaterialPtr TheMaterial = BlinnMaterial::create();
beginEditCP(TheMaterial);
TheMaterial->setDiffuse(0.8);
TheMaterial->setColor(Color3f(1.0,1.0,1.0));
TheMaterial->setAmbientColor(Color3f(1.0,1.0,1.0));
TheMaterial->setNumLights(1);
endEditCP(TheMaterial);
// Make Torus Node (creates Torus in background of scene)
NodePtr TorusGeometryNode = makeTorus(.5, 2, 24, 48);
beginEditCP(TorusGeometryNode->getCore());
GeometryPtr::dcast(TorusGeometryNode->getCore())->setMaterial(TheMaterial);
endEditCP(TorusGeometryNode->getCore());
calcVertexNormals(GeometryPtr::dcast(TorusGeometryNode->getCore()));
calcVertexTangents(GeometryPtr::dcast(TorusGeometryNode->getCore()),0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId);
RootTransformCore = Transform::create();
NodePtr TorusTransformNode = Node::create();
beginEditCP(TorusTransformNode, Node::CoreFieldMask);
TorusTransformNode->setCore(RootTransformCore);
TorusTransformNode->addChild(TorusGeometryNode);
endEditCP(TorusTransformNode, Node::CoreFieldMask);
//Create Light Beacon
Matrix LightMat;
LightMat.setTranslate(0.0f,10.0f,1.0f);
TransformPtr LightBeconCore = Transform::create();
beginEditCP(LightBeconCore, Transform::MatrixFieldMask);
LightBeconCore->setMatrix(LightMat);
endEditCP(LightBeconCore, Transform::MatrixFieldMask);
NodePtr LightBeconNode = Node::create();
beginEditCP(LightBeconNode, Node::CoreFieldMask);
LightBeconNode->setCore(LightBeconCore);
endEditCP(LightBeconNode, Node::CoreFieldMask);
//Create Light
TheLight = PointLight::create();
beginEditCP(TheLight);
TheLight->setBeacon(LightBeconNode);
endEditCP(TheLight);
NodePtr LightNode = Node::create();
beginEditCP(LightNode, Node::CoreFieldMask);
LightNode->setCore(TheLight);
LightNode->addChild(TorusTransformNode);
endEditCP(LightNode, Node::CoreFieldMask);
//Create Root
NodePtr TheRoot = Node::create();
beginEditCP(TheRoot);
TheRoot->setCore(Group::create());
TheRoot->addChild(CameraBeconNode);
TheRoot->addChild(LightNode);
TheRoot->addChild(LightBeconNode);
endEditCP(TheRoot);
//Create Background
SolidBackgroundPtr TheBackground = SolidBackground::create();
TheBackground->setColor(Color3f(1.0,0.0,0.0));
//DepthClearBackgroundPtr TheBackground = DepthClearBackground::create();
//Create the Image
ImagePtr TheColorImage = Image::create();
TheColorImage->set(Image::OSG_RGB_PF,2,2,1,1,1,0.0f,0,Image::OSG_FLOAT16_IMAGEDATA);
//Create the texture
TextureChunkPtr TheColorTextureChunk = TextureChunk::create();
//.........这里部分代码省略.........
示例10: main
int main( int argc, char **argv )
{
Int32 i,
retVal;
// OSG init
osgInit(argc, argv);
basetime = getSystemTime();
gThreadManager = ThreadManager::the();
SceneFileHandler::the().print();
// create the graph
// beacon for camera and light
NodePtr b1n = Node::create();
GroupPtr b1 = Group::create();
beginEditCP(b1n);
b1n->setCore( b1 );
endEditCP(b1n);
// transformation
NodePtr t1n = Node::create();
TransformPtr t1 = Transform::create();
beginEditCP(t1n);
t1n->setCore( t1 );
t1n->addChild( b1n );
endEditCP(t1n);
cam_trans = t1;
// light
NodePtr dlight = Node::create();
DirectionalLightPtr dl = DirectionalLight::create();
beginEditCP(dlight);
dlight->setCore( dl );
endEditCP(dlight);
beginEditCP(dl);
dl->setAmbient( .3, .3, .3, 1 );
dl->setDiffuse( 1, 1, 1, 1 );
dl->setDirection(0,0,1);
dl->setBeacon( b1n);
endEditCP(dl);
// root
root = Node::create();
GroupPtr gr1 = Group::create();
beginEditCP(root);
root->setCore( gr1 );
root->addChild( t1n );
root->addChild( dlight );
endEditCP(root);
// Load the file
NodePtr file = NullFC;
if ( argc > 1 )
file = SceneFileHandler::the().read(argv[1]);
if ( file == NullFC )
{
std::cerr << "Couldn't load file, ignoring" << std::endl;
file = makePlane( 2,2,2,2 );
}
file->updateVolume();
Vec3f min,max;
file->getVolume().getBounds( min, max );
std::cout << "Volume: from " << min << " to " << max << std::endl;
beginEditCP(dlight);
dlight->addChild( file );
endEditCP(dlight);
std::cerr << "Tree: " << std::endl;
root->dump();
// Camera
PerspectiveCameraPtr cam = PerspectiveCamera::create();
cam->setBeacon( b1n );
cam->setFov( deg2rad( 60 ) );
cam->setNear( 0.1 );
cam->setFar( 10000 );
// Background
GradientBackgroundPtr bkgnd = GradientBackground::create();
bkgnd->addLine( Color3f( 0,0,0 ), 0 );
bkgnd->addLine( Color3f( 0,0,1 ), 0 );
// Action
//.........这里部分代码省略.........
示例11: main
//.........这里部分代码省略.........
{
fprintf(stderr, "FCPtr NULL\n");
}
}
else
{
fprintf(stderr, "Binder NULL\n");
}
*/
file = aVRMLToOSG.getRoot();
if(file == NullFC)
return 0;
file->updateVolume();
Vec3f min,max;
file->getVolume().getBounds( min, max );
cout << "Volume: from " << min << " to " << max << endl;
beginEditCP(dlight);
dlight->addChild( file );
endEditCP(dlight);
cerr << "Tree: " << endl;
// root->dump();
// Camera
cam = PerspectiveCamera::create();
cam->setBeacon( b1n );
cam->setFov( deg2rad( 90 ) );
cam->setNear( 0.1 );
cam->setFar( 10000 );
// Background
SolidBackgroundPtr bkgnd = SolidBackground::create();
// Viewport
vp = Viewport::create();
vp->setCamera( cam );
vp->setBackground( bkgnd );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
// Window
cout << "GLUT winid: " << winid << endl;
GLUTWindowPtr gwin;
GLint glvp[4];
glGetIntegerv( GL_VIEWPORT, glvp );
gwin = GLUTWindow::create();
gwin->setId(winid);
gwin->setSize( glvp[2], glvp[3] );
win = gwin;
win->addPort( vp );
win->init();
示例12: main
//.........这里部分代码省略.........
obj3Pnts->addValue( Pnt3f(4, 0,0) );
endEditCP( obj3Pnts );
beginEditCP( obj3Types );
//obj3Types->addValue( GL_TRIANGLES );
//obj3Types->addValue( GL_QUADS );
//obj3Types->addValue( GL_TRIANGLES );
obj3Types->addValue( GL_POLYGON );
endEditCP( obj3Types );
beginEditCP( obj3Lengths );
//obj3Lengths->addValue( 3 );
//obj3Lengths->addValue( 4 );
//obj3Lengths->addValue( 3 );
obj3Lengths->addValue( 6 );
endEditCP( obj3Lengths );
beginEditCP( obj3Colors );
for( UInt32 i=0; i<obj3Pnts->getSize(); ++i )
{
obj3Colors->addValue( Color3f(.7,.7,.7) );
}
endEditCP( obj3Colors );
beginEditCP( obj3Index );
//for( UInt32 i=0; i<obj3Pnts->getSize(); ++i )
//{
// obj3Index->addValue( i );
//}
obj3Index->addValue( 0 );
obj3Index->addValue( 1 );
obj3Index->addValue( 5 );
obj3Index->addValue( 9 );
obj3Index->addValue( 6 );
obj3Index->addValue( 2 );
endEditCP( obj3Index );
beginEditCP( obj3Core );
obj3Core->setIndices( obj3Index );
obj3Core->setPositions( obj3Pnts );
obj3Core->setTypes( obj3Types );
obj3Core->setLengths( obj3Lengths );
obj3Core->setColors( obj3Colors );
endEditCP( obj3Core );
beginEditCP( objects[3] );
objects[3]->setCore( obj3Core );
endEditCP( objects[3] );
calcFaceNormals( GeometryPtr::dcast(objects[3]->getCore()) );
normals[3] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[3]->getCore()), 0.5 );
//ROOT
root = Node::create();
GroupPtr rootCore = Group::create();
beginEditCP(root);
root->setCore(rootCore);
root->addChild(transNode);
root->addChild(objects[0]);
root->addChild(normals[0]);
activeObj = root->findChild( objects[0] );
activeNorm = root->findChild( normals[0] );
endEditCP(root);
camera = PerspectiveCamera::create();
camera->setBeacon( beaconNode );
camera->setFov( 90 );
camera->setNear( 0.1 );
camera->setFar( 10000 );
SolidBackgroundPtr background = SolidBackground::create();
viewp = Viewport::create();
viewp->setCamera( camera );
viewp->setBackground( background );
viewp->setRoot( root );
viewp->setSize( 0,0, 1,1 );
GLint glVP[4];
glGetIntegerv( GL_VIEWPORT, glVP );
GLUTWindowPtr gwin = GLUTWindow::create();
gwin->setId(winID);
gwin->setSize(glVP[2], glVP[3]);
window = gwin;
window->addPort( viewp );
window->init();
drAct = DrawAction::create();
Vec3f pos( 0, 0, 3 );
tball.setMode( Trackball::OSGObject );
tball.setStartPosition( pos, true );
tball.setSum( true );
tball.setTranslationMode( Trackball::OSGFree );
glutMainLoop();
return 0;
}