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

OGre實際應用程序[四]譯

Posted on 2008-09-06 16:54 美洲豹 閱讀(808) 評論(0)  編輯 收藏 引用

讓我們開始吧

在這一部分,將解釋對于一個實際的基于Ogre的程序而言,是如何構建的。

代碼

main()函數

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教程的第一個教程是一樣的。

對于這段代碼的快速掃描,可以看到initialization, resource location setup, and the main loop. 在編譯這個程序之前,需要加上下面的這些文件"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"類是一個非常簡單的“State Manager”類的例子。Simulation (or game) 狀態只是執行的上下文(contexts). States并沒有統一的標準,這與你的應用程序有關, SHUTDOWN, SIMULATION and GUI 是三個典型的狀態.

對于輸入,選取OISOIS對應的輸入文件如下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;
}
 

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

編譯與運行代碼

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

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


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   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>
            欧美电影免费观看高清| 欧美激情在线免费观看| 亚洲国产精品久久久久秋霞蜜臀| 午夜精品一区二区三区在线| 国产精品欧美经典| 午夜视频久久久久久| 亚洲一区二区三区高清不卡| 国产嫩草影院久久久久 | 亚洲视频一区二区免费在线观看| 欧美黄色小视频| 欧美日韩免费视频| 午夜日韩电影| 久久婷婷国产综合精品青草| 亚洲激情影视| 夜夜嗨av一区二区三区免费区| 国产精品永久入口久久久| 久久九九国产| 欧美日韩国产精品| 欧美中文字幕在线观看| 久久久一二三| 中文在线资源观看网站视频免费不卡| 亚洲一区二区三区涩| 在线看片第一页欧美| 亚洲欧洲一区二区三区久久| 国产精品欧美日韩| 亚洲大黄网站| 国产欧美一区二区视频| 亚洲国产精品va| 国产欧美日韩视频一区二区| 欧美成人精品激情在线观看| 国产精品v日韩精品| 欧美国产成人精品| 国产精品国产三级国产普通话三级 | 国产精品久久久久久户外露出| 久久久精品五月天| 欧美色欧美亚洲另类七区| 久久久久久久久久久一区| 欧美精品一区二区三区蜜桃| 久久久久网站| 国产精品久久综合| 亚洲国产日韩欧美在线99| 国产亚洲美州欧州综合国| 亚洲激情另类| 在线欧美福利| 久久99在线观看| 午夜精品在线看| 欧美日韩精品国产| 欧美α欧美αv大片| 国产精品亚洲综合色区韩国| 亚洲精品婷婷| 亚洲免费观看高清完整版在线观看| 久久精品99国产精品日本| 午夜精品一区二区三区在线| 欧美激情一区二区三区高清视频| 毛片av中文字幕一区二区| 国产区日韩欧美| 亚洲女人av| 亚洲欧美日韩视频二区| 欧美日韩一区在线| 欧美韩国在线| 国产日韩欧美91| 亚洲欧美制服中文字幕| 亚洲主播在线| 国产精品激情| 亚洲宅男天堂在线观看无病毒| 亚洲私人影院| 国产精品久久久久久久久久妞妞| 一区二区三区四区五区视频| 亚洲一区二区少妇| 国产精品乱人伦一区二区| 亚洲一区二区三区乱码aⅴ| 亚洲欧美日韩专区| 国产精品欧美日韩| 欧美亚洲专区| 毛片av中文字幕一区二区| 亚洲国产精品国自产拍av秋霞| 另类专区欧美制服同性| 欧美激情第3页| 亚洲最新视频在线播放| 欧美视频日韩视频| 亚洲欧美另类久久久精品2019| 欧美亚洲在线视频| 黄色小说综合网站| 美日韩精品视频| 亚洲精选在线| 欧美一区二区免费观在线| 国产综合网站| 欧美国产视频一区二区| 99国产一区| 久久精品一区二区三区中文字幕| 狠狠色丁香久久婷婷综合_中| 看片网站欧美日韩| 亚洲毛片在线观看| 欧美在线观看www| 亚洲国产一区二区三区a毛片 | 久久夜色精品一区| 亚洲精品三级| 久久狠狠一本精品综合网| 在线观看欧美精品| 欧美精品二区三区四区免费看视频| 日韩亚洲欧美高清| 久久久久免费视频| 亚洲视频欧美在线| 国产亚洲欧美日韩在线一区| 欧美成人免费播放| 先锋影音久久久| 亚洲国产精品成人一区二区| 欧美亚洲日本国产| 亚洲狼人精品一区二区三区| 国产精品午夜春色av| 久久久www免费人成黑人精品| 亚洲美女电影在线| 麻豆91精品| 欧美一级视频| 一本色道久久88综合亚洲精品ⅰ | 91久久精品一区二区别| 欧美日韩在线直播| 久久偷看各类wc女厕嘘嘘偷窃| 一区二区三区回区在观看免费视频| 免费成人你懂的| 久久高清一区| 亚洲性图久久| 亚洲精品欧美专区| 黄色成人免费观看| 国产精品久久久久国产a级| 美日韩精品免费| 欧美一区网站| 一区二区三区四区五区精品| 亚洲国产毛片完整版| 久久久精品一区| 午夜电影亚洲| 亚洲淫片在线视频| 亚洲无玛一区| 亚洲视频在线观看视频| 亚洲精品在线观看视频| 1204国产成人精品视频| 国产午夜精品一区理论片飘花| 国产精品二区在线观看| 欧美日韩一区二区三区四区在线观看| 麻豆freexxxx性91精品| 久久五月婷婷丁香社区| 久久精品一区二区三区四区 | 美女诱惑黄网站一区| 久久全球大尺度高清视频| 久久久噜噜噜久久中文字幕色伊伊 | 欧美激情中文字幕一区二区| 久久综合精品一区| 久久免费视频在线| 久久午夜精品| 鲁大师成人一区二区三区| 狂野欧美一区| 欧美aa在线视频| 欧美日韩国产欧| 欧美视频一区在线观看| 国产精品免费看| 国产一区二区在线观看免费| 黄色一区三区| 亚洲日本激情| 亚洲一区在线免费观看| 午夜精品视频网站| 久久亚洲美女| 亚洲国产精品久久久久秋霞不卡 | 欧美大片免费久久精品三p| 欧美黑人多人双交| 亚洲精选一区| 午夜精品一区二区三区四区| 久久久久久噜噜噜久久久精品| 久久综合一区| 欧美日韩亚洲一区| 国产午夜亚洲精品不卡| 在线免费观看欧美| 夜夜嗨av一区二区三区免费区| 亚洲女人天堂成人av在线| 久久在线视频在线| 亚洲欧洲日产国码二区| 亚洲综合色丁香婷婷六月图片| 欧美在线国产| 欧美全黄视频| 黄色欧美成人| 中文亚洲欧美| 免费不卡在线观看av| aa级大片欧美三级| 久久精品国产一区二区三区| 欧美精品一区二区久久婷婷| 国产女精品视频网站免费| 在线成人小视频| 午夜精品久久久久久久99黑人| 免费成人性网站| 亚洲一本视频| 欧美激情1区2区3区| 国内外成人在线| 亚洲视频在线观看网站| 欧美高清在线播放| 欧美一区二区国产| 欧美日韩视频一区二区三区| 在线不卡中文字幕| 久久国产手机看片| 99成人在线| 欧美精品免费播放| 在线免费观看视频一区|