OGRE学习(一)

12.15

因为以后工作的需要,需要熟悉OGRE引擎。先从熟悉SDK的使用入手吧。

OgreSDK1.7.1提供的Sample,繁杂的内容过多。我列了个简单的代码,暂能够跑一个简单的OGRE程序(新手一定很喜欢^__^)。代码如下:

//-----------------------------------------------------------------------------------------------------------------------

#include "OgrePrerequisites.h"
#include "OgreRoot.h"
#include "OgreWindowEventUtilities.h"
#include "OgreRenderWindow.h"
#include "OgreSceneManager.h"
#include "OgreCamera.h"
#include "OIS/OIS.h"
#include "windows.h"

Ogre::Root* mRoot;              // OGRE root
Ogre::RenderWindow* mWindow;    // render window
Ogre::SceneManager* mSceneMgr;
Ogre::Camera *mCamera;
OIS::InputManager* mInputMgr;   // OIS input manager

INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
    mRoot = 0;
    mWindow = 0;
    Ogre::String pluginsPath = Ogre::StringUtil::BLANK;
    #ifdef _DEBUG
        mRoot = OGRE_NEW Ogre::Root("plugins_d.cfg");
    #else
        mRoot = OGRE_NEW Ogre::Root();
    #endif
    mRoot->showConfigDialog();
    mWindow = mRoot->initialise(true);
    mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "MySceneManager");
    mCamera = mSceneMgr->createCamera("MainCam");
    mCamera->setAspectRatio(1.333333f);
    mCamera->setFOVy(Ogre::Radian(45.0f));
    mCamera->setNearClipDistance(1.0f);
    mCamera->setFarClipDistance(1000.0f);
    mCamera->setPosition(0, 10, 0);
    Ogre::Viewport * vp1 = mWindow->addViewport(mCamera);
    Ogre::Viewport * vp2 = mWindow->addViewport(mCamera,1,0.5f,0.0f,0.5f,0.5f);
    Ogre::Viewport * vp3 = mWindow->addViewport(mCamera,2,0.0f,0.5f,0.5f,0.5f);
    Ogre::Viewport * vp4 = mWindow->addViewport(mCamera,3,0.5f,0.5f,0.5f,0.5f);
    vp1->setBackgroundColour(Ogre::ColourValue());
    vp2->setBackgroundColour(Ogre::ColourValue(0.0,0.0,1.0));
    vp3->setBackgroundColour(Ogre::ColourValue(0.0,1.0,1.0));
    vp4->setBackgroundColour(Ogre::ColourValue(1.0,0.0,1.0));

    bool run =true;
    while ( run )
    {   
        Ogre::WindowEventUtilities::messagePump();
        if (!mRoot->_fireFrameStarted())
            break;
        if ( mWindow->isClosed() )
            break;
        if (!mRoot->_updateAllRenderTargets())
            break;
        if (!mRoot->_fireFrameEnded())
            break;
        //mWindow->update();

    }
    //mRoot->startRendering();    // start the render loop

    mRoot->saveConfig();
    mRoot->shutdown();
    if (mRoot) OGRE_DELETE mRoot;

    return 0;
}

//-----------------------------------------------------------------------------------------------------------------------

运行界面:

image

 

      另外,抽空理了理OGRE的一些要素,以下是官方提供的一张框架图,做为参考。

      Ogre中Root挂了很多Node,Node下可以挂其他的Node。这些Node一般是可绘制的节点,称之为Renderable,Node通常又包含了一些MovableObject,

MovableObject可以是Camera,Light,Entity(包含了位置、选择等信息)等。Node通常又拥有一个AABB(可通过MovableObject及子Node节点的AABB算出),这个AABB供SceneManager进行可见性判断。如果可见的话,Node(Renderable)被放入一个Map组织的渲染队列RenderQueue,RenderQueue会针对Renderable的情况排序。最后再统一批次做Renderable的渲染。

image

posted @ 2010-12-15 15:51  Dawnli  阅读(1001)  评论(2编辑  收藏  举报