Ogre 如何渲染简单的几何物体

Ogre 如何渲染简单的几何物体

Ogre 如何渲染简单的几何物体
使用ManualObject或者其派生类渲染简单的几何物体, 步骤如下:
    1. 新创建一个ManualObject对象
            mManualObj = new Ogre::ManualObject("SimpleStuff2");
    2. 设置该ManualObject的参数
        1) 设置其渲染序列组
            mManualObj->setRenderQueueGroup(RENDER_QUEUE_OVERLAY);
        2) 使用单元投影矩阵和单元视图矩阵, 这两个默认为false, 即使用相机的视图矩阵和投影矩阵
            mManualObj->setUseIdentityProjection(true);
            mManualObj->setUseIdentityView(true);
            使用这两个函数之后, 所绘制的物体坐标范围位于(-1, -1, -1)至(1, 1, 1)之间
        3) 设置查询参数
            mManualObj = new Ogre::ManualObject("SimpleStuff2");
    3. 调用绘制函数
        mManualObj->clear();
        mManualObj->begin("", RenderOperation::OT_LINE_STRIP);
        for (int i = 0; i < 5; i++)
        {
            mManualObj->position(pos[i]);
        }
        mManualObj->end();
    4. 创建场景节点挂接该对象
        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mManualObj);   


完整代码
SimpleStuff.h
 1 #ifndef __SIMPLE_STUFF_H__
 2  #define __SIMPLE_STUFF_H__
 3 
 4 #include "ExampleApplication.h"
 5 
 6  class SimpleStuffApp :  public ExampleApplication
 7 {
 8  public:
 9     SimpleStuffApp() {}
10     ~SimpleStuffApp()
11     {
12          if(mManualObj)
13         {
14             delete mManualObj;
15         }
16     }
17  protected:
18      void createScene();
19     Ogre::ManualObject* mManualObj;
20 };
21 
22  #endif


SimpleStuff.cpp
 1 #include "SimpleStuff.h"
 2 
 3  void SimpleStuffApp::createScene()
 4 {
 5     mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
 6     
 7      float constantValue = 0.5;
 8     Vector3 pos[] =
 9     {
10         Vector3(-constantValue, -constantValue, 1),
11         Vector3(constantValue, -constantValue, 1),
12         Vector3(constantValue, constantValue, 1),
13         Vector3(-constantValue, constantValue, 1),
14         Vector3(-constantValue, -constantValue, 1),
15     };
16     mManualObj =  new Ogre::ManualObject("SimpleStuff2");
17     mManualObj->setRenderQueueGroup(RENDER_QUEUE_OVERLAY);
18     mManualObj->setUseIdentityProjection( true);
19     mManualObj->setUseIdentityView( true);
20     mManualObj->setQueryFlags(0);
21     mManualObj->clear();
22     mManualObj->begin("", RenderOperation::OT_LINE_STRIP);
23      for ( int i = 0; i < 5; i++)
24     {
25         mManualObj->position(pos[i]);
26     }
27     mManualObj->end();
28  //     mManualObj->setBoundingBox(AxisAlignedBox::BOX_INFINITE);
29      mManualObj->setVisible( true);
30 
31     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mManualObj);
32 }
33 
34 #ifdef __cplusplus
35  extern "C" {
36  #endif
37 
38  #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
39  #define WIN32_LEAN_AND_MEAN
40 #include "windows.h"
41 
42     INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
43  #else
44      int main( int argc,  char **argv)
45  #endif
46     {
47         SimpleStuffApp app;
48          try {
49             app.go();
50         }  catch( Ogre::Exception& e ) {
51  #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
52             MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL );
53  #else
54             std::cerr << "An exception has occured: " << e.getFullDescription();
55  #endif
56         }
57          return 0;
58     }
59 
60 #ifdef __cplusplus
61 }
62  #endif


http://www.cppblog.com/summericeyl/archive/2010/04/28/113902.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值