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

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>
            亚洲午夜一区| 亚洲第一中文字幕| 一区二区三区欧美亚洲| 欧美国产视频一区二区| 亚洲高清色综合| 欧美韩国日本综合| 欧美激情中文字幕乱码免费| 亚洲精品视频在线播放| 亚洲卡通欧美制服中文| 欧美日韩国产二区| 亚洲欧美亚洲| 久久国产综合精品| 亚洲精品乱码久久久久久按摩观| 亚洲精品午夜| 国产色产综合产在线视频| 欧美激情亚洲另类| 欧美午夜精品久久久久久孕妇| 午夜欧美视频| 久久先锋影音| 亚洲欧美日韩国产一区二区| 久久精品30| 9人人澡人人爽人人精品| 亚洲伊人久久综合| 亚洲人成网站色ww在线| 亚洲曰本av电影| 日韩一级黄色大片| 欧美亚洲免费在线| 亚洲色图制服丝袜| 久久久久久香蕉网| 午夜视频久久久| 欧美.www| 久久免费高清| 欧美性天天影院| 欧美国产欧美综合| 国产欧美日韩不卡免费| 亚洲人体大胆视频| 狠狠色综合色区| 亚洲女爱视频在线| 一区二区三区|亚洲午夜| 久久久久国产一区二区三区四区| 亚洲夜晚福利在线观看| 久久五月婷婷丁香社区| 欧美一区日韩一区| 欧美日韩中国免费专区在线看| 老色鬼精品视频在线观看播放 | 久久精品免费电影| 欧美乱人伦中文字幕在线| 老色批av在线精品| 国模一区二区三区| 午夜精品福利一区二区三区av| 一区二区三区偷拍| 欧美成年网站| 欧美高清视频| 在线精品一区| 久久久九九九九| 久久精品中文字幕免费mv| 国产精品亚洲成人| 亚洲一区二区三区在线播放| 亚洲一区二区在线视频 | 亚洲图片你懂的| 一本色道久久综合| 欧美精品国产精品日韩精品| 欧美激情无毛| 亚洲毛片一区| 欧美激情a∨在线视频播放| 免费亚洲一区| 亚洲国产欧美日韩精品| 免费看av成人| 亚洲激情综合| 一区二区av在线| 欧美性猛交xxxx乱大交蜜桃| 夜夜爽99久久国产综合精品女不卡 | 欧美亚洲视频在线观看| 久久先锋影音av| 亚洲第一页自拍| 久久性天堂网| 亚洲精品之草原avav久久| 一区二区三区成人精品| 国产精品yjizz| 亚洲欧美中文日韩在线| 久久久999| 亚洲国产日韩欧美在线99| 欧美福利视频| 一本久道久久综合中文字幕| 欧美一级久久久久久久大片| 国产真实精品久久二三区| 久久人人爽爽爽人久久久| 亚洲国产二区| 欧美亚洲日本网站| 亚洲电影毛片| 欧美午夜电影在线| 久久gogo国模啪啪人体图| 欧美激情女人20p| 亚洲视频一区二区| 国模套图日韩精品一区二区| 欧美精品粉嫩高潮一区二区| 亚洲视频精选| 毛片av中文字幕一区二区| 在线视频免费在线观看一区二区| 国产精品一区二区久久| 另类av一区二区| 亚洲线精品一区二区三区八戒| 久久香蕉国产线看观看网| 9国产精品视频| 黄色欧美成人| 国产精品久久久久久福利一牛影视 | 亚洲欧美激情视频| 欧美国产日韩一二三区| 午夜视频在线观看一区二区| 亚洲第一二三四五区| 国产精品久久波多野结衣| 久久午夜激情| 欧美一区高清| 亚洲裸体视频| 欧美电影免费观看高清| 小黄鸭视频精品导航| 亚洲精品视频在线观看网站| 国产美女一区二区| 欧美日韩在线不卡| 欧美激情精品久久久久久| 久久精品国产久精国产思思| 99精品国产高清一区二区 | 欧美成在线观看| 久久久久久穴| 久久av资源网站| 夜夜爽99久久国产综合精品女不卡 | 9久re热视频在线精品| 在线精品国精品国产尤物884a| 欧美性猛交视频| 欧美极品在线播放| 欧美14一18处毛片| 久久综合网络一区二区| 午夜精品久久久久久久蜜桃app | 欧美激情国产精品| 久久视频免费观看| 久久精品九九| 欧美一区二区高清在线观看| 亚洲一区二区免费视频| 一本久久a久久精品亚洲| 亚洲精品韩国| 亚洲毛片在线观看.| 亚洲欧洲精品一区二区| 亚洲国产精品福利| 亚洲欧洲久久| 亚洲美女色禁图| 亚洲免费久久| 夜夜嗨av一区二区三区中文字幕 | 欧美日本在线视频| 欧美人体xx| 欧美日韩精品伦理作品在线免费观看 | 亚洲精品国产品国语在线app| 亚洲高清视频一区| 亚洲欧洲一区| av成人免费在线| 亚洲欧美日韩一区二区| 欧美亚洲日本网站| 久久一二三四| 欧美激情在线狂野欧美精品| 欧美日韩精品欧美日韩精品一 | 欧美日韩色一区| 国产精品日韩久久久| 国产日韩欧美电影在线观看| 激情六月婷婷综合| 亚洲国产毛片完整版| 99re8这里有精品热视频免费| 1000部国产精品成人观看| 亚洲国产精品电影| 在线观看日韩av先锋影音电影院| 国产精品一区二区三区久久久| 国产午夜亚洲精品理论片色戒| 亚洲国产99| 亚洲先锋成人| 久久久久久噜噜噜久久久精品| 欧美一区二区在线观看| 久久精品亚洲一区| 亚洲国语精品自产拍在线观看| 一区二区av| 久久综合999| 国产精品美女999| 韩日午夜在线资源一区二区| 亚洲剧情一区二区| 久久久99久久精品女同性| 亚洲国产精品99久久久久久久久| 亚洲私拍自拍| 久久综合狠狠综合久久综合88| 欧美亚日韩国产aⅴ精品中极品| 红桃视频亚洲| 亚洲欧美国产另类| 欧美激情亚洲综合一区| 午夜老司机精品| 欧美日韩国产在线| 亚洲高清久久网| 欧美亚洲一区二区三区| 亚洲欧洲三级| 免费成人av在线看| 国产亚洲欧美日韩精品| 亚洲视频一二区| 最新国产精品拍自在线播放| 久久免费视频在线观看| 国产精品免费一区豆花|