青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

讓我們開始吧

在這一部分,將解釋對(duì)于一個(gè)實(shí)際的基于Ogre的程序而言,是如何構(gòu)建的。

代碼

main()函數(shù)

main.cpp

#include "input.h"
#include "simulation.h"
 
#include "Ogre.h"
 
#include "OgreWindowEventUtilities.h"
 
#if defined(WIN32)
#include "windows.h"
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#else
int main (int argc, char *argv[]) {
#endif
 
        Ogre::Root *ogre;
        Ogre::RenderWindow *window;
        Ogre::SceneManager *sceneMgr;
        Ogre::Camera *camera;
 
        // fire up an Ogre rendering window. Clearing the first two (of three) params will let us 
        // specify plugins and resources in code instead of via text file
        ogre = new Ogre::Root("", "");
 
 
        // This is a VERY minimal rendersystem loading example; we are hardcoding the OpenGL 
        // renderer, instead of loading GL and D3D9. We will add renderer selection support in a 
        // future article.
 
        // I separate the debug and release versions of my plugins using the same "_d" suffix that
        // the Ogre main libraries use; you may need to remove the "_d" in your code, depending on the
        // naming convention you use 
        // EIHORT NOTE: All Ogre DLLs use this suffix convention now -- #ifdef on the basis of the _DEBUG 
        // define
#if defined(_DEBUG)
        ogre->loadPlugin("RenderSystem_GL_d");
#else
        ogre->loadPlugin("RenderSystem_GL");
#endif
 
        Ogre::RenderSystemList *renderSystems = NULL;
        Ogre::RenderSystemList::iterator r_it;
 
        // we do this step just to get an iterator that we can use with setRenderSystem. In a future article
        // we actually will iterate the list to display which renderers are available. 
        renderSystems = ogre->getAvailableRenderers();
        r_it = renderSystems->begin();
        ogre->setRenderSystem(*r_it);
        ogre->initialise(false);
 
        // load common plugins
#if defined(_DEBUG)
        ogre->loadPlugin("Plugin_CgProgramManager_d");               
        ogre->loadPlugin("Plugin_OctreeSceneManager_d");
#else
        ogre->loadPlugin("Plugin_CgProgramManager");          
        ogre->loadPlugin("Plugin_OctreeSceneManager");
#endif
        // load the basic resource location(s)
        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
               "resource", "FileSystem", "General");
        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
               "resource/gui.zip", "Zip", "GUI");
#if defined(WIN32)
        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
               "c:\\windows\\fonts", "FileSystem", "GUI");
#endif
 
        Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
        Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI");
 
        // setup main window; hardcode some defaults for the sake of presentation
        Ogre::NameValuePairList opts;
        opts["resolution"] = "1024x768";
        opts["fullscreen"] = "false";
        opts["vsync"] = "false";
 
        // create a rendering window with the title "CDK"
        window = ogre->createRenderWindow("CDK", 1024, 768, false, &opts);
 
        // since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article 
        // we'll see how to change this
        sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
        camera = sceneMgr->createCamera("camera");
        camera->setNearClipDistance(5);
    Ogre::Viewport* vp = window->addViewport(camera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
 
        // most examples get the viewport size to calculate this; for now, we'll just 
        // set it to 4:3 the easy way
        camera->setAspectRatio((Ogre::Real)1.333333);
 
        // this next bit is for the sake of the input handler
        unsigned long hWnd;
        window->getCustomAttribute("WINDOW", &hWnd);
 
        // set up the input handlers
        Simulation *sim = new Simulation();
        InputHandler *handler = new InputHandler(sim, hWnd);
        sim->requestStateChange(SIMULATION);
 
        while (sim->getCurrentState() != SHUTDOWN) {
               
               handler->capture();
 
               // run the message pump (Eihort)
               Ogre::WindowEventUtilities::messagePump();
 
               ogre->renderOneFrame();
        }
 
        // clean up after ourselves
        delete handler;
        delete sim;
        delete ogre;
 
        return 0;
}

這是最小的程序,它與Ogre教程的第一個(gè)教程是一樣的。

對(duì)于這段代碼的快速掃描,可以看到initialization, resource location setup, and the main loop. 在編譯這個(gè)程序之前,需要加上下面的這些文件"Simulation" declaration (.h) and definition (.cpp) files:

Simulation

simulation.h

#pragma once
 
#include <vector>
#include <map>
 
