原先打算把CEGUI用到MFC Activex中,然后做成WEB3D,但是不成功,在MFC应用程序中没有问题,在IE就出错,这个是我写的一个简单的例子,只是实现了嵌入,其他功能比如鼠标键盘事件都没有处理,整合几个例子而成,目的在于测试,感兴趣的自己可以研究一下

 Code
Code BaseApplication.h
BaseApplication.h

 /**//*
/**//* -----------------------------------------------------------------------------
----------------------------------------------------------------------------- Filename:    BaseApplication.h
Filename:    BaseApplication.h -----------------------------------------------------------------------------
-----------------------------------------------------------------------------
 This source file is generated by the Ogre AppWizard.
This source file is generated by the Ogre AppWizard.
 Check out: http://conglomerate.berlios.de/wiki/doku.php?id=ogrewizards
Check out: http://conglomerate.berlios.de/wiki/doku.php?id=ogrewizards
 Based on the Example Framework for OGRE
Based on the Example Framework for OGRE (Object-oriented Graphics Rendering Engine)
(Object-oriented Graphics Rendering Engine)
 Copyright (c) 2000-2007 The OGRE Team
Copyright (c) 2000-2007 The OGRE Team For the latest info, see http://www.ogre3d.org/
For the latest info, see http://www.ogre3d.org/
 You may use this sample code for anything you like, it is not covered by the
You may use this sample code for anything you like, it is not covered by the LGPL like the rest of the OGRE engine.
LGPL like the rest of the OGRE engine. -----------------------------------------------------------------------------
----------------------------------------------------------------------------- */
*/ #ifndef __BaseApplication_h_
#ifndef __BaseApplication_h_ #define __BaseApplication_h_
#define __BaseApplication_h_
 #include <ogre.h>
#include <ogre.h> #include <OgreStringConverter.h>
#include <OgreStringConverter.h> #include <OgreException.h>
#include <OgreException.h>
 //Use this define to signify OIS will be used as a DLL
//Use this define to signify OIS will be used as a DLL //(so that dll import/export macros are in effect)
//(so that dll import/export macros are in effect) #define OIS_DYNAMIC_LIB
#define OIS_DYNAMIC_LIB #include <OIS/OIS.h>
#include <OIS/OIS.h>
 using namespace Ogre;
using namespace Ogre;
 #include <CEGUI.h>
#include <CEGUI.h> #include <CEGUISystem.h>
#include <CEGUISystem.h> #include <CEGUISchemeManager.h>
#include <CEGUISchemeManager.h> #include <OgreCEGUIRenderer.h>
#include <OgreCEGUIRenderer.h>
 class BaseApplication : public Ogre::Singleton<BaseApplication>,  public FrameListener, public WindowEventListener, public OIS::KeyListener, public OIS::MouseListener
