• <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
            數(shù)據(jù)加載中……

            OGRE學(xué)習(xí)之地形跟蹤

                      hey,guys,又上來貼代碼啦。
                      繼續(xù)OGRE的學(xué)習(xí)。廢話少說看代碼。
              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         // 我們的目標(biāo)及時找到攝像機(jī)的當(dāng)前位置,并沿著它向地面發(fā)射一條射線。這被稱為射線場景查詢,它會告訴我們我們下面的地面的高度。
             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         // 現(xiàn)在我們需要執(zhí)行查詢,得到結(jié)果。查詢結(jié)果是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             // 我們不想讓機(jī)器人懸在空中的哈
             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 

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

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

            久久久99精品成人片中文字幕| 中文精品久久久久人妻| 国产综合精品久久亚洲| 久久亚洲熟女cc98cm| 欧美伊香蕉久久综合类网站| 久久久久久亚洲精品不卡| 久久综合久久自在自线精品自| 97久久精品无码一区二区天美| 久久影院久久香蕉国产线看观看| 99久久免费国产精品特黄| 国产精品丝袜久久久久久不卡| 精品综合久久久久久98| 久久99精品久久久久久秒播| 人妻精品久久久久中文字幕一冢本| 久久精品国产只有精品66 | 91精品国产乱码久久久久久| 久久亚洲国产成人精品无码区| 久久精品www人人爽人人| 无码国内精品久久人妻麻豆按摩| 久久久久免费看成人影片| 午夜精品久久久久9999高清| 久久最近最新中文字幕大全| 日产精品久久久久久久性色| 亚洲国产精品无码久久青草| 国产亚洲精午夜久久久久久| 久久91精品国产91久久麻豆| 日日噜噜夜夜狠狠久久丁香五月| 色综合久久中文字幕综合网| 国产成人久久777777| 久久亚洲精品视频| 国产产无码乱码精品久久鸭| 欧美黑人激情性久久| 久久久久久久亚洲Av无码| 久久久久亚洲精品无码蜜桃| 亚洲乱码精品久久久久..| 一本一本久久aa综合精品| 中文字幕无码免费久久| 久久久久久国产精品无码下载 | 国产精品激情综合久久| 国产精品欧美久久久久无广告| 久久福利青草精品资源站免费|