typedef enum {
        STARTUP,
        GUI,
        LOADING,
        CANCEL_LOADING,
        SIMULATION,
        SHUTDOWN
} SimulationState;
 
class Simulation {
 
public:
        Simulation();
        virtual ~Simulation();
 
public:
        bool requestStateChange(SimulationState state);
        bool lockState();
        bool unlockState();
        SimulationState getCurrentState();
 
        void setFrameTime(float ms);
        inline float getFrameTime() { return m_frame_time; }
 
protected:
        SimulationState m_state;
        bool m_locked;
        float m_frame_time;
};
 
 

simulation.cpp

#include "simulation.h"
#include "OgreStringConverter.h"
 
Simulation::Simulation() {
        m_state = STARTUP;
}
 
Simulation::~Simulation() {
}
 
 
SimulationState Simulation::getCurrentState() {
        return m_state;
}
 
// for the sake of clarity, I am not using actual thread synchronization 
// objects to serialize access to this resource. You would want to protect
// this block with a mutex or critical section, etc.
bool Simulation::lockState() {
        if (m_locked == false) {
 
                m_locked = true;
               return true;
        }
        else
               return false;
}
 
bool Simulation::unlockState() {
        if (m_locked == true) {
               m_locked = false;
               return true;
        }
        else
               return false;
}
 
bool Simulation::requestStateChange(SimulationState newState) {
        if (m_state == STARTUP) {
               m_locked = false;
               m_state = newState;
 
               return true;
        }
 
        // this state cannot be changed once initiated
        if (m_state == SHUTDOWN) {
               return false;
        }
 
        if ((m_state == GUI || m_state == SIMULATION || m_state == LOADING || m_state == CANCEL_LOADING) && 
                       (newState != STARTUP) && (newState != m_state)) {
               m_state = newState;
               return true;
        }
        else
               return false;
}
 
void Simulation::setFrameTime(float ms) {
        m_frame_time = ms;
}
 

"Simulation"類是一個(gè)非常簡(jiǎn)單的“State Manager”類的例子。Simulation (or game) 狀態(tài)只是執(zhí)行的上下文(contexts). States并沒有統(tǒng)一的標(biāo)準(zhǔn),這與你的應(yīng)用程序有關(guān), SHUTDOWN, SIMULATION and GUI 是三個(gè)典型的狀態(tài).

對(duì)于輸入,選取OISOIS對(duì)應(yīng)的輸入文件如下input.h/.cpp:

InputHandler

input.h

#pragma once
 
#include "OISEvents.h"
#include "OISInputManager.h"
#include "OISMouse.h"
#include "OISKeyboard.h"
#include "OISJoyStick.h"
 
class Simulation;
 
class InputHandler : 
               public OIS::MouseListener, 
               public OIS::KeyListener, 
               public OIS::JoyStickListener
{
private:
        OIS::InputManager *m_ois;
        OIS::Mouse *mMouse;
        OIS::Keyboard *mKeyboard;
        unsigned long m_hWnd;
        Simulation *m_simulation;      
public:
        InputHandler(Simulation *sim, unsigned long hWnd); 
        ~InputHandler();
 
        void setWindowExtents(int width, int height) ;
        void capture();
 
        // MouseListener
        bool mouseMoved(const OIS::MouseEvent &evt);
        bool mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID);
        bool mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID);
        
        // KeyListener
        bool keyPressed(const OIS::KeyEvent &evt);
        bool keyReleased(const OIS::KeyEvent &evt);
        
        // JoyStickListener
        bool buttonPressed(const OIS::JoyStickEvent &evt, int index);
        bool buttonReleased(const OIS::JoyStickEvent &evt, int index);
        bool axisMoved(const OIS::JoyStickEvent &evt, int index);
        bool povMoved(const OIS::JoyStickEvent &evt, int index);
};
 
 


input.cpp

#include "input.h"
#include "OgreStringConverter.h"
#include "simulation.h"
 
InputHandler::InputHandler(Simulation *sim, unsigned long hWnd)  {
        
        OIS::ParamList pl;
        pl.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));
        
        m_hWnd = hWnd;
        m_ois = OIS::InputManager::createInputSystem( pl );
        mMouse = static_cast<OIS::Mouse*>(m_ois->createInputObject( OIS::OISMouse, true ));
        mKeyboard = static_cast<OIS::Keyboard*>(m_ois->createInputObject( OIS::OISKeyboard, true));
        mMouse->setEventCallback(this);
        mKeyboard->setEventCallback(this);
 
        m_simulation = sim;
}
 
