先說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個頂點。