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

             

             

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

             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     /// 加載引擎物理對象碰撞回調(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é)組對象. 
            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 

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

            1 core::PhysicsEngine<dWorldID,dSpaceID,dJointGroupID,dGeomID> engine;
            或者可以這樣
            1 core::PhysicsEngine<> engine;
            再給出一個簡單的物理對象數(shù)據(jù)結(jié)構(gòu)
             1 ////////////////////////////////////////////////////////////
             2 /// 定義引擎物理對象數(shù)據(jù)結(jié)構(gòu)(一個對象由N個幾何體構(gòu)成)
             3 ////////////////////////////////////////////////////////////
             4 /*template<class Object,class Geom,int N>
             5 struct PhysicsObject
             6 
             7     Object object;
             8     //! 有必要設(shè)計一個定長數(shù)組了.
             9     Geom   geom[N];    
            10 };*/ 
            一個物理對象由N個簡單幾何體構(gòu)成
            這個是簡單到了極點只是不太符合要求
            下一步該考慮設(shè)計物理對象類了
            對象可以旋轉(zhuǎn),平移,設(shè)置質(zhì)量,加掛幾何體.......
            最后再上幾個ode函數(shù)加深一點認(rèn)識吧:
             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è)置幾何體相對于其物體的局部旋轉(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è)置幾何對象的函數(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 閱讀(1548) 評論(3)  編輯 收藏 引用
            Comments
            • # re: 綁定ode物理引擎于蓋莫游戲引擎
              陳梓瀚(vczh)
              Posted @ 2010-02-28 17:14
              一般來說,要求用戶提供一個模型的同時,要提供一個配套的物理模型(可以不只一個多面體,譬如說人,是有關(guān)節(jié)的),然后給接口讓他們有機(jī)會直接控制速度、位置和力就好了。沒設(shè)置的就讓物理引擎去算。

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

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


             
            久久综合久久久| 久久久久黑人强伦姧人妻| 伊人久久无码精品中文字幕| 久久亚洲中文字幕精品一区四| 久久AⅤ人妻少妇嫩草影院| 欧美久久亚洲精品| 久久综合香蕉国产蜜臀AV| 精品久久久久久久久中文字幕| 亚洲一区二区三区日本久久九| 久久91综合国产91久久精品| 国产精品无码久久综合网| 久久久这里有精品中文字幕| 久久青青草原精品国产| 国产精品久久久久久福利69堂| 日日狠狠久久偷偷色综合免费| 久久人人爽人人爽人人AV| 久久噜噜电影你懂的| 久久人人妻人人爽人人爽| 国产成人精品久久一区二区三区av | 无码专区久久综合久中文字幕| 亚洲日韩中文无码久久| 精品国产乱码久久久久软件| 国产精品综合久久第一页| 欧美va久久久噜噜噜久久| 久久91精品国产91久| 亚洲七七久久精品中文国产| 亚洲国产精品综合久久网络 | 伊人久久综合精品无码AV专区| 国内精品久久久久国产盗摄| 久久影院亚洲一区| 色8激情欧美成人久久综合电| 国产免费久久精品99re丫y| 色欲久久久天天天综合网 | 国产成人无码精品久久久性色| 亚洲中文精品久久久久久不卡| 久久国产亚洲精品无码| 狠狠狠色丁香婷婷综合久久五月 | 久久久久久久综合日本亚洲| 精品久久久久国产免费| 久久妇女高潮几次MBA| 伊人久久免费视频|