InputHandler::~InputHandler() {
        if (mMouse)
               delete mMouse;
        if (mKeyboard)
               delete mKeyboard;
        OIS::InputManager::destroyInputSystem(m_ois);
}
 
void InputHandler::capture() {
        mMouse->capture();
        mKeyboard->capture();
}
 
void  InputHandler::setWindowExtents(int width, int height){
        //Set Mouse Region.. if window resizes, we should alter this to reflect as well
        const OIS::MouseState &ms = mMouse->getMouseState();
        ms.width = width;
        ms.height = height;
}
 
 
// MouseListener
bool InputHandler::mouseMoved(const OIS::MouseEvent &evt) {
        return true;
}
 
bool InputHandler::mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID btn) {
        return true;
}
 
bool InputHandler::mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID btn) {
        return true;
}
 
               
// KeyListener
bool InputHandler::keyPressed(const OIS::KeyEvent &evt) {
        return true;
}
 
bool InputHandler::keyReleased(const OIS::KeyEvent &evt) {
        if (evt.key == OIS::KC_ESCAPE)
               m_simulation->requestStateChange(SHUTDOWN);
 
        return true;
}
 
               
 
// JoyStickListener
bool InputHandler::buttonPressed(const OIS::JoyStickEvent &evt, int index) {
        return true;
}
 
bool InputHandler::buttonReleased(const OIS::JoyStickEvent &evt, int index) {
        return true;
}
 
bool InputHandler::axisMoved(const OIS::JoyStickEvent &evt, int index) {
        return true;
}
 
bool InputHandler::povMoved(const OIS::JoyStickEvent &evt, int index) {
        return true;
}
 

這里,我們對(duì)OIS的處理,使用緩存模式(buffered mode),因此我們可以避免遺漏掉輸入事件。而用InputHandler::capture()只取即時(shí)事件,會(huì)清空它們的緩存。

編譯與運(yùn)行代碼

        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
               "resource", "FileSystem", "General");
        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
               "resource/gui.zip", "Zip", "GUI");

如上所述,在初始化中,我們定義了兩個(gè)資源組(resource groups): General and GUI. General 是一直都存在的,也是默認(rèn)的資源組。GUI 是我們創(chuàng)建用于存放GUI內(nèi)容的,在gui.zip中的文件都會(huì)導(dǎo)入這個(gè)資源組。


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


posts - 15, comments - 2, trackbacks - 0, articles - 29

