|
本帖最后由 267270476 于 2013-7-16 08:56 编辑
quad生成:- osg::ref_ptr<osg::Geometry> OsgGeometryBuilder::getQuadGeometry(
- const osg::ref_ptr<osg::Vec3Array>& aVertexArray)
- {
- osg::ref_ptr<osg::Geometry> aVertexQuad = new osg::Geometry();
- aVertexQuad->setVertexArray(aVertexArray.get());
- osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(1);
- (*normals)[0].set(0, 0, -1);
- aVertexQuad->setNormalArray(normals.get());
- aVertexQuad->setNormalBinding(osg::Geometry::BIND_OVERALL);
- aVertexQuad->addPrimitiveSet(new osg::DrawArrays(osg::DrawArrays::QUADS, 0, aVertexArray->size()));
- return aVertexQuad;
- }
复制代码- osg::ref_ptr<osg::Group> OsgGeometryBuilder::CreateQuadOsgGeometryFromCenter(
- const new_geometry::Vertex3d& aCenter,
- const double& aWidth)
- {
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- std::vector<new_geometry::Vertex3d> vertice3Ds = getQuadVertices(aCenter, aWidth);
- float deltaX = 0;
- float deltaY = 0;
- osg::ref_ptr<osg::Vec3Array> vertexArray = getOptimizedVec3Array(
- &vertice3Ds,
- deltaX,
- deltaY);
- osg::ref_ptr<osg::Geometry> vertexQuad = getQuadGeometry(vertexArray);
- geode->addDrawable(vertexQuad);
- osg::ref_ptr<osg::MatrixTransform> transformer = new osg::MatrixTransform;
- transformer->addChild(geode);
- transformer->setMatrix(osg::Matrix::translate(deltaX, deltaY, 0));
- osg::ref_ptr<osg::Group> group = new osg::Group;
- group->addChild(transformer);
- return group;
- }
复制代码 Intersector生成:- osg::ref_ptr<osgUtil::PolytopeIntersector> OsgIntersectorEventHandler::getPolytopeIntersector(
- const osgGA::GUIEventAdapter& aEventAdapter,
- const double& aWidth,
- const double& aHeight)
- {
- double centerX = aEventAdapter.getXnormalized();
- double centerY = aEventAdapter.getYnormalized();
- osg::ref_ptr<osgUtil::PolytopeIntersector> picker(
- new osgUtil::PolytopeIntersector(
- osgUtil::Intersector::PROJECTION,
- centerX - aWidth,
- centerY - aHeight,
- centerX + aWidth,
- centerY + aHeight)
- );
- return picker;
- }
复制代码 Quad的边长为0.04,求交器的长宽都为0.02.
跪求大神们帮忙! |
|