|
准备用HUD做2D编辑,捕捉鼠标事件,但获取的坐标(getXnormalized,getYnormalized)都不对,怎么才能获取正确的坐标,求解答。HUD代码:- osg::Vec3d center = geode->getBound().center();
- double radius = geode->getBound().radius();
- //设置相机
- osg::Camera* camera = new osg::Camera;
- double left = center.x() - radius;
- double right = center.x() + radius;
- double bottom = center.y() - radius;
- double top = center.y() + radius;
- //设置透视矩阵
- camera->setProjectionMatrix(osg::Matrix::ortho2D(left, right, bottom, top));
- camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- //得到默认设置
- camera->setViewMatrix(osg::Matrix::identity());
- //设置背景为透明,否则的话可以设置ClearColor
- camera->setClearMask(GL_DEPTH_BUFFER_BIT);
- //设置渲染顺序,必须在最后渲染
- camera->setRenderOrder(osg::Camera::POST_RENDER);
- camera->addChild(geode);
复制代码 |
|