游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2227|回复: 2

[转载]Joint学习笔记

[复制链接]

14

主题

96

帖子

124

积分

注册会员

Rank: 2

积分
124
QQ
发表于 2007-2-6 09:38:00 | 显示全部楼层 |阅读模式
来源:http://www.blog.edu.cn/user1/4750/archives/2004/10822.shtml

OgreRefAppJoint.h应该是负责游戏世界和ODE物理引擎连接的接口,因为它是被OgreRefAppWorld.h所包含的文件,它本身定义了类“Joint”包含了OgreRefAppPrerequisites.h文件。后者是OGRE与ODE最底层的连接,包含了所有需要的ODE头文件,定义了相等的数据类型。下面来看看这个文件到底有什么内容,做什么工作。

#ifndef __REFAPP_JOINT_H__
#define __REFAPP_JOINT_H__
#i nclude "OgreRefAppPrerequisites.h"

namespace OgreRefApp {

     class _OgreRefAppExport Joint               //DLL导出类
     {
     public:
         enum JointType {
             JT_BALL,
             JT_SLIDER,                                   //滑动
             JT_HINGE,                                     //折叶
             JT_UNIVERSAL,                            //全体的
             JT_HINGE2
         };
         Joint(JointType jtype);
         virtual ~Joint() { if (mOdeJoint) delete mOdeJoint; }

         JointType getType(void);
         virtual void setAnchorPosition(const Vector3& point) = 0;
         virtual const Vector3& getAnchorPosition(void);
         virtual const std::pair<ApplicationObject*, ApplicationObject*>& getAttachments(void);
         virtual void setAxes(const Vector3& primaryAxis, const Vector3& secondaryAxis = Vector3::ZERO) = 0;      //设置轴线

         virtual const std::pair<Vector3, Vector3>& getAxes(void);
     protected:
         void setAttachments(ApplicationObject* obj1, ApplicationObject* obj2);
         JointType mType;           //连接类型消息

         Vector3 mAnchor;          //锚点类型消息

         std::pair<ApplicationObject*, ApplicationObject*> mAttachedObjects;

         std::pair<ApplicationObject*, ApplicationObject*> mAttachedObjects;
         std::pair<Vector3, Vector3> mAxes;
         // ODE object
         dJoint* mOdeJoint;
     };
}
#endif


Joint类定义的就是具体的连接的类型,不过连接到底是指什么和什么的连接还不是很明白,只知道是把ODE的连接映射为OGRE的连接。要想弄明白这些到底是干什么的还必须要继续看World类是什么样的。根据我现在的猜测,应该是处理两个物体接触时的特征的,因为有什么轴、锚点一类的东西,所以Joint翻译成“接触”更恰当一些。
       下面来看一下它的CPP文件,看看这个类是怎么实现的。

00025 #i nclude "OgreRefAppJoint.h"
00026 #i nclude "OgreRefAppApplicationObject.h"
00027 //包含了这个文件意味着将要实现具体物体的接触处理
00028 namespace OgreRefApp {

00031     Joint::Joint(Joint::JointType jtype)
00032         : mType(jtype), mAnchor(Vector3::ZERO), mOdeJoint(NULL)
00033     {
00034         mAxes.first = Vector3::UNIT_X;
00035         mAxes.second = Vector3::UNIT_Z;
00036
00037         // Subclasses must set attachment since mOdeJoint must be created
00038         
00039     }
00040     //-------------------------------------------------------------------------
00041     Joint::JointType Joint::getType(void)
00042     {
00043         return mType;
00044     }
00045     //-------------------------------------------------------------------------
00046     const Vector3& Joint::getAnchorPosition(void)
00047     {
00048         return mAnchor;
00049     }
00050     //-------------------------------------------------------------------------
00051     void Joint::setAttachments(ApplicationObject* obj1, ApplicationObject* obj2)
00052     {
00053         dBodyID b1, b2;
00054         b1 = b2 = 0;
00055         if (obj1)
00056         {
00057             assert(obj1->getOdeBody() && "Cannot attach objects which do not have ODE bodies.");
00058             b1 = obj1->getOdeBody()->id();
00059         }
00060         if (obj2)
00061         {
00062             assert(obj2->getOdeBody() && "Cannot attach objects which do not have ODE bodies.");
00063             b2 = obj2->getOdeBody()->id();
00064         }
00065
00066         mOdeJoint->attach(b1, b2);
00067         mAttachedObjects.first = obj1;
00068         mAttachedObjects.second = obj2;
00069
00070     }
00071     //-------------------------------------------------------------------------
00072     const std::pair<ApplicationObject*, ApplicationObject*>&
00073     Joint::getAttachments(void)
00074     {
00075         return mAttachedObjects;
00076     }
00077     //-------------------------------------------------------------------------
00078     const std::pair<Vector3, Vector3>&
00079     Joint::getAxes(void)
00080     {
00081         return mAxes;
00082     }
00087 }

没什么好说的,基本上就是在构造头文件所定义的方法,所以想深入学习彻底弄懂它就需要进一步学习另一个类了:World.

44

主题

248

帖子

274

积分

中级会员

Rank: 3Rank: 3

积分
274
发表于 2007-2-8 09:37:00 | 显示全部楼层

Re:[转载]Joint学习笔记

ode的碰撞虽然快 可是精度太差了。。。。。。

几个物体叠在一起你会发现 那几个物体 会一直抖个不停

13

主题

90

帖子

96

积分

注册会员

Rank: 2

积分
96
发表于 2007-2-11 22:59:00 | 显示全部楼层

Re: [转载]Joint学习笔记

那是因为参数设置的不太好吧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-26 10:40

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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