1.设置几何体各顶点坐标
osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = corner; //原点
(*coords)[1] = corner+width; //x轴点
(*coords)[2] = corner+width+height; //与原点对称的斜方向顶点
(*coords)[3] = corner+height; //z轴点
geom->setVertexArray(coords);
2.向量积得出法向量
(*norms)[0] = width^height;
3.开始没搞清x,y,z轴三个顶点坐标的设置,原来是先设置的当地坐标,然后再设置的世界坐标。搞清楚osg坐标系朝向问题即可想明白。
center->addDrawable( createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Images/reflect.rgb")),osg::Vec3(0.0f,0.0f,0.0f)); //原点图片
x_arrow->addDrawable( createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posx.png")),osg::Vec3(5.0f,0.0f,0.0f)); //x轴图片
y_arrow->addDrawable( createSquare(osg::Vec3(0.0f,-0.5f,-0.5f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posy.png")),osg::Vec3(0.0f,5.0f,0.0f)); //y轴图片
z_arrow->addDrawable( createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readRefImageFile("Cubemap_axis/posz.png")),osg::Vec3(0.0f,0.0f,5.0f)); //z轴图片