class BaseApplication : public Ogre::Singleton<BaseApplication>,  public FrameListener, public WindowEventListener, public OIS::KeyListener, public OIS::MouseListener

 {
{ public:
public: BaseApplication(void);
    BaseApplication(void); virtual ~BaseApplication(void);
    virtual ~BaseApplication(void);
 virtual void go(void);
    virtual void go(void); void SetWnd(HWND w);
    void SetWnd(HWND w); protected:
protected: virtual bool setup();
    virtual bool setup(); virtual bool configure(void);
    virtual bool configure(void); virtual void chooseSceneManager(void);
    virtual void chooseSceneManager(void); virtual void createCamera(void);
    virtual void createCamera(void); virtual void createFrameListener(void);
    virtual void createFrameListener(void); virtual void createScene(void) = 0; // Override me!
    virtual void createScene(void) = 0; // Override me! virtual void destroyScene(void);
    virtual void destroyScene(void); virtual void createViewports(void);
    virtual void createViewports(void); virtual void setupResources(void);
    virtual void setupResources(void); virtual void createResourceListener(void);
    virtual void createResourceListener(void); virtual void loadResources(void);
    virtual void loadResources(void); virtual void updateStats(void);
    virtual void updateStats(void); virtual bool processUnbufferedKeyInput(const FrameEvent& evt);
    virtual bool processUnbufferedKeyInput(const FrameEvent& evt); virtual bool processUnbufferedMouseInput(const FrameEvent& evt);
    virtual bool processUnbufferedMouseInput(const FrameEvent& evt); virtual void moveCamera();
    virtual void moveCamera(); virtual bool frameStarted(const FrameEvent& evt);
    virtual bool frameStarted(const FrameEvent& evt); virtual bool frameEnded(const FrameEvent& evt);
    virtual bool frameEnded(const FrameEvent& evt);
 void showDebugOverlay(bool show);
    void showDebugOverlay(bool show); void switchMouseMode();
    void switchMouseMode(); void switchKeyMode();
    void switchKeyMode(); bool keyPressed( const OIS::KeyEvent &arg );
    bool keyPressed( const OIS::KeyEvent &arg ); bool keyReleased( const OIS::KeyEvent &arg );
    bool keyReleased( const OIS::KeyEvent &arg ); bool mouseMoved( const OIS::MouseEvent &arg );
    bool mouseMoved( const OIS::MouseEvent &arg ); bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
    bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ); bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
    bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
 //Adjust mouse clipping area
    //Adjust mouse clipping area virtual void windowResized(RenderWindow* rw);
    virtual void windowResized(RenderWindow* rw); //Unattach OIS before window shutdown (very important under Linux)
    //Unattach OIS before window shutdown (very important under Linux) virtual void windowClosed(RenderWindow* rw);
    virtual void windowClosed(RenderWindow* rw);
 void requestShutdown(void);
    void requestShutdown(void); void setupEventHandlers(void);
    void setupEventHandlers(void); bool handleQuit(const CEGUI::EventArgs& e);
    bool handleQuit(const CEGUI::EventArgs& e);
 Root *mRoot;
    Root *mRoot; Camera* mCamera;
    Camera* mCamera; SceneManager* mSceneMgr;
    SceneManager* mSceneMgr; RenderWindow* mWindow;
    RenderWindow* mWindow; CEGUI::System* mGUISystem;
    CEGUI::System* mGUISystem; CEGUI::Renderer* mGUIRenderer;
    CEGUI::Renderer* mGUIRenderer; bool mShutdownRequested;
    bool mShutdownRequested; int mSceneDetailIndex ;
    int mSceneDetailIndex ; Real mMoveSpeed;
    Real mMoveSpeed; Degree mRotateSpeed;
    Degree mRotateSpeed; Overlay* mDebugOverlay;
    Overlay* mDebugOverlay; std::string mDebugText;
    std::string mDebugText; //OIS Input devices
    //OIS Input devices OIS::InputManager* mInputManager;
    OIS::InputManager* mInputManager; OIS::Mouse*    mMouse;
    OIS::Mouse*    mMouse; OIS::Keyboard* mKeyboard;
    OIS::Keyboard* mKeyboard; Vector3 mTranslateVector;
    Vector3 mTranslateVector; bool mStatsOn;
    bool mStatsOn; bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
    bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn; unsigned int mNumScreenShots;
    unsigned int mNumScreenShots; float mMoveScale;
    float mMoveScale; Degree mRotScale;
    Degree mRotScale; Real mTimeUntilNextToggle; // just to stop toggles flipping too fast
    Real mTimeUntilNextToggle; // just to stop toggles flipping too fast Radian mRotX, mRotY;
    Radian mRotX, mRotY; TextureFilterOptions mFiltering;
    TextureFilterOptions mFiltering; int mAniso;
    int mAniso; HWND wnd;
    HWND wnd; };
};
 #endif // #ifndef __BaseApplication_h_
#endif // #ifndef __BaseApplication_h_

 Code
Code
 /**//*
/**//* -----------------------------------------------------------------------------
----------------------------------------------------------------------------- Filename:    BaseApplication.cpp
Filename:    BaseApplication.cpp -----------------------------------------------------------------------------
-----------------------------------------------------------------------------
 This source file is generated by the Ogre AppWizard.
This source file is generated by the Ogre AppWizard.
 Check out: http://conglomerate.berlios.de/wiki/doku.php?id=ogrewizards
Check out: http://conglomerate.berlios.de/wiki/doku.php?id=ogrewizards
 Based on the Example Framework for OGRE
Based on the Example Framework for OGRE (Object-oriented Graphics Rendering Engine)
(Object-oriented Graphics Rendering Engine)
 Copyright (c) 2000-2007 The OGRE Team
Copyright (c) 2000-2007 The OGRE Team For the latest info, see http://www.ogre3d.org/
For the latest info, see http://www.ogre3d.org/
 You may use this sample code for anything you like, it is not covered by the
You may use this sample code for anything you like, it is not covered by the LGPL like the rest of the OGRE engine.
LGPL like the rest of the OGRE engine. -----------------------------------------------------------------------------
----------------------------------------------------------------------------- */
*/
 #include "stdafx.h"
#include "stdafx.h" #include "BaseApplication.h"
#include "BaseApplication.h"


 template<> BaseApplication* Ogre::Singleton<BaseApplication>::ms_Singleton = 0;
template<> BaseApplication* Ogre::Singleton<BaseApplication>::ms_Singleton = 0;
 CEGUI::MouseButton convertOISMouseButtonToCegui(int buttonID)
