|
本帖最后由 xulin_2005 于 2012-8-24 10:17 编辑
旋转视角后平面消失问题
背景:
我在写一个网格区域随鼠标高亮的功能。即,鼠标在网格上移动,相应的网格区域会高亮显示。
问题描述:
当放大视角时,高亮区域的平面会消失,然后转动视角后又会出现。具体见图:
其他线索:
我以为是法线角度设置的问题,因为一开始绘制的平面,未经过鼠标移动后放大视角不会出现这个问题,具体见图:
截图:
随鼠标移动的高亮区域
初始化时画的高亮平面
相关代码:
- // 更新高亮区域
- void GridGround::UpdateHL()
- {
- if ( !m_gmQuaz || !m_bNeedUpdate )
- return;
- osg::Vec3Array * vertices = dynamic_cast<osg::Vec3Array *> ( m_gmQuaz->getVertexArray() );
- if ( vertices && (vertices->size() == 4) )
- {
- vertices->at(0).set(g_center + g_dx*(float)m_x + g_dy*(float)m_y);
- vertices->at(1).set(g_center + g_dx*(float)(m_x+m_w) + g_dy*(float)m_y);
- vertices->at(2).set(g_center + g_dx*(float)(m_x+m_w) + g_dy*(float)(m_y+m_l));
- vertices->at(3).set(g_center + g_dx*(float)m_x + g_dy*(float)(m_y+m_l));
- }
-
- // 法线重置
- osg::Vec3Array* normals = new osg::Vec3Array;
- normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
- m_gmQuaz->setNormalArray(normals);
- m_gmQuaz->setNormalBinding(osg::Geometry::BIND_OVERALL);
- // 准备更新
- vertices->dirty();
- m_bNeedUpdate = false;
- }
复制代码
-
- // 绘制网格区域
- osg::Node* GridGround::create(const osg::Vec3& center,float radius, int x = 0, int y = 0, int w = 1, int l = 1, int g_iNumTiles = 10)
- {
- // 画网格线
- ...
- // 绘制高亮区域
- //m_gmQuaz = new osg::Geometry;
- m_gmQuaz->setName("HeightLight");
- // 绘制矩形区域
- osg::Vec3Array* crdsQuaz = new osg::Vec3Array;
- crdsQuaz->push_back(g_v000 + g_dx*(float)x + g_dy*(float)y);
- crdsQuaz->push_back(g_v000 + g_dx*(float)(x+w) + g_dy*(float)y);
- crdsQuaz->push_back(g_v000 + g_dx*(float)(x+w) + g_dy*(float)(y+l));
- crdsQuaz->push_back(g_v000 + g_dx*(float)x + g_dy*(float)(y+l));
- m_gmQuaz->setVertexArray(crdsQuaz);
- m_gmQuaz->setColorArray(colors);
- m_gmQuaz->setColorBinding(osg::Geometry::BIND_OVERALL);
- m_gmQuaz->setNormalArray(normals);
- m_gmQuaz->setNormalBinding(osg::Geometry::BIND_OVERALL);
- m_gmQuaz->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,crdsQuaz->size()));
- m_gmQuaz->setUseDisplayList( false );
- m_gmQuaz->setUseVertexBufferObjects( true );
- osg::Geode* geode = new osg::Geode;
- geode->addDrawable(m_gmGrid);
- // 贴地表图
- ...
- return geode;
- }
复制代码- case (osgGA::GUIEventAdapter::MOVE): // 鼠标移动事件处理
- {
- bool bRet = getPosition(m_Viewer, ea, position);
- if ( bRet )
- {
- m_pGridGround->Caculate(position, 1, 1);
- m_pGridGround->UpdateHL();
- }
- }
复制代码 |
|