Ogre靜態管線和手繪Mesh ManualObject

來源:互聯網
上載者:User

先說ManualObject

MannualObject mo;

mo.begin("Examples/GrassBlades",RenderOperation::OT_TRIANGLE_LIST);
   for (int i=0;i<3;++i)
   {
    mo.position(-vec.x,height,-vec.z);
    mo.textureCoord(0,0);
    mo.position(vec.x,height,vec.z);
    mo.textureCoord(1,0);
    mo.position(-vec.x,0,-vec.z);
    mo.textureCoord(0,1);
    mo.position(vec.x,0,vec.z);
    mo.textureCoord(1,1);

    int offset = i*4;
    mo.triangle(offset,offset+3,offset+1);
    mo.triangle(offset,offset+2,offset+3);
    vec = rot * vec;
   }
   mo.end();
   mo.convertToMesh("GrassBladesMesh");

所謂ManualObject就是使用自訂頂點,索引,紋理座標,和DX 裡定義頂點差不多。最後convertToMesh,將這個模型儲存在ResourceManager裡面。

再說靜態管線,對於靜態管線,就是諸如遊戲中的建築物,樹啊,草啊,這些不用移動的物體,用靜態渲染,我想這個和DX裡面將頂點存入靜態Memorypool。

靜態管線首先設定一個地區,地區由中心點和範圍組成,一個矩形地區,然後在這個矩形地區添加物體即可。

下面是在靜態管線中建立草坪的代碼。

Entity* grass = mSceneMgr->createEntity("grass","GrassBladesMesh");
   StaticGeometry* sg = mSceneMgr->createStaticGeometry("GrassArea");
   const int size = 375;
   const int amount = 20;
  
   sg->setRegionDimensions(Vector3(size,size,size));
   sg->setOrigin(Vector3(-size/2,0,-size/2));

   for (int x=-size/2;x<size/2;x+=size/amount)
   {
    for (int z= -size/2;z<size/2;z+=size/amount)
    {
     Real r = size/(float)amount/2;
     Vector3 pos(x+Math::RangeRandom(-r,r),0,z+Math::RangeRandom(-r,r));
     Vector3 scale(1,Math::RangeRandom(0.9,1.1),1);
     Quaternion oritention;
     oritention.FromAngleAxis(Degree(Math::RangeRandom(0,359)),Vector3::UNIT_Y);
     sg->addEntity(grass,pos,oritention,scale);
     sg->build();
    }
   }
}

再說說草的繪製,一個四邊形立起來,上面是一張草的圖片,然後旋轉60,繞垂直軸,再旋轉60,4*3 =12個頂點。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.