Copyright © 美洲豹

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲第一伊人| 国外成人免费视频| 激情视频一区| 一本久久a久久精品亚洲| 红桃视频一区| 毛片基地黄久久久久久天堂| 久久国产精品99国产精| 国产精品国产精品国产专区不蜜| 欧美国产精品| 伊人男人综合视频网| 欧美一区二区| 久久久久久久久久码影片| 国产精品嫩草影院av蜜臀| 日韩一级视频免费观看在线| 99re66热这里只有精品4| 欧美波霸影院| 亚洲国产精品ⅴa在线观看| 一色屋精品亚洲香蕉网站| 欧美xxxx在线观看| 亚洲视频国产视频| 亚洲男人av电影| 欧美亚一区二区| 在线亚洲激情| 欧美成人一区在线| 亚洲自拍偷拍视频| 国产精品亚洲成人| 性欧美超级视频| 久久综合一区二区三区| 一区二区三区中文在线观看 | 老司机精品视频一区二区三区| 久久亚洲图片| 亚洲国产高清在线| 欧美成人午夜激情在线| 亚洲综合国产| 久久午夜影视| 亚洲女女做受ⅹxx高潮| 在线免费高清一区二区三区| 美女日韩欧美| 欧美在线观看一区二区| 另类亚洲自拍| 篠田优中文在线播放第一区| 国产一区二区精品久久91| 久久久久久久性| 亚洲国产美女精品久久久久∴| 欧美一区二视频| 尤物九九久久国产精品的分类| 欧美午夜在线一二页| 欧美成人a视频| 久久精品水蜜桃av综合天堂| 欧美成人在线影院| 久久精品亚洲| 日韩一级视频免费观看在线| 在线成人免费视频| 国产日韩av一区二区| 久久青草欧美一区二区三区| 亚洲人成网站影音先锋播放| 午夜欧美理论片| 亚洲风情在线资源站| 国产亚洲欧美日韩一区二区| 国产精品视频1区| 欧美日韩中文精品| 久久人人爽人人爽爽久久| 欧美在线视频免费| 欧美亚洲一区在线| 一区二区精品国产| 9久re热视频在线精品| 久久久精品一区| 久久精品一本| 久久免费一区| 亚洲欧美日韩视频二区| 亚洲一区二区少妇| 亚洲激情在线观看| 国产免费成人| 欧美日韩成人综合在线一区二区 | 中日韩高清电影网| 精品动漫3d一区二区三区免费版| 国产午夜精品美女视频明星a级 | 欧美激情亚洲激情| 欧美一区二区大片| 欧美一区二区三区四区在线观看 | 亚洲国产精品久久久| 亚洲高清毛片| 亚洲美女少妇无套啪啪呻吟| 99热免费精品在线观看| 亚洲午夜国产成人av电影男同| 欧美1区视频| 久久精品视频免费观看| 狼狼综合久久久久综合网| 欧美凹凸一区二区三区视频| 亚洲福利视频一区二区| 99视频一区二区三区| 亚洲欧美日韩爽爽影院| 日韩亚洲欧美成人一区| 亚洲视频在线观看免费| 欧美在线播放高清精品| 久久亚洲综合色一区二区三区| 欧美激情精品| 欧美aaa级| 久久综合99re88久久爱| 欧美精品免费在线| 欧美大胆人体视频| 欧美性淫爽ww久久久久无| 国产一区二区三区高清播放| 亚洲国语精品自产拍在线观看| 亚洲理论在线观看| 亚洲精品综合久久中文字幕| 亚洲一级在线观看| 久久亚洲影音av资源网| 亚洲精品乱码久久久久久黑人| 亚洲一二三四久久| 噜噜噜躁狠狠躁狠狠精品视频| 欧美三级午夜理伦三级中文幕| 国产日韩欧美在线播放| 亚洲精品小视频在线观看| 亚洲毛片一区| 久久大逼视频| 亚洲日本欧美| 久久久久久久999| 国产精品啊啊啊| 最新日韩在线视频| 亚洲精品乱码久久久久久| 亚洲欧美一区二区三区久久 | 亚洲男人的天堂在线观看| 久久影院午夜片一区| 9人人澡人人爽人人精品| 久久亚洲电影| 国产一区二区三区不卡在线观看 | 国内一区二区三区| 亚洲视频一二区| 欧美电影打屁股sp| 午夜精品美女自拍福到在线| 欧美另类一区| 国产女人18毛片水18精品| 日韩视频在线播放| 欧美成人精品| 欧美在线在线| 国产美女精品在线| 亚洲婷婷在线| 亚洲人永久免费| 蜜臀久久99精品久久久久久9 | 在线亚洲电影| 欧美精品亚洲| 亚洲欧洲日产国码二区| 久久中文精品| 久久精品毛片| 国产一区二区中文| 国产综合久久久久影院| 亚洲免费在线| 中文日韩在线| 欧美视频四区| 亚洲视频欧洲视频| 亚洲三级影片| 欧美破处大片在线视频| 亚洲人成7777| 亚洲国产高清视频| 欧美91视频| 亚洲精品视频在线看| 亚洲国产91| 欧美极品影院| 一区二区av| 美女视频黄a大片欧美| 一区二区三区色| 欧美偷拍另类| 亚洲欧美在线一区二区| 亚洲网站在线看| 国产精品女人网站| 欧美一区二区三区四区夜夜大片| 亚洲一区久久久| 欧美日韩一区二区三区在线| 亚洲高清自拍| 亚洲欧洲精品一区二区精品久久久| 午夜一区二区三区不卡视频| 国产视频欧美视频| 蜜桃av噜噜一区| 欧美成人性生活| 在线视频一区观看| 亚洲福利视频在线| 欧美人与禽性xxxxx杂性| 亚洲午夜一区| 午夜视频在线观看一区二区三区| 国产综合精品| 亚洲第一偷拍| 国产精品扒开腿做爽爽爽视频| 亚洲欧美日韩国产综合| 先锋资源久久| 亚洲国内自拍| 一区二区三区欧美日韩| 国产欧美日韩视频一区二区| 麻豆精品视频在线观看视频| 欧美大尺度在线| 亚洲欧美综合网| 久久久久亚洲综合| aa级大片欧美三级| 亚洲欧美日韩国产综合精品二区| 在线观看欧美视频| 99精品国产高清一区二区| 国产午夜精品福利| 亚洲精品国久久99热| 国产精品一区久久| 亚洲电影免费观看高清完整版在线 |