Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
接着上文继续学习ode物理引擎的函数和数据结构O(∩_∩)O~
15.刚体对象的启用和禁止
刚体对象可以被启用或者禁止
禁止刚体对象则在仿真过程中刚体不参与仿真
如果启用自禁止的话,那么刚体对象会在给定仿真步中idle(如何翻译?)
如果启用自动禁止的话,那么当刚体线速度和角速度同时小于给定阈值之时被禁止
1 void dBodyEnable (dBodyID);
2 void dBodyDisable (dBodyID);
3 int dBodyIsEnabled (dBodyID);
4 void dBodySetAutoDisableFlag (dBodyID, int do_auto_disable);
5 int dBodyGetAutoDisableFlag (dBodyID);
1void dBodySetAutoDisableAngularThreshold (dBodyID, dReal angular_threshold);
2dReal dBodyGetAutoDisableAngularThreshold (dBodyID);
3void dBodySetAutoDisableLinearThreshold (dBodyID, dReal linear_threshold);
4dReal dBodyGetAutoDisableLinearThreshold (dBodyID);
需要确保的是线速度和角速度要小于给定的阈值
16.几个杂项函数
 
1 void dBodySetData (dBodyID, void *data);
2 void *dBodyGetData (dBodyID);
设置,和获取刚体数据
1 int dBodyGetNumJoints (dBodyID b);
获取关联到物体上的关节个数
1 dJointID dBodyGetJoint (dBodyID, int index);
获取给物体上定标号的关节句柄
1 void dBodySetGravityMode (dBodyID b, int mode);
2 int dBodyGetGravityMode (dBodyID b);
设置和获取物体是否受重力影响(默认为是)
1 void dMakeRandomVector (dReal *A, int n, dReal range);

获取n个范围在+-rang中的随机变量

17.矩阵操作
-- 在任何引擎中矩阵都是必不可少的

 1 void dRSetIdentity (dMatrix3 R);
 2 void dRFromAxisAndAngle (dMatrix3 R, dReal ax, dReal ay, dReal az,dReal angle);
 3 void dRFromEulerAngles (dMatrix3 R, dReal phi, dReal theta, dReal psi);
 4 void dRFrom2Axes (dMatrix3 R, dReal ax, dReal ay, dReal az,dReal bx, dReal by, dReal bz);
 5 void dRFromZAxis (dMatrix3 R, dReal ax, dReal ay, dReal az);
 6 void dQSetIdentity (dQuaternion q);
 7 void dQFromAxisAndAngle (dQuaternion q, dReal ax, dReal ay, dReal az,dReal angle);
 8 void dQMultiply0 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
 9 void dQMultiply3 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
10 void dRfromQ (dMatrix3 R, const dQuaternion q);
11 void dQfromR (dQuaternion q, const dMatrix3 R);
12 void dDQfromW (dReal dq[4], const dVector3 w, const dQuaternion q);
这些函数为别是:
设置为单位矩阵,
从给定轴和角度或者矩阵
从欧拉角到矩阵
...

18.ode关节
 1 dJointID dJointCreateBall (dWorldID, dJointGroupID);
 2 dJointID dJointCreateHinge (dWorldID, dJointGroupID);
 3 dJointID dJointCreateSlider (dWorldID, dJointGroupID);
 4 dJointID dJointCreateContact (dWorldID, dJointGroupID,
 5 const dContact *);
 6 dJointID dJointCreateUniversal (dWorldID, dJointGroupID);
 7 dJointID dJointCreateHinge2 (dWorldID, dJointGroupID);
 8 dJointID dJointCreateFixed (dWorldID, dJointGroupID);
 9 dJointID dJointCreateAMotor (dWorldID, dJointGroupID);
10 void dJointDestroy (dJointID);
可以看出ode中定义的关机类型有Ball,Hinge,Slider,...
对关节的销毁动作为断开所有连接的引擎物体,再销毁关节
1 dJointGroupID dJointGroupCreate (int max_size);
2 void dJointGroupDestroy (dJointGroupID);
3 void dJointGroupEmpty (dJointGroupID);
4 
第一个函数中的max_size目前必须是(0)这是为了和以前兼容
销毁关节和清空关节点区别在于销毁会销毁关节组中所有的关节对象和销毁关节组,而清空关节组则只是销毁所有的关节对象
1 void dJointAttach (dJointID, dBodyID body1, dBodyID body2);
使用给定关节连接2个物理对象,如果关节先前是连接的则断开之,如果body1或者body2有1个为0则说明把对象连接对静态环境中去
1 void dJointSetData (dJointID, void *data);
2 void *dJointGetData (dJointID);
设置关节数据没什么好说的
1 int dJointGetType (dJointID);
获取给定关节的关节类型
可能的类型有
dJointTypeBall         A ball-and-socket joint.
dJointTypeHinge      A hinge joint.
dJointTypeSlider      A slider joint.
dJointTypeContact   A contact joint.
dJointTypeUniversal A universal joint.
dJointTypeHinge2    A hinge-2 joint.
dJointTypeFixed      A fixed joint.
dJointTypeAMotor  An angular motor joint.
1 dBodyID dJointGetBody (dJointID, int index);
获取关节给定索引的连接物理对象(以0索引起始)
1 int dAreConnected (dBodyID, dBodyID);
检测2个问题是不是别连接了

