在ogre中如果需要进行自定义图形绘制可以使用ManualObject。例如绘制一个三角形的用法如下:
SceneNode* pGridNode = m_pBaseNode->createChildSceneNode("gridNode");
//创建ManualObject
Ogre::ManualObject* grid = m_pSceneMgr->createManualObject("gird");
//创建材质 //使用ogre的自带材质
grid->begin("BaseWhite",RenderOperation::OT_TRIANGLE_LIST); //顶点顺序默认为逆时针可见 grid->position(100.0f,,); //vertex1
grid->colour(ColourValue(,,,)); grid->position(,,);
grid->colour(ColourValue(,,,)); //vertex2 grid->position(-100.0f,,);
grid->colour(ColourValue(,,,)); //vertex3 grid->end(); pGridNode->attachObject(grid);
绘制1个Quad
void EditorScene::DrawQuadIndexed()
{
//使用顶点缓存绘制一个quad 只需要指定4个vertex
SceneNode* pGridNode = m_pBaseNode->createChildSceneNode("gridNode",Vector3(,,));
ManualObject* quad = m_pSceneMgr->createManualObject("quad"); quad->begin("BaseWhite",RenderOperation::OT_TRIANGLE_LIST); quad->position(,-,); //vertex1
quad->colour(ColourValue(,,,));
quad->position(,,);
quad->colour(ColourValue(,,,)); //vertex2
quad->position(-100.0f,,);
quad->colour(ColourValue(,,,)); //vertex3
quad->position(-,-,);
quad->colour(ColourValue(,,,)); //vertex4 //指定顶点
quad->triangle(,,); //triangle1
quad->triangle(,,); //triangle2
quad->end();
pGridNode->attachObject(quad); }
其中Ogre自带三种内置材质:
DefaultSettings :默认材质
BaseWhite :基于光照的白色材质,事实上DefaultSettings的材质就是它
BaseWhiteNoLighting :基于无光照的白色材质