查看: 2429|回复: 2

求助一个有关顶点索引的问题,谢谢您的回复

[复制链接]

该用户从未签到

发表于 2008-8-19 15:55:39 | 显示全部楼层 |阅读模式
今天遇到一个有关顶点索引的问题,对我这菜手来说感到很奇怪。我的目的是想把一个num*num的点阵连成一系列的三角形,在点阵的规格num小于等于16的时候可达预期运行结果,可是在num大于16以后就不能得到正确的结果了,程序如下:

#include <osg/Group>
#include <osg/Geode>
#include <osg/Array>
#include <osg/Geometry>
#include <osg/Drawable>
#include <osg/Vec3>
#include <osg/Array>
#include <osgViewer/Viewer>

int main(int, char**)
{
                 const int num=16;                         //点阵的规格num*num

        osg::ref_ptr<osg::Group> root=new osg::Group();
        osg::ref_ptr<osg::Geode> geod=new osg::Geode();
        osg::ref_ptr<osg::Geometry> gmtr=new osg::Geometry();
                root->addChild(geod.get());
        geod->addDrawable(gmtr.get());

        osg::ref_ptr<osg::Vec3Array> vertex=new osg::Vec3Array();

        for(int i=0; i<num; i++)
                for(int j=0; j<num; j++)
                {
                        vertex->push_back(osg::Vec3f(i,j,0.f));
                }

        osg::UByteArray* vertexindex=new osg::UByteArray();

        for(int i=0; i<num-1; i++)
                for(int j=0; j<num-1; j++)
                {
                        vertexindex->push_back(i*num+j);
                        vertexindex->push_back(i*num+j+1);
                        vertexindex->push_back((i+1)*num+j+1);

                }

        gmtr->setVertexArray(vertex.get());
        gmtr->setVertexIndices(vertexindex);

        gmtr->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet::TRIANGLES,0,vertexindex->size()));

        osgViewer::Viewer viewer;
        viewer.setSceneData(root.get());

        return viewer.run();
}

其中const型的num即为点阵规格(num*num),当num等于16时,运行截图如下:
num_16.jpg
当num大于16以后就运行出错了,谢谢高手解答。

该用户从未签到

发表于 2008-8-19 16:00:05 | 显示全部楼层
UByteArray是Byte数组,也就是8位数组,它能接受的数范围不超过0-256
所以大于16*16的顶点索引就不接受了,可以考虑用UIntArray代替

该用户从未签到

 楼主| 发表于 2008-8-20 10:00:13 | 显示全部楼层
嗯,再次谢谢你的热心帮助。呵呵,osg考虑的周到,索引总数不超过256时每个元素给8位,多给了也是浪费,我明白了,谢谢。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表