• <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>

            Code Knight

            Programming is so cool
            隨筆 - 52, 文章 - 0, 評論 - 14, 引用 - 0
            數據加載中……

            OGRE學習之地形跟蹤

                      hey,guys,又上來貼代碼啦。
                      繼續OGRE的學習。廢話少說看代碼。
              1 #include <CEGUI/CEGUISystem.h>
              2 #include <CEGUI/CEGUISchemeManager.h>
              3 #include <OgreCEGUIRenderer.h>
              4 
              5 #include "ExampleApplication.h"
              6 
              7 class MouseQueryListener : public ExampleFrameListener, public OIS::MouseListener
              8 {
              9 public:
             10 
             11     MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer)
             12         : ExampleFrameListener(win, cam, falsetrue), mGUIRenderer(renderer)
             13     {
             14         mCount = 0;
             15         mCurrentObject = NULL;
             16         mLMouseDown = false;
             17         mRMouseDown = false;
             18         mSceneMgr = sceneManager;
             19 
             20         // Reduce move speed
             21         mMoveSpeed = 50;
             22         mRotateSpeed /= 500;
             23 
             24         // Register this so that we get mouse events.
             25         mMouse->setEventCallback(this);
             26 
             27         // Create RaySceneQuery
             28         mRaySceneQuery = mSceneMgr->createRayQuery(Ray());
             29 
             30     } // MouseQueryListener
             31 
             32     ~MouseQueryListener()
             33     {
             34         // We created the query, and we are also responsible for deleting it.
             35         mSceneMgr->destroyQuery(mRaySceneQuery);
             36 
             37     }
             38 
             39     bool frameStarted(const FrameEvent &evt)
             40     {
             41         // Process the base frame listener code.  Since we are going to be
             42         // manipulating the translate vector, we need this to happen first.
             43         if (!ExampleFrameListener::frameStarted(evt))
             44             return false;
             45 
             46         // 我們的目標及時找到攝像機的當前位置,并沿著它向地面發射一條射線。這被稱為射線場景查詢,它會告訴我們我們下面的地面的高度。
             47         // Setup the scene query
             48         Vector3 camPos = mCamera->getPosition();
             49         Ray cameraRay(Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y);
             50         mRaySceneQuery->setRay(cameraRay);
             51 
             52         // 現在我們需要執行查詢,得到結果。查詢結果是std::iterator類型的。 
             53         // Perform the scene query
             54         RaySceneQueryResult &result = mRaySceneQuery->execute();
             55         RaySceneQueryResult::iterator itr = result.begin();
             56 
             57         // Get the results, set the camera height
             58         if (itr != result.end() && itr->worldFragment)
             59         {
             60             Real terrainHeight = itr->worldFragment->singleIntersection.y;
             61             if ((terrainHeight + 10.0f> camPos.y)
             62                 mCamera->setPosition( camPos.x, terrainHeight + 10.0f, camPos.z );
             63         }
             64 
             65         return true;
             66 
             67     }
             68 
             69     /* MouseListener callbacks. */
             70     bool mouseMoved(const OIS::MouseEvent &arg)
             71     {
             72         // Update CEGUI with the mouse motion
             73         CEGUI::System::getSingleton().injectMouseMove(arg.state.X.rel, arg.state.Y.rel);
             74 
             75         return true;
             76     }
             77 
             78     bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
             79     {
             80         // Left mouse button down
             81         if (id == OIS::MB_Left)
             82         {
             83             // Setup the ray scene query, use CEGUI's mouse position
             84             CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();
             85             Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x/float(arg.state.width), mousePos.d_y/float(arg.state.height));
             86             mRaySceneQuery->setRay(mouseRay);
             87 
             88             // 我們不想讓機器人懸在空中的哈
             89             // Execute query
             90             RaySceneQueryResult &result = mRaySceneQuery->execute();
             91             RaySceneQueryResult::iterator itr = result.begin( );
             92 
             93             // Get results, create a node/entity on the position
             94             if (itr != result.end() && itr->worldFragment)
             95             {
             96                 char name[16];
             97                 sprintf( name, "Robot%d", mCount++ );
             98                 Entity *ent = mSceneMgr->createEntity(name, "robot.mesh");
             99                 mCurrentObject = mSceneMgr->getRootSceneNode()->createChildSceneNode(String(name) + "Node", itr->worldFragment->singleIntersection);
            100                 mCurrentObject->attachObject(ent);
            101                 mCurrentObject->setScale(0.1f0.1f0.1f);
            102             } // if
            103 
            104             mLMouseDown = true;
            105         } // if
            106 
            107         // Right mouse button down
            108         else if (id == OIS::MB_Right)
            109         {
            110             CEGUI::MouseCursor::getSingleton().hide();
            111             mRMouseDown = true;
            112         } // else if
            113 
            114 
            115         // If we are dragging the left mouse button.
            116         if (mLMouseDown)
            117         {
            118         } // if
            119 
            120         // If we are dragging the right mouse button.
            121         else if (mRMouseDown)
            122         {
            123             mCamera->yaw(Degree(-arg.state.X.rel * mRotateSpeed));
            124             mCamera->pitch(Degree(-arg.state.Y.rel * mRotateSpeed));
            125         } // else if
            126 
            127         
            128 
            129         return true;
            130     }
            131 
            132     bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
            133     {
            134         // Left mouse button up
            135         if (id == OIS::MB_Left)
            136         {
            137             mLMouseDown = false;
            138         } // if
            139 
            140         // Right mouse button up
            141         else if (id == OIS::MB_Right)
            142         {
            143             CEGUI::MouseCursor::getSingleton().show();
            144             mRMouseDown = false;
            145         } // else if
            146 
            147         return true;
            148     }
            149 
            150 
            151 protected:
            152     RaySceneQuery *mRaySceneQuery;     // The ray scene query pointer
            153     bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
            154     int mCount;                        // The number of robots on the screen
            155     SceneManager *mSceneMgr;           // A pointer to the scene manager
            156     SceneNode *mCurrentObject;         // The newly created object
            157     CEGUI::Renderer *mGUIRenderer;     // CEGUI renderer
            158 };
            159 
            160 class MouseQueryApplication : public ExampleApplication
            161 {
            162 protected:
            163     CEGUI::OgreCEGUIRenderer *mGUIRenderer;
            164     CEGUI::System *mGUISystem;         // cegui system
            165 public:
            166     MouseQueryApplication()
            167     {
            168     }
            169 
            170     ~MouseQueryApplication()
            171     {
            172     }
            173 protected:
            174     void chooseSceneManager(void)
            175     {
            176         // Use the terrain scene manager.
            177         mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE);
            178     }
            179 
            180     void createScene(void)
            181     {
            182         // Set ambient light
            183         mSceneMgr->setAmbientLight(ColourValue(0.50.50.5));
            184         mSceneMgr->setSkyDome(true"Examples/CloudySky"58);
            185 
            186         // World geometry
            187         mSceneMgr->setWorldGeometry("terrain.cfg");
            188 
            189         // Set camera look point
            190         mCamera->setPosition(40100580);
            191         mCamera->pitch(Degree(-30));
            192         mCamera->yaw(Degree(-45));
            193 
            194         // CEGUI setup
            195         mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false3000, mSceneMgr);
            196         mGUISystem = new CEGUI::System(mGUIRenderer);
            197 
            198         // Mouse
            199         CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLookSkin.scheme");
            200         CEGUI::MouseCursor::getSingleton().setImage("TaharezLook""MouseArrow");
            201 
            202     }
            203 
            204     void createFrameListener(void)
            205     {
            206         mFrameListener = new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer);
            207         mFrameListener->showDebugOverlay(true);
            208         mRoot->addFrameListener(mFrameListener);
            209     }
            210 };
            211 
            212 
            213 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            214 #define WIN32_LEAN_AND_MEAN
            215 #include "windows.h"
            216 
            217 INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
            218 #else
            219 int main(int argc, char **argv)
            220 #endif
            221 {
            222     // Create application object
            223     MouseQueryApplication app;
            224 
            225     try {
            226         app.go();
            227     } catch(Exception& e) {
            228 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            229         MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
            230 #else
            231         fprintf(stderr, "An exception has occurred: %s\n",
            232             e.getFullDescription().c_str());
            233 #endif
            234     }
            235 
            236     return 0;
            237 }
            238 

            還是有鍵盤輸入的問題,不知道為什么這次使用非緩沖輸入點擊右鍵旋轉攝像機只響應一次?有高手幫忙解答一下!
            12.18 問題已解決.it's an easy question

            posted on 2009-12-16 21:15 Code Knight 閱讀(955) 評論(0)  編輯 收藏 引用 所屬分類: OGRE

            亚洲伊人久久大香线蕉苏妲己| 久久青青草原精品国产软件| 国产69精品久久久久9999| 国产精品一区二区久久国产| 草草久久久无码国产专区| 国产精品99久久久久久猫咪| 亚洲国产精品综合久久一线| 亚洲香蕉网久久综合影视| 久久99国产精品久久99| 国内精品久久久久影院老司| 精品久久久无码人妻中文字幕豆芽| 久久精品国产亚洲av高清漫画 | 久久精品无码一区二区三区免费 | 国产99久久久久久免费看| 精品久久久无码中文字幕天天| 久久99这里只有精品国产| 精品免费久久久久久久| 精品久久久一二三区| 99久久综合国产精品二区| 欧美亚洲国产精品久久| 91久久国产视频| 国产午夜福利精品久久2021| 香蕉99久久国产综合精品宅男自 | 久久国产乱子伦精品免费午夜| 久久久久99这里有精品10 | 久久99九九国产免费看小说| 久久99精品国产一区二区三区| 中文字幕人妻色偷偷久久| 久久se这里只有精品| 国产精品久久国产精品99盘| 亚洲精品高清国产一线久久| 无码精品久久一区二区三区| 久久精品国产精品亚洲人人| 2021国产成人精品久久| 久久精品欧美日韩精品| 久久丫精品国产亚洲av不卡 | 97久久超碰国产精品2021| 国产精品久久久久久久久久影院| 亚洲精品国产综合久久一线| 久久久久成人精品无码 | 久久精品国产半推半就|