在OSG场景中,采用HUD抬头显示来显示模型的运动参数,但是运行的时候发现HUD出现重复投射的现象,如图中红线框中所示。
抬头显示的CreateHUDText函数如下:
// 创建HUD抬头显示文字
osg::Projection* cOSG::CreateHUDText(void)
{
// 获取屏幕尺寸
RECT rect;
int rect_width,rect_height;
// Get the current window size
::GetWindowRect(m_hWnd, &rect);
rect_width = rect.right - rect.left;
rect_height = rect.bottom - rect.top;
// 投影节点用于定义HUD的视景体(view frustrum)
osg::Projection* HUDProjectionMatrix = new osg::Projection;
// 投影矩阵的水平和垂直范围与屏幕尺寸相同,
// 因此该节点子树中的位置坐标将等同于像素坐标
HUDProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,rect_width,0,rect_height));
// HUD模型观察矩阵应使用单位矩阵
osg::MatrixTransform* HUDModelViewMatrix = new osg::MatrixTransform;
HUDModelViewMatrix->setMatrix(osg::Matrix::identity());
// 确保模型观察矩阵不会