CEGUI::MouseButton convertOISMouseButtonToCegui(int buttonID)

 {
{ switch (buttonID)
    switch (buttonID)
 
     {
{ case 0: return CEGUI::LeftButton;
    case 0: return CEGUI::LeftButton; case 1: return CEGUI::RightButton;
    case 1: return CEGUI::RightButton; case 2:    return CEGUI::MiddleButton;
    case 2:    return CEGUI::MiddleButton; case 3: return CEGUI::X1Button;
    case 3: return CEGUI::X1Button; default: return CEGUI::LeftButton;
    default: return CEGUI::LeftButton; }
    } }
}
 //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- BaseApplication::BaseApplication(void)
BaseApplication::BaseApplication(void) : mRoot(0),
    : mRoot(0), mCamera(0),
    mCamera(0), mSceneMgr(0),
    mSceneMgr(0), mWindow(0),
    mWindow(0), mGUISystem(0),
    mGUISystem(0), mGUIRenderer(0),
    mGUIRenderer(0), mShutdownRequested(false),
    mShutdownRequested(false), mSceneDetailIndex(0),
    mSceneDetailIndex(0), mMoveSpeed(100),
    mMoveSpeed(100), mRotateSpeed(36),
    mRotateSpeed(36), mDebugOverlay(0),
    mDebugOverlay(0), mDebugText(""),
    mDebugText(""), mInputManager(0),
    mInputManager(0), mMouse(0),
    mMouse(0), mKeyboard(0),
    mKeyboard(0), mTranslateVector(Vector3::ZERO),
    mTranslateVector(Vector3::ZERO), mStatsOn(true),
    mStatsOn(true), mUseBufferedInputKeys(false),
    mUseBufferedInputKeys(false), mUseBufferedInputMouse(false),
    mUseBufferedInputMouse(false), mInputTypeSwitchingOn(false),
    mInputTypeSwitchingOn(false), mNumScreenShots(0),
    mNumScreenShots(0), mMoveScale(0.0f),
    mMoveScale(0.0f), mRotScale(0.0f),
    mRotScale(0.0f), mTimeUntilNextToggle(0),
    mTimeUntilNextToggle(0), mRotX(0),
    mRotX(0), mRotY(0),
    mRotY(0), mFiltering(TFO_BILINEAR),
    mFiltering(TFO_BILINEAR), mAniso(1)
    mAniso(1)

 {
{ }
}
 //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- BaseApplication::~BaseApplication(void)
