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

OGre實際應用程序[四]譯

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

讓我們開始吧

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

代碼

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

對于這段代碼的快速掃描,可以看到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) 狀態(tài)只是執(zhí)行的上下文(contexts). States并沒有統(tǒng)一的標準,這與你的應用程序有關, SHUTDOWN, SIMULATION and GUI 是三個典型的狀態(tài).

對于輸入,選取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 是我們創(chuàng)建用于存放GUI內容的,在gui.zip中的文件都會導入這個資源組。

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>
            久久久精品日韩| 国产一区二区三区免费不卡| 一区二区三区黄色| 亚洲精品国产视频| 亚洲高清电影| 最新国产乱人伦偷精品免费网站 | 欧美α欧美αv大片| 欧美 日韩 国产精品免费观看| 久久免费视频在线| 欧美黄色网络| 99re66热这里只有精品3直播 | 久久躁狠狠躁夜夜爽| 久久久噜噜噜久久中文字幕色伊伊 | 久久超碰97中文字幕| 久久久久网址| 欧美激情四色| 国产精品久久久久aaaa九色| 国内精品久久久久久久97牛牛| 亚洲第一天堂av| 一本色道久久88综合日韩精品| 欧美亚洲自偷自偷| 欧美激情视频一区二区三区在线播放| 欧美国产精品| 亚洲伊人网站| 欧美~级网站不卡| 国产精品一二三四| 亚洲欧洲美洲综合色网| 午夜在线视频一区二区区别| 欧美国产第一页| 欧美一级久久久| 欧美日韩一区二区三区四区在线观看| 国产亚洲一区二区在线观看| 亚洲美女av黄| 久久久无码精品亚洲日韩按摩| 亚洲高清资源综合久久精品| 亚洲综合大片69999| 免费观看欧美在线视频的网站| 欧美日韩在线另类| 亚洲第一福利视频| 久久精品国产在热久久| 亚洲精品国产无天堂网2021| 久久九九电影| 麻豆国产精品777777在线| 欧美精品一区二区三区蜜臀| 国产精品高精视频免费| 国产视频综合在线| 亚洲素人一区二区| 欧美大胆成人| 久久久久青草大香线综合精品| 国产欧美一区二区三区沐欲 | 欧美成人自拍视频| 韩日成人在线| 久久婷婷国产麻豆91天堂| 一区二区精品| 欧美日韩一区在线观看| 亚洲精品久久嫩草网站秘色| 久久在线视频在线| 欧美在线亚洲| 国产婷婷一区二区| 欧美一区免费视频| 亚洲一区二区精品视频| 欧美日韩国产大片| 亚洲最新视频在线播放| 亚洲欧洲精品一区二区三区不卡| 久久视频国产精品免费视频在线| 国产日韩成人精品| 久久免费视频在线| 久久国产精彩视频| 黄色一区二区在线| 另类尿喷潮videofree| 久久精品免费| 亚洲国产小视频| 亚洲国产一二三| 欧美日韩高清在线一区| 亚洲综合久久久久| 亚洲影院在线观看| 国产一区二区日韩精品欧美精品| 欧美一区二区三区四区在线观看地址 | 亚洲精品资源| 亚洲国产高清在线观看视频| 免费成人av在线| 99精品国产在热久久| 99国产一区二区三精品乱码| 国产精品女人毛片| 久久久久久夜精品精品免费| 久久综合九色综合欧美狠狠| 99国产精品视频免费观看| 一本色道**综合亚洲精品蜜桃冫| 国产精品乱码久久久久久| 久久久蜜桃精品| 麻豆乱码国产一区二区三区| 日韩视频精品在线| 亚洲欧美国产精品桃花| 精品9999| 亚洲美女免费视频| 国产午夜亚洲精品羞羞网站| 亚洲第一成人在线| 国产精品专区h在线观看| 一区二区三区精密机械公司 | 欧美极品一区二区三区| 一区二区三区欧美在线| 欧美中文在线观看| 一区二区三区精品视频在线观看| 亚洲欧美日韩国产综合| 亚洲美女视频在线观看| 午夜国产不卡在线观看视频| 亚洲第一在线综合网站| 亚洲影视在线播放| 99在线精品免费视频九九视| 久久国产视频网| 亚洲影音一区| 女人香蕉久久**毛片精品| 午夜视频一区二区| 欧美伦理视频网站| 久久久噜噜噜久久中文字幕色伊伊| 欧美日韩高清在线| 欧美激情中文字幕乱码免费| 国产日韩在线播放| 日韩午夜激情| 亚洲精品乱码久久久久| 欧美一区二区成人| 一区二区三区免费观看| 久久亚洲色图| 久久久免费精品视频| 国产精品一区免费视频| 亚洲人成7777| 亚洲成人影音| 久久久久久亚洲综合影院红桃| 亚洲免费在线视频一区 二区| 老色鬼精品视频在线观看播放| 久久精品女人的天堂av| 国产精品美女| 宅男66日本亚洲欧美视频| 999亚洲国产精| 久久久噜噜噜久久| 蜜桃av一区二区三区| 国内视频一区| 久久不射网站| 久久亚洲综合色| 国内精品视频一区| 久久精品国产v日韩v亚洲 | 99pao成人国产永久免费视频| 亚洲日本va在线观看| 久久嫩草精品久久久精品一 | 亚洲欧美国产三级| 欧美怡红院视频| 国产视频综合在线| 欧美在线精品一区| 免费成人黄色片| 亚洲国产成人porn| 欧美韩国日本综合| 亚洲美女91| 午夜精品久久久久久99热软件| 欧美视频一区二| 亚洲免费影院| 美女精品视频一区| 亚洲乱码久久| 欧美天天视频| 久久精品在线观看| 欧美激情小视频| 亚洲美女精品一区| 午夜伦欧美伦电影理论片| 国产精品大片免费观看| 欧美一区二区大片| 亚洲国产精品成人va在线观看| 99riav1国产精品视频| 欧美体内she精视频在线观看| 午夜在线一区二区| 欧美国产1区2区| 亚洲男人av电影| 国语自产精品视频在线看一大j8| 你懂的亚洲视频| 亚洲一区二区三区四区中文| 久久在线播放| 一区二区三区国产在线观看| 国产午夜精品全部视频播放 | 国产美女精品| 久久久久国内| 亚洲一区二区久久| 欧美大片免费观看| 亚洲综合色视频| 最近看过的日韩成人| 国产午夜精品美女毛片视频| 欧美激情一区二区| 久久精品在线播放| 在线亚洲国产精品网站| 免费国产一区二区| 欧美一级专区| 亚洲先锋成人| 亚洲久久视频| 亚洲国产视频直播| 在线观看成人小视频| 国产精品一区三区| 欧美午夜精品一区二区三区| 欧美xx69| 免费在线看成人av| 久久精品国产77777蜜臀| 亚洲一区二区成人| 国产精品99久久久久久久女警| 欧美电影在线免费观看网站|