查看: 1100|回复: 1

node的角度位置怎么固定(代码贴出)

[复制链接]

该用户从未签到

发表于 2013-2-1 16:33:29 | 显示全部楼层 |阅读模式
// 创建一个追踪求操作器
trackball = new osgGA::TrackballManipulator();
//创建一个调度操作器
keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
// 添加追踪球操作器到调度操作器中
keyswitchManipulator->addMatrixManipulator( '1', "Trackball", trackball.get());
// Init the switcher to the first manipulator (in this case the only manipulator)
keyswitchManipulator->selectMatrixManipulator(0);  // Zero based index Value


// Local Variable to hold window size data
RECT rect;

// 创建一个视图
mViewer = new osgViewer::Viewer();

// Add a Stats Handler to the viewer
mViewer->addEventHandler(new osgViewer::StatsHandler);
   
    // Get the current window size
    ::GetWindowRect(m_hWnd, &rect);

    // Init the GraphicsContext Traits
    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;

    // Init the Windata Variable that holds the handle for the Window to display OSG in.
    osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(m_hWnd);

    // Setup the traits parameters
    traits->x = 0;
    traits->y = 0;
    traits->width = rect.right - rect.left;
    traits->height = rect.bottom - rect.top;
    traits->windowDecoration = false;
    traits->doubleBuffer = true;
    traits->sharedContext = 0;
    traits->setInheritedWindowPixelFormat = true;
    traits->inheritedWindowData = windata;
    // Create the Graphics Context
    osg::GraphicsContext* gc = osg::GraphicsContext::createGraphicsContext(traits.get());

    // Init a new Camera (Master for this View)
    osg::ref_ptr<osg::Camera> camera = new osg::Camera;
       
    // Assign Graphics Context to the Camera
    camera->setGraphicsContext(gc);

    // Set the viewport for the Camera
    camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));

    // Add the Camera to the Viewer
    mViewer->addSlave(camera.get());

        // Add the Camera Manipulator to the Viewer
    mViewer->setCameraManipulator(keyswitchManipulator.get());

        osg::ref_ptr<osg::Group> root = new osg::Group();

        osgText::Text* updatetext = new osgText::Text();
        CreateHUD *hudText= new CreateHUD();

        root->addChild(hudText->createHUD(updatetext));

       
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //HUD node
         osg::Camera* hudCamera = new osg::Camera;
         hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
         hudCamera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);//(0,18,0,14)
         hudCamera->setViewMatrix(osg::Matrix::identity());
                 hudCamera->setRenderOrder(osg::Camera:OST_RENDER);
         hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);

                 osg::ref_ptr<osg::Node> node;
                 osg::PositionAttitudeTransform* transform = new osg::PositionAttitudeTransform;
                 transform->addChild(node);
                  root->addChild(transform);
                //hudCamera->addChild(transform);
                transform->setScale(osg::Vec3(1.0,1.0,1.0));
                transform->setPosition(osg::Vec3(0.0,0.0,0.0));
                osg:uat rotation;
                rotation.makeRotate(osg:egreesToRadians(0.0f), osg::Vec3(1.0f,0.0f,0.0f),
                        osg::DegreesToRadians(0.0f), osg::Vec3(0.0f, 1.0f, 0.0f),
                        osg::DegreesToRadians(0.0f), osg::Vec3(0.0f, 0.0f, 1.0f));

                transform->setAttitude(rotation);
        //HUD node
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        osgUtil::Optimizer optimizer ;
        optimizer.optimize(root) ;

    // Set the Scene Data
        mViewer->setSceneData(root.get());

        // Realize the Viewer
    mViewer->realize();

}

该用户从未签到

发表于 2013-2-4 09:31:56 | 显示全部楼层
您要问什么
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表