使用Ogre::ManualObject 绘制自定义图形
在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,0,0); //vertex1 grid->colour(ColourValue(1,1,1,1)); grid->position(0,173,0); grid->colour(ColourValue(1,1,1,1)); //vertex2 grid->position(-100.0f,0,0); grid->colour(ColourValue(1,1,1,1)); //vertex3 grid->end(); pGridNode->attachObject(grid);
绘制1个Quad
void EditorScene::DrawQuadIndexed() { //使用顶点缓存绘制一个quad 只需要指定4个vertex SceneNode* pGridNode = m_pBaseNode->createChildSceneNode("gridNode",Vector3(0,0,200)); ManualObject* quad = m_pSceneMgr->createManualObject("quad"); quad->begin("BaseWhite",RenderOperation::OT_TRIANGLE_LIST); quad->position(100,-100,0); //vertex1 quad->colour(ColourValue(1,1,1,1)); quad->position(100,100,0); quad->colour(ColourValue(1,1,1,1)); //vertex2 quad->position(-100.0f,100,0); quad->colour(ColourValue(1,1,1,1)); //vertex3 quad->position(-100,-100,0); quad->colour(ColourValue(1,1,1,1)); //vertex4 //指定顶点 quad->triangle(0,1,2); //triangle1 quad->triangle(2,3,0); //triangle2 quad->end(); pGridNode->attachObject(quad); }
其中Ogre自带三种内置材质:
DefaultSettings :默认材质
BaseWhite :基于光照的白色材质,事实上DefaultSettings的材质就是它
BaseWhiteNoLighting :基于无光照的白色材质