BaseApplication::~BaseApplication(void)

 {
{ //Remove ourself as a Window listener
    //Remove ourself as a Window listener WindowEventUtilities::removeWindowEventListener(mWindow, this);
    WindowEventUtilities::removeWindowEventListener(mWindow, this); windowClosed(mWindow);
    windowClosed(mWindow); if(mGUISystem)
    if(mGUISystem)
 
     {
{ delete mGUISystem;
        delete mGUISystem; mGUISystem = 0;
        mGUISystem = 0; }
    } if(mGUIRenderer)
    if(mGUIRenderer)
 
     {
{ delete mGUIRenderer;
        delete mGUIRenderer; mGUIRenderer = 0;
        mGUIRenderer = 0; }
    } delete mRoot;
    delete mRoot; }
} void BaseApplication::SetWnd(HWND w)
void BaseApplication::SetWnd(HWND w)

 {
{ wnd =w;
 wnd =w; }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::configure(void)
bool BaseApplication::configure(void)

 {
{ // Show the configuration dialog and initialise the system
    // Show the configuration dialog and initialise the system // You can skip this and use root.restoreConfig() to load configuration
    // You can skip this and use root.restoreConfig() to load configuration // settings if you were sure there are valid ones saved in ogre.cfg
    // settings if you were sure there are valid ones saved in ogre.cfg if(mRoot->showConfigDialog())
        if(mRoot->showConfigDialog())
 
         {
{ // If returned true, user clicked OK so initialise
        // If returned true, user clicked OK so initialise // Here we choose to let the system create a default rendering window by passing 'true'
        // Here we choose to let the system create a default rendering window by passing 'true' mWindow = mRoot->initialise(false);
        mWindow = mRoot->initialise(false); NameValuePairList parms;
    NameValuePairList parms; parms["externalWindowHandle"] = StringConverter::toString((long)this->wnd);
    parms["externalWindowHandle"] = StringConverter::toString((long)this->wnd);
 
     mWindow = mRoot->createRenderWindow("MFC", 300, 300, false, &parms);
    mWindow = mRoot->createRenderWindow("MFC", 300, 300, false, &parms); // Let's add a nice window icon
        // Let's add a nice window icon
 
       return true;
        return true; }
    } else
    else
 
     {
{ return false;
        return false; }
    } }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::chooseSceneManager(void)
void BaseApplication::chooseSceneManager(void)

 {
{ // Get the SceneManager, in this case a generic one
    // Get the SceneManager, in this case a generic one mSceneMgr = mRoot->createSceneManager(ST_GENERIC);
    mSceneMgr = mRoot->createSceneManager(ST_GENERIC); }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::createCamera(void)
void BaseApplication::createCamera(void)

 {
{ // Create the camera
    // Create the camera mCamera = mSceneMgr->createCamera("PlayerCam");
    mCamera = mSceneMgr->createCamera("PlayerCam");
 // Position it at 500 in Z direction
    // Position it at 500 in Z direction mCamera->setPosition(Vector3(0,0,80));
    mCamera->setPosition(Vector3(0,0,80)); // Look back along -Z
    // Look back along -Z mCamera->lookAt(Vector3(0,0,-300));
    mCamera->lookAt(Vector3(0,0,-300)); mCamera->setNearClipDistance(5);
    mCamera->setNearClipDistance(5);
 }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::createFrameListener(void)
void BaseApplication::createFrameListener(void)

 {
{ mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
    mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); mUseBufferedInputKeys = false;
    mUseBufferedInputKeys = false; mUseBufferedInputMouse = true;
    mUseBufferedInputMouse = true; mInputTypeSwitchingOn = mUseBufferedInputKeys || mUseBufferedInputMouse;
    mInputTypeSwitchingOn = mUseBufferedInputKeys || mUseBufferedInputMouse; mRotateSpeed = 36;
    mRotateSpeed = 36; mMoveSpeed = 100;
    mMoveSpeed = 100;
 using namespace OIS;
    using namespace OIS;
 LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); //ParamList pl;
    //ParamList pl; //size_t windowHnd = 0;
    //size_t windowHnd = 0; //std::ostringstream windowHndStr;
    //std::ostringstream windowHndStr;
 //mWindow->getCustomAttribute("WINDOW", &windowHnd);
    //mWindow->getCustomAttribute("WINDOW", &windowHnd); //windowHndStr << windowHnd;
    //windowHndStr << windowHnd; //pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    //pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
 //mInputManager = InputManager::createInputSystem( pl );
    //mInputManager = InputManager::createInputSystem( pl );
 //mKeyboard = static_cast<Keyboard*>(mInputManager->createInputObject( OISKeyboard, mUseBufferedInputKeys ));
    //mKeyboard = static_cast<Keyboard*>(mInputManager->createInputObject( OISKeyboard, mUseBufferedInputKeys )); //mMouse = static_cast<Mouse*>(mInputManager->createInputObject( OISMouse, mUseBufferedInputMouse ));
    //mMouse = static_cast<Mouse*>(mInputManager->createInputObject( OISMouse, mUseBufferedInputMouse ));
 //mMouse->setEventCallback(this);
    //mMouse->setEventCallback(this); //mKeyboard->setEventCallback(this);
    //mKeyboard->setEventCallback(this);
 mShutdownRequested = false;
    mShutdownRequested = false; //Set initial mouse clipping size
    //Set initial mouse clipping size windowResized(mWindow);
    windowResized(mWindow);
 //Register as a Window listener
    //Register as a Window listener WindowEventUtilities::addWindowEventListener(mWindow, this);
    WindowEventUtilities::addWindowEventListener(mWindow, this);
 mStatsOn = true;
    mStatsOn = true; mNumScreenShots = 0;
    mNumScreenShots = 0; mTimeUntilNextToggle = 0;
    mTimeUntilNextToggle = 0; mSceneDetailIndex = 0;
    mSceneDetailIndex = 0; mMoveScale = 0.0f;
    mMoveScale = 0.0f; mRotScale = 0.0f;
    mRotScale = 0.0f; mTranslateVector = Vector3::ZERO;
    mTranslateVector = Vector3::ZERO; mAniso = 1;
    mAniso = 1; mFiltering = TFO_BILINEAR;
    mFiltering = TFO_BILINEAR;
 showDebugOverlay(true);
    showDebugOverlay(true); mRoot->addFrameListener(this);
    mRoot->addFrameListener(this); }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::destroyScene(void)
void BaseApplication::destroyScene(void)

 {
{ }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::createViewports(void)
void BaseApplication::createViewports(void)

 {
{ // Create one viewport, entire window
    // Create one viewport, entire window Viewport* vp = mWindow->addViewport(mCamera);
    Viewport* vp = mWindow->addViewport(mCamera); vp->setBackgroundColour(ColourValue(0,0,0));
    vp->setBackgroundColour(ColourValue(0,0,0));
 // Alter the camera aspect ratio to match the viewport
    // Alter the camera aspect ratio to match the viewport mCamera->setAspectRatio(
    mCamera->setAspectRatio( Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
        Real(vp->getActualWidth()) / Real(vp->getActualHeight())); }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::setupResources(void)
void BaseApplication::setupResources(void)

 {
{ // Load resource paths from config file
    // Load resource paths from config file ConfigFile cf;
    ConfigFile cf; cf.load("resources.cfg");
    cf.load("resources.cfg");
 // Go through all sections & settings in the file
    // Go through all sections & settings in the file ConfigFile::SectionIterator seci = cf.getSectionIterator();
    ConfigFile::SectionIterator seci = cf.getSectionIterator();
 String secName, typeName, archName;
    String secName, typeName, archName; while (seci.hasMoreElements())
    while (seci.hasMoreElements())
 
     {
{ secName = seci.peekNextKey();
        secName = seci.peekNextKey(); ConfigFile::SettingsMultiMap *settings = seci.getNext();
        ConfigFile::SettingsMultiMap *settings = seci.getNext(); ConfigFile::SettingsMultiMap::iterator i;
        ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i)
        for (i = settings->begin(); i != settings->end(); ++i)
 
         {
{ typeName = i->first;
            typeName = i->first; archName = i->second;
            archName = i->second; ResourceGroupManager::getSingleton().addResourceLocation(
            ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
                archName, typeName, secName); }
        } }
    } }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::createResourceListener(void)
void BaseApplication::createResourceListener(void)

 {
{
 }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::loadResources(void)
void BaseApplication::loadResources(void)

 {
{ ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::go(void)
void BaseApplication::go(void)

 {
{ if (!setup())
    if (!setup()) return;
        return;
 //showDebugOverlay(true);
    //showDebugOverlay(true);
 //mRoot->startRendering();
    //mRoot->startRendering(); mWindow->setActive(true);
        mWindow->setActive(true); mWindow->update();
    mWindow->update();
 // clean up
    // clean up //destroyScene();
    //destroyScene(); }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::setup(void)
bool BaseApplication::setup(void)

 {
{ mRoot = new Root();
    mRoot = new Root();
 setupResources();
    setupResources();
 bool carryOn = configure();
    bool carryOn = configure(); if (!carryOn) return false;
    if (!carryOn) return false;
 chooseSceneManager();
    chooseSceneManager(); createCamera();
    createCamera(); createViewports();
    createViewports();
 // Set default mipmap level (NB some APIs ignore this)
    // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5);
    TextureManager::getSingleton().setDefaultNumMipmaps(5);
 // Create any resource listeners (for loading screens)
    // Create any resource listeners (for loading screens) createResourceListener();
    createResourceListener(); // Load resources
    // Load resources loadResources();
    loadResources();
 // Create the scene
    // Create the scene createScene();
    createScene();
 createFrameListener();
    createFrameListener();
 return true;
    return true; };
}; //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::updateStats(void)
void BaseApplication::updateStats(void)

 {
{ static String currFps = "Current FPS: ";
    static String currFps = "Current FPS: "; static String avgFps = "Average FPS: ";
    static String avgFps = "Average FPS: "; static String bestFps = "Best FPS: ";
    static String bestFps = "Best FPS: "; static String worstFps = "Worst FPS: ";
    static String worstFps = "Worst FPS: "; static String tris = "Triangle Count: ";
    static String tris = "Triangle Count: ";
 // update stats when necessary
    // update stats when necessary
 try
    try  {
{ OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps");
        OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps");
        OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps");
        OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps");
        OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps");
 const RenderTarget::FrameStats& stats = mWindow->getStatistics();
        const RenderTarget::FrameStats& stats = mWindow->getStatistics();
 guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
        guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS));
        guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)
        guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) +" "+StringConverter::toString(stats.bestFrameTime)+" ms");
            +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)
        guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
            +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
 OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris");
        OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris"); guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
        guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
 OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
        OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); guiDbg->setCaption(mDebugText);
        guiDbg->setCaption(mDebugText); }
    } catch(
    catch( )
)
 
     {
{ // ignore
        // ignore }
    } }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::processUnbufferedKeyInput(const FrameEvent& evt)
bool BaseApplication::processUnbufferedKeyInput(const FrameEvent& evt)

 {
{ using namespace OIS;
    using namespace OIS; OIS::Keyboard* mInputDevice = mKeyboard; // Nice hack, eh? :)
    OIS::Keyboard* mInputDevice = mKeyboard; // Nice hack, eh? :)
 if (mInputDevice->isKeyDown(KC_A))
    if (mInputDevice->isKeyDown(KC_A))
 
     {
{ // Move camera left
        // Move camera left mTranslateVector.x = -mMoveScale;
        mTranslateVector.x = -mMoveScale; }
    }
 if (mInputDevice->isKeyDown(KC_D))
    if (mInputDevice->isKeyDown(KC_D))
 
     {
{ // Move camera RIGHT
        // Move camera RIGHT mTranslateVector.x = mMoveScale;
        mTranslateVector.x = mMoveScale; }
    }

 /**//* Move camera forward by keypress. */
    /**//* Move camera forward by keypress. */ if (mInputDevice->isKeyDown(KC_UP) || mInputDevice->isKeyDown(KC_W) )
    if (mInputDevice->isKeyDown(KC_UP) || mInputDevice->isKeyDown(KC_W) )
 
     {
{ mTranslateVector.z = -mMoveScale;
        mTranslateVector.z = -mMoveScale; }
    }

 /**//* Move camera backward by keypress. */
    /**//* Move camera backward by keypress. */ if (mInputDevice->isKeyDown(KC_DOWN) || mInputDevice->isKeyDown(KC_S) )
    if (mInputDevice->isKeyDown(KC_DOWN) || mInputDevice->isKeyDown(KC_S) )
 
     {
{ mTranslateVector.z = mMoveScale;
        mTranslateVector.z = mMoveScale; }
    }
 if (mInputDevice->isKeyDown(KC_PGUP))
    if (mInputDevice->isKeyDown(KC_PGUP))
 
     {
{ // Move camera up
        // Move camera up mTranslateVector.y = mMoveScale;
        mTranslateVector.y = mMoveScale; }
    }
 if (mInputDevice->isKeyDown(KC_PGDOWN))
    if (mInputDevice->isKeyDown(KC_PGDOWN))
 
     {
{ // Move camera down
        // Move camera down mTranslateVector.y = -mMoveScale;
        mTranslateVector.y = -mMoveScale; }
    }
 if (mInputDevice->isKeyDown(KC_RIGHT))
    if (mInputDevice->isKeyDown(KC_RIGHT))
 
     {
{ mCamera->yaw(-mRotScale);
        mCamera->yaw(-mRotScale); }
    }
 if (mInputDevice->isKeyDown(KC_LEFT))
    if (mInputDevice->isKeyDown(KC_LEFT))
 
     {
{ mCamera->yaw(mRotScale);
        mCamera->yaw(mRotScale); }
    }
 if( mInputDevice->isKeyDown( KC_ESCAPE) )
    if( mInputDevice->isKeyDown( KC_ESCAPE) )
 
     {
{ return false;
        return false; }
    }
 // see if switching is on, and you want to toggle
    // see if switching is on, and you want to toggle if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_M) && mTimeUntilNextToggle <= 0)
    if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_M) && mTimeUntilNextToggle <= 0)
 
     {
{ switchMouseMode();
        switchMouseMode(); mTimeUntilNextToggle = 1;
        mTimeUntilNextToggle = 1; }
    }
 if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_K) && mTimeUntilNextToggle <= 0)
    if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_K) && mTimeUntilNextToggle <= 0)
 
     {
{ // must be going from immediate keyboard to buffered keyboard
        // must be going from immediate keyboard to buffered keyboard switchKeyMode();
        switchKeyMode(); mTimeUntilNextToggle = 1;
        mTimeUntilNextToggle = 1; }
    } if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
    if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
 
     {
{ mStatsOn = !mStatsOn;
        mStatsOn = !mStatsOn; showDebugOverlay(mStatsOn);
        showDebugOverlay(mStatsOn);
 mTimeUntilNextToggle = 1;
        mTimeUntilNextToggle = 1; }
    } if (mInputDevice->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0)
    if (mInputDevice->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0)
 
     {
{ switch(mFiltering)
        switch(mFiltering)
 
         {
{ case TFO_BILINEAR:
        case TFO_BILINEAR: mFiltering = TFO_TRILINEAR;
            mFiltering = TFO_TRILINEAR; mAniso = 1;
            mAniso = 1; break;
            break; case TFO_TRILINEAR:
        case TFO_TRILINEAR: mFiltering = TFO_ANISOTROPIC;
            mFiltering = TFO_ANISOTROPIC; mAniso = 8;
            mAniso = 8; break;
            break; case TFO_ANISOTROPIC:
        case TFO_ANISOTROPIC: mFiltering = TFO_BILINEAR;
            mFiltering = TFO_BILINEAR; mAniso = 1;
            mAniso = 1; break;
            break; default:
        default: break;
            break; }
        } MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
        MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering); MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
        MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);

 showDebugOverlay(mStatsOn);
        showDebugOverlay(mStatsOn);
 mTimeUntilNextToggle = 1;
        mTimeUntilNextToggle = 1; }
    }
 if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
    if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
 
     {
{ std::ostringstream ss;
        std::ostringstream ss; ss << "screenshot_" << ++mNumScreenShots << ".png";
        ss << "screenshot_" << ++mNumScreenShots << ".png"; mWindow->writeContentsToFile(ss.str());
        mWindow->writeContentsToFile(ss.str()); mTimeUntilNextToggle = 0.5;
        mTimeUntilNextToggle = 0.5; mDebugText = "Saved: " + ss.str();
        mDebugText = "Saved: " + ss.str(); }
    }
 if (mInputDevice->isKeyDown(KC_R) && mTimeUntilNextToggle <=0)
    if (mInputDevice->isKeyDown(KC_R) && mTimeUntilNextToggle <=0)
 
     {
{ mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
        mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
 switch(mSceneDetailIndex)
        switch(mSceneDetailIndex)  {
{ case 0 : mCamera->setPolygonMode(PM_SOLID) ; break ;
                case 0 : mCamera->setPolygonMode(PM_SOLID) ; break ; case 1 : mCamera->setPolygonMode(PM_WIREFRAME) ; break ;
                case 1 : mCamera->setPolygonMode(PM_WIREFRAME) ; break ; case 2 : mCamera->setPolygonMode(PM_POINTS) ; break ;
                case 2 : mCamera->setPolygonMode(PM_POINTS) ; break ; }
        } mTimeUntilNextToggle = 0.5;
        mTimeUntilNextToggle = 0.5; }
    }
 static bool displayCameraDetails = false;
    static bool displayCameraDetails = false; if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
    if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
 
     {
{ displayCameraDetails = !displayCameraDetails;
        displayCameraDetails = !displayCameraDetails; mTimeUntilNextToggle = 0.5;
        mTimeUntilNextToggle = 0.5; if (!displayCameraDetails)
        if (!displayCameraDetails) mDebugText = "";
            mDebugText = ""; }
    } if (displayCameraDetails)
    if (displayCameraDetails)
 
     {
{ // Print camera details
        // Print camera details mDebugText = "P: " + StringConverter::toString(mCamera->getDerivedPosition()) +
        mDebugText = "P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation());
            " " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation()); }
    }
 // Return true to continue rendering
    // Return true to continue rendering return true;
    return true; }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::processUnbufferedMouseInput(const FrameEvent& evt)
