• <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>
            Cpper
            C/C++高級(jí)工程師 Android高級(jí)軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿

             

             

            接上文介紹了ode的基本函數(shù),接下來應(yīng)該考慮如何綁定Ode和游戲引擎
            簡單的說,單單使用ode不是什么難事情,必須網(wǎng)上使用ode的例子一大把
            問題的關(guān)鍵是如何較好的結(jié)合ode和引擎,記不至于游戲引擎把ode封裝的太深以至于影響其使用的靈活性.另外一方面是,也不能把過多的額外操作拋給用戶操作。
            不過可以先設(shè)計(jì)一個(gè)基本的框架,以后根據(jù)需要和認(rèn)識(shí)的不斷加深再做修改。
            于是先寫下物理引擎的基本框架-很簡單的了:

             1 ////////////////////////////////////////////////////////////
             2 /// 定義物理引擎模板類 
             3 ////////////////////////////////////////////////////////////
             4 template<class World,class Space,class JointGroup,class Geom> 
             5 class PhysicsEngine
             6 {
             7 public:
             8     typedef void(*ContactNearCallback)(void *data, Geom o1, Geom o2);             
             9 public:
            10     ///////////////////////////////////////////////////////
            11     /// 構(gòu)造,析構(gòu)物理引擎類 
            12     //////////////////////////////////////////////////////
            13     PhysicsEngine();
            14     ~PhysicsEngine(); 
            15 public:     
            16     ///////////////////////////////////////////////////////
            17     /// 設(shè)定物理引擎平面(ax+by+cz+d=0) 
            18     //////////////////////////////////////////////////////
            19     void        SetPlane(float a = 0float b = 0float c = 1float d = 0);
            20     
            21     ///////////////////////////////////////////////////////
            22     /// 設(shè)定物理世界重力加速度 
            23     ///////////////////////////////////////////////////////     
            24     void        SetGravity(float x = 0float y = 0float z = -9.81);
            25     
            26     ///////////////////////////////////////////////////////
            27     /// 設(shè)定物理世界仿真更新值 
            28     ///////////////////////////////////////////////////////     
            29     inline void SetStepValue(float step = 0.05fbool quick = true)
            30     {
            31         this->step = step; this->quick = quick;      
            32     }
            33     
            34     ///////////////////////////////////////////////////////
            35     /// 加載引擎物理對(duì)象碰撞回調(diào)函數(shù) 
            36     //////////////////////////////////////////////////////
            37     inline void  SetCollideCallBack(ContactNearCallback callback)
            38     {
            39          this->callback = callback;        
            40     }
            41  
            42     ///////////////////////////////////////////////////////
            43     /// 調(diào)用物理引擎模擬 
            44     ///////////////////////////////////////////////////////     
            45     void       Simulation(); 
            46     
            47     ///////////////////////////////////////////////////////
            48     /// 獲取物理引擎世界,空間和關(guān)節(jié)組對(duì)象. 
            49     ///////////////////////////////////////////////////////    
            50     inline World       GetWorld(){return world;}
            51     inline Space       GetSpace(){return space;}
            52     inline JointGroup  GetContactGroup(){return contactgroup;}
            53 private:
            54     World                  world;
            55     Space                  space;
            56     JointGroup             contactgroup;
            57     ContactNearCallback    callback; 
            58     float                  step;
            59     bool                   quick;                 
            60 };
            61  
            62 #ifdef PHYSICS_EXT_ODE
            63     #include "OdePhysics.inl"
            64 #endif 

             具體對(duì)于ode,我看可以這樣使用之:

            1 core::PhysicsEngine<dWorldID,dSpaceID,dJointGroupID,dGeomID> engine;
            或者可以這樣
            1 core::PhysicsEngine<> engine;
            再給出一個(gè)簡單的物理對(duì)象數(shù)據(jù)結(jié)構(gòu)
             1 ////////////////////////////////////////////////////////////
             2 /// 定義引擎物理對(duì)象數(shù)據(jù)結(jié)構(gòu)(一個(gè)對(duì)象由N個(gè)幾何體構(gòu)成)
             3 ////////////////////////////////////////////////////////////
             4 /*template<class Object,class Geom,int N>
             5 struct PhysicsObject
             6 
             7     Object object;
             8     //! 有必要設(shè)計(jì)一個(gè)定長數(shù)組了.
             9     Geom   geom[N];    
            10 };*/ 
            一個(gè)物理對(duì)象由N個(gè)簡單幾何體構(gòu)成
            這個(gè)是簡單到了極點(diǎn)只是不太符合要求
            下一步該考慮設(shè)計(jì)物理對(duì)象類了
            對(duì)象可以旋轉(zhuǎn),平移,設(shè)置質(zhì)量,加掛幾何體.......
            最后再上幾個(gè)ode函數(shù)加深一點(diǎn)認(rèn)識(shí)吧:
             1 /**
             2  * @brief Set the local offset rotation matrix of a geom from its body.
             3  *
             4  * Sets the geom's rotational offset in local coordinates.
             5  * After this call, the geom will be at a new position determined from the
             6  * body's position and the offset.
             7  * The geom must be attached to a body.
             8  * If the geom did not have an offset, it is automatically created.
             9  *
            10  * @param geom the geom to set.
            11  * @param R the new rotation matrix.
            12  * @ingroup collide
            13  */
            14 ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R);

            設(shè)置幾何體相對(duì)于其物體的局部旋轉(zhuǎn)平移矩陣
             1 /**
             2  * @brief Set the offset position of a geom from its body.
             3  *
             4  * Sets the geom's positional offset to move it to the new world
             5  * coordinates.
             6  * After this call, the geom will be at the world position passed in,
             7  * and the offset will be the difference from the current body position.
             8  * The geom must be attached to a body.
             9  * If the geom did not have an offset, it is automatically created.
            10  *
            11  * @param geom the geom to set.
            12  * @param x the new X coordinate.
            13  * @param y the new Y coordinate.
            14  * @param z the new Z coordinate.
            15  * @ingroup collide
            16  */
            17 ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z);
            生成,設(shè)置幾何對(duì)象的函數(shù):
             1 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
             2 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
             3 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
             4 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
             5 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
             6 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
             7 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
             8 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
             9 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
            10 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
            11 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
            12 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
            13 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
            14 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
            15 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
            16 ODE_API dReal dGeomRayGetLength (dGeomID ray);
            17 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
            18 dReal dx, dReal dy, dReal dz);
            19 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);

            posted on 2010-02-28 17:02 ccsdu2009 閱讀(1558) 評(píng)論(3)  編輯 收藏 引用
            Comments
            • # re: 綁定ode物理引擎于蓋莫游戲引擎
              陳梓瀚(vczh)
              Posted @ 2010-02-28 17:14
              一般來說,要求用戶提供一個(gè)模型的同時(shí),要提供一個(gè)配套的物理模型(可以不只一個(gè)多面體,譬如說人,是有關(guān)節(jié)的),然后給接口讓他們有機(jī)會(huì)直接控制速度、位置和力就好了。沒設(shè)置的就讓物理引擎去算。

              你可以通過開發(fā)一個(gè)3dmax插件來為你的引擎產(chǎn)生這些數(shù)據(jù)  回復(fù)  更多評(píng)論   
            • # re: 綁定ode物理引擎于蓋莫游戲引擎
              99書城
              Posted @ 2010-03-01 18:02
              問我ieriuwer我的房間和我  回復(fù)  更多評(píng)論   
            • # re: 綁定ode物理引擎于蓋莫游戲引擎
              樂蜂網(wǎng)美麗俏佳人
              Posted @ 2010-03-01 22:01
              開始的法規(guī)盡快答復(fù)進(jìn)口  回復(fù)  更多評(píng)論   

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


             
            久久青草国产精品一区| 久久免费99精品国产自在现线| 午夜人妻久久久久久久久| 久久久久久九九99精品| 66精品综合久久久久久久| 日日狠狠久久偷偷色综合96蜜桃| 色妞色综合久久夜夜| 久久ZYZ资源站无码中文动漫| 久久av免费天堂小草播放| 无码人妻久久一区二区三区| 久久97久久97精品免视看秋霞| 伊人久久国产免费观看视频 | 色播久久人人爽人人爽人人片AV | 久久人妻无码中文字幕| 久久中文字幕一区二区| 亚洲精品无码久久久| 久久综合丁香激情久久| 久久精品国产色蜜蜜麻豆| 93精91精品国产综合久久香蕉| 精品国产青草久久久久福利| 大美女久久久久久j久久| 国产精品一久久香蕉产线看| 亚洲一级Av无码毛片久久精品| 亚洲午夜久久久精品影院| 久久精品国产亚洲av日韩| 超级碰碰碰碰97久久久久| 国产亚洲精午夜久久久久久| 国产精品久久久久久| 国产69精品久久久久9999APGF| 综合久久一区二区三区| 久久久久久国产精品美女| 国产精品成人99久久久久| 国内精品久久久久久久97牛牛| 97久久国产综合精品女不卡 | 久久被窝电影亚洲爽爽爽| 久久这里只有精品18| 亚洲乱码中文字幕久久孕妇黑人| 2021国产精品午夜久久| 久久人与动人物a级毛片| 伊人色综合久久天天人守人婷| 久久综合九色综合久99|