游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4390|回复: 3

各位朋友帮帮忙啊,困扰三天的输入问题了OIS

[复制链接]

1

主题

1

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2010-3-1 16:43:00 | 显示全部楼层 |阅读模式
各位朋友,以下是我照着例子写的程序,别人都可以编译就我编译不了
到了
mMouse->setEventCallback(this);        
mKeyboard->setEventCallback(this);      
这里就出现 “处未处理的异常: 0xC0000005: 读取位置 0xcdcdcdcd 时发生访问冲突”

请问各位朋友该怎么改一下才能够让他正常运行啊?以下是代码:

#include "Ogre.h"
#include "OIS/OIS.h"
#include "CEGUI/CEGUI.h"
#include "OgreCEGUIRenderer.h"
#include "ExampleApplication.h"

using namespace Ogre;

class ExitListener:public ExampleFrameListener,public OIS::KeyListener,public OIS::MouseListener
{
public:
        ExitListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr): ExampleFrameListener(win, cam, true,true)
        {
                mCamNode = cam->getParentSceneNode();        
                mSceneMgr = sceneMgr;
                mRotate = 0.13;        
                mMove = 250;        // continue rendering        
                mContinue = true;        
                mMouse->setEventCallback(this);        
                mKeyboard->setEventCallback(this);        
                mDirection = Vector3::ZERO;

        }
        bool frameStarted(const FrameEvent& evt)
        {         
                        mMouse->capture();            
                        mKeyboard->capture();        
                mCamNode->translate(mDirection * evt.timeSinceLastFrame, Node::TS_LOCAL);        
                return mContinue;
        }

        bool mouseMoved(const OIS::MouseEvent &e)   
        {        
                if (e.state.buttonDown(OIS::MB_Right))        
                {            
                        mCamNode->yaw(Degree(-mRotate * e.state.X.rel), Node::TS_WORLD);            
                        mCamNode->pitch(Degree(-mRotate * e.state.Y.rel), Node::TS_LOCAL);        
                }        
                return true;   
        }

        bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)   
        {      
                /*Light *light = mSceneMgr->getLight("Light1");        
                switch (id)      
                {        
                case OIS::MB_Left:            
                        light->setVisible(! light->isVisible());            
                        break;        
                }       */
                return true;   
        }

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

        bool keyPressed(const OIS::KeyEvent &e)
        {
                switch (e.key)        
                {        
                case OIS::KC_ESCAPE:            
                        mContinue = false;            
                        break;     
                        /*
                case OIS::KC_1:            
                        mCamera->getParentSceneNode()->detachObject(mCamera);            
                        mCamNode = mSceneMgr->getSceneNode("CamNode1");            
                        mCamNode->attachObject(mCamera);            
                        break;        
                case OIS::KC_2:            
                        mCamera->getParentSceneNode()->detachObject(mCamera);            
                        mCamNode = mSceneMgr->getSceneNode("CamNode2");            
                        mCamNode->attachObject(mCamera);            
                        break;        case OIS::KC_UP:        */
                case OIS::KC_W:            
                        mDirection.z -= mMove;            
                        break;        
                case OIS::KC_DOWN:        
                case OIS::KC_S:            
                        mDirection.z += mMove;            
                        break;        
                case OIS::KC_LEFT:        
                case OIS::KC_A:            
                        mDirection.x -= mMove;            
                        break;        
                case OIS::KC_RIGHT:        
                case OIS::KC_D:            
                        mDirection.x += mMove;            
                        break;        
                case OIS::KC_PGDOWN:        
                case OIS::KC_E:            
                        mDirection.y -= mMove;            
                        break;        
                case OIS::KC_PGUP:        
                case OIS::KC_Q:            
                        mDirection.y += mMove;            
                        break;        
                }        
                return true;
        }
        bool keyReleased(const OIS::KeyEvent &e)
        {
                switch (e.key)        
                {        
                case OIS::KC_UP:        
                case OIS::KC_W:            
                        mDirection.z += mMove;            
                        break;        
                case OIS::KC_DOWN:      
                case OIS::KC_S:            
                        mDirection.z -= mMove;            
                        break;        
                case OIS::KC_LEFT:        
                case OIS::KC_A:            
                        mDirection.x += mMove;            
                        break;        
                case OIS::KC_RIGHT:        
                case OIS::KC_D:            
                        mDirection.x -= mMove;            
                        break;        
                case OIS::KC_PGDOWN:        
                case OIS::KC_E:            
                        mDirection.y += mMove;            
                        break;        
                case OIS::KC_PGUP:        
                case OIS::KC_Q:            
                        mDirection.y -= mMove;            
                        break;        
                } // switch        
                return true;
        }
private:
        OIS::Keyboard *mKeyboard;
        OIS::Mouse* mMouse;
        Real mMove;
        Real mRotate;          // The rotate constant   
           // The movement constant   
        SceneManager *mSceneMgr;   // The current SceneManager   
        SceneNode *mCamNode;   // The SceneNode the camera is currently attached to   
        bool mContinue;        // Whether to continue rendering or not   
        Vector3 mDirection;
        ExitListener *mFrameListener;
};