19.关节接触;
ode用户指南的原文是:
The contact joint prevents body 1 and body 2 from inter-penetrating at the contact point. It does this by
only allowing the bodies to have an "outgoing "velocity in the direction of the contact normal. Contact joints
typically have a lifetime of one time step. They are created and deleted in response to collision detection.
Contact joints can simulate friction at the contact by applying special forces in the two friction directions
that are perpendicular to the normal.When a contact joint is created, a dContact structure must be supplied. This has the following definition:
接触关节预防碰撞对象的"刺穿"问题,当接触关节产生的时候,其必要的数据元素必须被标记
1 struct dContact {
2 dSurfaceParameters surface;
3 dContactGeom geom;
4 dVector3 fdir1;
5 };
goem是碰撞函数设置的数据结构其中包含了:
碰撞点,碰撞法向矢量和碰撞的2个对象id
而fdir是第一摩擦力方向(其方向和摩擦力方向是相同的),同时也是垂直于接触面法向矢量的.
当且仅当surface.mode = dContactFDir1时期需要被定义
而第二摩擦力方向则是由第一摩擦里方向和接触面方向矢量计算的正交向量
其中的dSurfaceParameters surface是由用户设置的数据结构
其数据结构为:
 1 typedef struct dSurfaceParameters {
 2   /* must always be defined */
 3   int mode;
 4   dReal mu;
 5 
 6   /* only defined if the corresponding flag is set in mode */
 7   dReal mu2;
 8   dReal bounce;
 9   dReal bounce_vel;
10   dReal soft_erp;
11   dReal soft_cfm;
12   dReal motion1,motion2;
13   dReal slip1,slip2;
14 } dSurfaceParameters;
其中的mode必须被标记
mu和mu2取值为(0 to dInfinity.)
如果没有设置mu2,则使用mu为2个摩擦力方向
如果设置了mu2则使用mu为第一个摩擦力方向使用mu2为第二摩擦力方向
如果设置了fdir1则使用fdir作为第一摩擦力方向要不然则自动获取其值
bounce表明其为弹性表面也就是说碰撞对象会相互弹起(取值0-1)0标明完全没有弹性
soft_erp控制的是接触表面的erp,这个值可以设置柔性表面
soft_cfm控制的是柔性表面的最大cfm
其他参数以后再介绍之

20.几何体对象
几何体是检测系统中的基本单元
几何体的销毁和生成
 1 void dGeomDestroy (dGeomID);
 2 void dGeomSetData (dGeomID, void *);
 3 void *dGeomGetData (dGeomID);
 4 void dGeomSetBody (dGeomID, dBodyID);
 5 dBodyID dGeomGetBody (dGeomID);
 6 void dGeomSetPosition (dGeomID, dReal x, dReal y, dReal z);
 7 void dGeomSetRotation (dGeomID, const dMatrix3 R);
 8 void dGeomSetQuaternion (dGeomID, const dQuaternion);
 9 const dReal * dGeomGetPosition (dGeomID);
10 const dReal * dGeomGetRotation (dGeomID);
11 void dGeomGetQuaternion (dGeomID, dQuaternion result);
12 void dGeomGetAABB (dGeomID, dReal aabb[6]);
13 int dGeomIsSpace (dGeomID);
14 dSpaceID dGeomGetSpace (dGeomID);
其中有几何体的销毁,设置几何体数据,关联几何体到缸体
设置,获取几何体旋转,
获取几何体aabb盒子以及检测几何体是否在空间中
1 int dGeomGetClass (dGeomID);
这是获取几何体类型的函数其取值为:
dSphereClass         Sphere
dBoxClass             Box
dCCylinderClass    Capped cylinder
dCylinderClass       Regular flat-ended cylinder
dPlaneClass            Infinite plane (non-placeable)
dGeomTransformClass Geometry transform
dRayClass              Ray
dTriMeshClass       Triangle mesh
dSimpleSpaceClass Simple space
dHashSpaceClass   Hash table based space
int dGeomGetClass (dGeomID);
下面的是几何体的禁止和启用
1 void dGeomEnable (dGeomID);
2 void dGeomDisable (dGeomID);
3 int dGeomIsEnabled (dGeomID);
如果几何体被禁止那么他就不会才与碰撞(尽管它在物理空间中)

该篇就到这里吧,这里给出一个典型的接触面设置:
1 surface.mode = dContactBounce | dContactSoftCFM;
2 surface.mu = dInfinity;
3 surface.mu2 = 0;
4 surface.bounce = 0.01;
5 surface.bounce_vel = 0.1;
6 surface.soft_cfm = 0.01;
可以看出他是使用了接触面弹起
其第一摩擦力方向和第二摩擦力方向是相同的 
posted on 2010-02-26 16:36 ccsdu2009 阅读(866) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理