bool BaseApplication::processUnbufferedMouseInput(const FrameEvent& evt)

 {
{ 
    
 return true;
    return true; }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::moveCamera()
void BaseApplication::moveCamera()

 {
{
 // Make all the changes to the camera
    // Make all the changes to the camera // Note that YAW direction is around a fixed axis (freelook style) rather than a natural YAW (e.g. airplane)
    // Note that YAW direction is around a fixed axis (freelook style) rather than a natural YAW (e.g. airplane) mCamera->yaw(mRotX);
    mCamera->yaw(mRotX); mCamera->pitch(mRotY);
    mCamera->pitch(mRotY); mCamera->moveRelative(mTranslateVector);
    mCamera->moveRelative(mTranslateVector);

 }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::showDebugOverlay(bool show)
void BaseApplication::showDebugOverlay(bool show)

 {
{ 
     }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::requestShutdown(void)
void BaseApplication::requestShutdown(void)

 {
{ mShutdownRequested = true;
    mShutdownRequested = true; }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::frameStarted(const FrameEvent& evt)
bool BaseApplication::frameStarted(const FrameEvent& evt)

 {
{ if(mWindow->isClosed())
    if(mWindow->isClosed()) return false;
        return false;
 //Need to capture/update each device
    //Need to capture/update each device //mKeyboard->capture();
    //mKeyboard->capture(); //mMouse->capture();
    //mMouse->capture();
 //mUseBufferedInputMouse = mMouse->buffered();
    //mUseBufferedInputMouse = mMouse->buffered(); //mUseBufferedInputKeys = mKeyboard->buffered();
    //mUseBufferedInputKeys = mKeyboard->buffered();

 //     if(mUseBufferedInputMouse)
 //     if(mUseBufferedInputMouse) //     {
 //     { //        CEGUI::MouseCursor::getSingleton().show( );
 //        CEGUI::MouseCursor::getSingleton().show( ); //     }
 //     } //     else
 //     else //     {
 //     { //        CEGUI::MouseCursor::getSingleton().hide( );
 //        CEGUI::MouseCursor::getSingleton().hide( ); //     }
 //     }
 //if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys)
    //if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys) //{
    //{ //    // one of the input modes is immediate, so setup what is needed for immediate mouse/key movement
    //    // one of the input modes is immediate, so setup what is needed for immediate mouse/key movement //    if (mTimeUntilNextToggle >= 0)
    //    if (mTimeUntilNextToggle >= 0) //        mTimeUntilNextToggle -= evt.timeSinceLastFrame;
    //        mTimeUntilNextToggle -= evt.timeSinceLastFrame;
 //    // If this is the first frame, pick a speed
    //    // If this is the first frame, pick a speed //    if (evt.timeSinceLastFrame == 0)
    //    if (evt.timeSinceLastFrame == 0) //    {
    //    { //        mMoveScale = 1;
    //        mMoveScale = 1; //        mRotScale = 0.1;
    //        mRotScale = 0.1; //    }
    //    } //    // Otherwise scale movement units by time passed since last frame
    //    // Otherwise scale movement units by time passed since last frame //    else
    //    else //    {
    //    { //        // Move about 100 units per second,
    //        // Move about 100 units per second, //        mMoveScale = mMoveSpeed * evt.timeSinceLastFrame;
    //        mMoveScale = mMoveSpeed * evt.timeSinceLastFrame; //        // Take about 10 seconds for full rotation
    //        // Take about 10 seconds for full rotation //        mRotScale = mRotateSpeed * evt.timeSinceLastFrame;
    //        mRotScale = mRotateSpeed * evt.timeSinceLastFrame; //    }
    //    } //    mRotX = 0;
    //    mRotX = 0; //    mRotY = 0;
    //    mRotY = 0; //    mTranslateVector = Vector3::ZERO;
    //    mTranslateVector = Vector3::ZERO; //}
    //}
 //if (mUseBufferedInputKeys)
    //if (mUseBufferedInputKeys) //{
    //{ //    // no need to do any processing here, it is handled by event processor and
    //    // no need to do any processing here, it is handled by event processor and //    // you get the results as KeyEvents
    //    // you get the results as KeyEvents //}
    //} //else
    //else //{
    //{ //    if (processUnbufferedKeyInput(evt) == false)
    //    if (processUnbufferedKeyInput(evt) == false) //    {
    //    { //        return false;
    //        return false; //    }
    //    } //}
    //} //if (mUseBufferedInputMouse)
    //if (mUseBufferedInputMouse) //{
    //{ //    // no need to do any processing here, it is handled by event processor and
    //    // no need to do any processing here, it is handled by event processor and //    // you get the results as MouseEvents
    //    // you get the results as MouseEvents //}
    //} //else
    //else //{
    //{ //    if (processUnbufferedMouseInput(evt) == false)
    //    if (processUnbufferedMouseInput(evt) == false) //    {
    //    { //        return false;
    //        return false; //    }
    //    } //}
    //}
 //if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys)
    //if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys) //{
    //{ //    // one of the input modes is immediate, so update the movement vector
    //    // one of the input modes is immediate, so update the movement vector
 //    moveCamera();
    //    moveCamera();
 //}
    //}
 return true;
    return true; }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::frameEnded(const FrameEvent& evt)
bool BaseApplication::frameEnded(const FrameEvent& evt)

 {
{ if (mShutdownRequested)
    if (mShutdownRequested) return false;
        return false; //updateStats();
    //updateStats(); return true;
    return true; }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::switchMouseMode()
void BaseApplication::switchMouseMode()

 {
{ 
     }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::switchKeyMode()
void BaseApplication::switchKeyMode()

 {
{ 
     }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::keyPressed( const OIS::KeyEvent &arg )
bool BaseApplication::keyPressed( const OIS::KeyEvent &arg )

 {
{ 
     return true;
    return true; }
}
 bool BaseApplication::keyReleased( const OIS::KeyEvent &arg )
bool BaseApplication::keyReleased( const OIS::KeyEvent &arg )

 {
{ 
     return true;
    return true; }
}
 bool BaseApplication::mouseMoved( const OIS::MouseEvent &arg )
bool BaseApplication::mouseMoved( const OIS::MouseEvent &arg )

 {
{ //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
    //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel ); return true;
    return true; }
}
 bool BaseApplication::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
bool BaseApplication::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )

 {
{ 
     return true;
    return true; }
}
 bool BaseApplication::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
bool BaseApplication::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )

 {
{ 
     return true;
    return true; }
}
 //Adjust mouse clipping area
//Adjust mouse clipping area void BaseApplication::windowResized(RenderWindow* rw)
void BaseApplication::windowResized(RenderWindow* rw)

 {
{ unsigned int width, height, depth;
    unsigned int width, height, depth; int left, top;
    int left, top;

 //const OIS::MouseState &ms = mMouse->getMouseState();
    //const OIS::MouseState &ms = mMouse->getMouseState(); //ms.width = width;
    //ms.width = width; //ms.height = height;
    //ms.height = height; }
}
 //Unattach OIS before window shutdown (very important under Linux)
//Unattach OIS before window shutdown (very important under Linux) void BaseApplication::windowClosed(RenderWindow* rw)
void BaseApplication::windowClosed(RenderWindow* rw)

 {
{ 
     }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- void BaseApplication::setupEventHandlers(void)
void BaseApplication::setupEventHandlers(void)

 {
{ }
} //-------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------- bool BaseApplication::handleQuit(const CEGUI::EventArgs& e)
bool BaseApplication::handleQuit(const CEGUI::EventArgs& e)

 {
{ requestShutdown();
    requestShutdown(); return true;
    return true; }
}
 
                    
                     
                    
                 
                    
                 

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号