//////////////////////////////////////////////////////////////////////////
class Application
{
public:
        void go()
        {
                createRoot();
                defineResources();
                setupRenderSyetem();
                createRenderWindow();
                initializeResourceGroups();
                setupScene();
                setupInputSystem();
                setupCEGUI();
                createFrameListener();
                startRenderLoop();
        }

        ~Application()
        {
       
        }

private:
        Root *mRoot;
        OIS::Keyboard *mKeyboard;
        OIS::Mouse *mMouse;
        OIS::InputManager *mInputManager;
        CEGUI::OgreCEGUIRenderer *mRenderer;
        CEGUI::System *mSystem;
        ExitListener *mFrameListener;
        RenderWindow *win;
        SceneManager *mgr;
        Camera *cam;

        void createRoot()
        {
                mRoot=new Root();
        }

        void defineResources()
        {
                String secName,typeNmae,archName;
                ConfigFile cf;
                cf.load("resources.cfg");
                ConfigFile::SectionIterator seci=cf.getSectionIterator();
                while (seci.hasMoreElements())
                {
                        String typeName,archName,secName;
                        secName=seci.peekNextKey();
                        ConfigFile::SettingsMultiMap *settings=seci.getNext();
                        ConfigFile::SettingsMultiMap::iterator i;
                        for (i=settings->begin();i!=settings->end();++i)
                        {
                                typeName=i->first;
                                archName=i->second;
                                ResourceGroupManager::getSingleton().addResourceLocation(archName,typeName,secName);
                        }
                }
        }

        void setupRenderSyetem()
        {
                if(!mRoot->restoreConfig()&&!mRoot->showConfigDialog())
                        throw Exception(52,"User canceled the config dialog!","Application::setupRenderSyetem()");
        }

        void createRenderWindow()
        {
                mRoot->initialise(true,"FPS game");
        }

        void initializeResourceGroups()
        {
                TextureManager::getSingleton().setDefaultNumMipmaps(5);
                ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
        }

        void setupScene()
        {
       //创建场景管理器
                mgr=mRoot->createSceneManager(ST_EXTERIOR_CLOSE,"Default SceneManager");

                //设置环境光
                mgr->setAmbientLight(ColourValue(1,1,1));

                //创建摄像机
                cam=mgr->createCamera("Camera");
                cam->setPosition(Vector3(300,50,500));
                cam->setNearClipDistance(5);

                //创建视口
                Viewport *vp=mRoot->getAutoCreatedWindow()->addViewport(cam);

      //-----------------------------------设置机器人------------------------------------------------
                //Entity *ent1=mgr->createEntity("robot","robot.mesh");
                //mgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent1);

       //-----------------------------------设置地面------------------------------------------------
                mgr->setWorldGeometry( "terrain.cfg" );
       //-----------------------------------设置天空------------------------------------------------
                     Plane plane(Vector3::UNIT_Y, 0);
                Plane plan;
                plan.d=100;
                plan.normal=Vector3::NEGATIVE_UNIT_Y;
                mgr->setSkyPlane(true,plan,"Examples/CloudySky",500,20,true,0.5,150,150);


               
        }

        void setupInputSystem()
        {
               
        }

        void setupCEGUI()
        {
                mgr=mRoot->getSceneManager("Default SceneManager");
                win=mRoot->getAutoCreatedWindow();
                mRenderer=new CEGUI::OgreCEGUIRenderer(win,Ogre::RENDER_QUEUE_OVERLAY,false,3000,mgr);
                mSystem=new CEGUI::System(mRenderer);
        }

        void createFrameListener()
        {
                mFrameListener = new ExitListener(win, cam, mgr);        
                mRoot->addFrameListener(mFrameListener);        // Show the frame stats overlay        
                mFrameListener->showDebugOverlay(true);
        }

        void startRenderLoop()
        {
                mRoot->startRendering();
        }
};

6

主题

40

帖子

67

积分

注册会员

Rank: 2

积分
67
发表于 2010-3-1 17:08:00 | 显示全部楼层

Re:各位朋友帮帮忙啊,困扰三天的输入问题了OIS

mKeyboard,mMouse都没创建,怎么用,服了。

1

主题

5

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2010-3-12 00:53:00 | 显示全部楼层

Re: Re:各位朋友帮帮忙啊,困扰三天的输入问题了OIS

songxiaoyu8: Re:各位朋友帮帮忙啊,困扰三天的输入问题了OIS

mKeyboard,mMouse都没创建,怎么用,服了。


不是有创建。。。

9

主题

39

帖子

43

积分

注册会员

Rank: 2

积分
43
发表于 2010-3-29 19:02:00 | 显示全部楼层

Re:各位朋友帮帮忙啊,困扰三天的输入问题了OIS

处未处理的异常: 0xC0000005: 读取位置 0xcdcdcdcd 时发生访问冲突

这种错误一般是调用未初始化的指针造成的,说明你的
mMouse      
mKeyboard
并没有成功创建,好好对着程序检查检查吧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-10 10:27

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表