PhysX学习记录 五 Actor对象

来源:互联网 发布:网络黑市 编辑:程序博客网 时间:2024/06/05 18:01

原文地址:http://blog.csdn.net/heartrude/article/details/7770372


PhysX主要学习内容,当然是了解模拟对象Actor了。


先上框架图。这个是SDK文档上面的。




NxJoint组合NxActor。NxActor包含NxShape用来进行碰撞。NxShape由NxMaterial、Mesh组成。


Actor有Static,dynamic的区别。一个可动,一个不动。在创建时,没有NxBodyDesc就是static。

static actor不能移动,不能修改,必须有shape,不能删除。


1.Shape

Shape表示这Actor占据的实际物理空间,在碰撞检测时起着至关重要的重用。
对于静态Actor的作用就在于造成碰撞,所以必须有Shape。而动态Actor则不一定。

2.Sleep

在一个group的所在actor的所有睡眠门限参数都在门限内时,该组进入sleep状态。
actor在进入和退出睡眠状态时,都可以发送通知。
睡眠通知是回调实现的,而Active通知时查询实现的。

3.特殊的dynamic actor->Kinematic Actor

这种Actor不受外力、重力;也不受joint的动力影响。仅仅通过moveGlobal*()函数进行移动。移动过程中,清空所有挡路的dynamic actor。

4.Actor 参数

为了优化计算性能。Actor所有参数都有对应的线形和旋转参数。

坐标系、坐标、方向

基础知识

这里对于坐标系,主要是3个坐标系:Actor Frame、World Frame、Shape Frame
Actor Frame: Actor坐标系。初始化的时候是和World Frame同向的。随着Actor的旋转移动,则会偏移。在设置Actor的Shape的时候,Shape位置都是在该坐标系中的表示
World Frame:世界坐标系。所有Actor的位置信息都是在该坐标系里面的表示。
Shape Frame:形体坐标系。和形体创建时的设置有关。设置时都是相对于Actor坐标系的。

参数所在坐标系、及其表示

这些东西主要是我在代码编写过程中的总结:
NxActor::getGlobalPose
NxActor::getGlobalPosition
NxActor::getGlobalOrientation
NxActor::getGlobalOrientationQuat
四个函数是用来获取Actor的位置和方向信息的。位置就是一个NxVec3的坐标表示。
这里方向可能描述的不是很恰当。应该称为Actor坐标系相对World坐标系的偏移矩正比较恰当。

NxMat33::rotX
NxMat33::rotY
NxMat33::rotZ
这三个函数可不要理解错了。并不是计算当前偏移量按照X、Y或者Z轴旋转多少角度的结果。二是给出一个给出一个可以进行旋转的转换矩阵。具体的最后结果还是需要通过再次计算获得的。举例说明,下面是Actor绕Y轴旋转的代码:
[cpp] view plaincopy
  1. NxMat33 orientationM;  
  2. NxMat34 pos34 = m_pShooterActor->getGlobalPose(); \\获取当前信息  
  3. orientationM.rotY(NxPi/5);<span style="white-space:pre">                </span>\\获取转换矩阵  
  4. pos34.M = orientationM*pos34.M;<span style="white-space:pre">               </span>\\ 转换矩阵*当前转换矩阵 = 转换后的转换矩阵。 这里顺序不要弄反了  
  5. m_pShooterActor->moveGlobalPose(pos34);  


NxBodyDesc的所有参数说明

质量中心点位置(对于与Mass Frame)
NxMat34 massLocalPose;
Actor的惯性。如果没有设置,则会在CreateActor的时候自动计算
NxVec3 massSpaceInertia;
Actor质量。与density只要设置一个就可以了
NxReal mass;
线速度
NxVec3 linearVelocity;
角速度
NxVec3 angularVelocity;
进入睡眠的剩余次数。NxActor::WakeUp(0)。会设置该参数为0,则立即睡眠。
NxReal wakeUpCounter;
线形阻尼。用来计算一定速度下的阻力情况
NxReal linearDamping;
角速度阻尼。
NxReal angularDamping;
最大角速度。由于角速度过高时,对于非圆形actor,simulator时可能导致错误。所以有系统默认设置了最大角速度。对于车轮等圆形物体可以手动修改该参书
NxReal maxAngularVelocity;
即使全局开启了CCD功能。只有速度超过该门限,才能进入CCD(Continnoius Collision Detection)检测阶段
NxReal CCDMotionThreshold;
[cpp] view plaincopy
  1. /** 
  2. \brief Set if gravity should not be applied on this body 
  3.  
  4. @see NxBodyDesc.flags NxScene.setGravity() 
  5. */  
  6. NX_BF_DISABLE_GRAVITY   = (1<<0),  
  7.   
  8. /**  
  9. \brief Enable/disable freezing for this body/actor.  
  10.  
  11. \note This is an EXPERIMENTAL feature which doesn't always work on in all situations, e.g.  
  12. for actors which have joints connected to them. 
  13.  
  14. To freeze an actor is a way to simulate that it is static. The actor is however still simulated 
  15. as if it was dynamic, it's position is just restored after the simulation has finished. A much 
  16. more stable way to make an actor temporarily static is to raise the NX_BF_KINEMATIC flag. 
  17. */  
  18. NX_BF_FROZEN_POS_X      = (1<<1),  
  19. NX_BF_FROZEN_POS_Y      = (1<<2),  
  20. NX_BF_FROZEN_POS_Z      = (1<<3),  
  21. NX_BF_FROZEN_ROT_X      = (1<<4),  
  22. NX_BF_FROZEN_ROT_Y      = (1<<5),  
  23. NX_BF_FROZEN_ROT_Z      = (1<<6),  
  24. NX_BF_FROZEN_POS        = NX_BF_FROZEN_POS_X|NX_BF_FROZEN_POS_Y|NX_BF_FROZEN_POS_Z,  
  25. NX_BF_FROZEN_ROT        = NX_BF_FROZEN_ROT_X|NX_BF_FROZEN_ROT_Y|NX_BF_FROZEN_ROT_Z,  
  26. NX_BF_FROZEN            = NX_BF_FROZEN_POS|NX_BF_FROZEN_ROT,  
  27.   
  28.   
  29. /** 
  30. \brief Enables kinematic mode for the actor. 
  31.  
  32. Kinematic actors are special dynamic actors that are not  
  33. influenced by forces (such as gravity), and have no momentum. They are considered to have infinite 
  34. mass and can be moved around the world using the moveGlobal*() methods. They will push  
  35. regular dynamic actors out of the way. Kinematics will not collide with static or other kinematic objects. 
  36.  
  37. Kinematic actors are great for moving platforms or characters, where direct motion control is desired. 
  38.  
  39. You can not connect Reduced joints to kinematic actors. Lagrange joints work ok if the platform 
  40. is moving with a relatively low, uniform velocity. 
  41.  
  42. @see NxActor NxActor.raiseActorFlag() 
  43. */  
  44. NX_BF_KINEMATIC         = (1<<7),     //!< Enable kinematic mode for the body.  
  45.   
  46. /** 
  47. \brief Enable debug renderer for this body 
  48.  
  49. @see NxScene.getDebugRenderable() NxDebugRenderable NxParameter 
  50. */  
  51. NX_BF_VISUALIZATION     = (1<<8),  
  52.   
  53. NX_BF_DUMMY_0           = (1<<9), // deprecated flag placeholder  
  54.   
  55. /** 
  56. \brief Filter velocities used keep body awake. The filter reduces rapid oscillations and transient spikes. 
  57. @see NxActor.isSleeping() 
  58. */  
  59. NX_BF_FILTER_SLEEP_VEL  = (1<<10),  
  60.   
  61. /** 
  62. \brief Enables energy-based sleeping algorithm. 
  63. @see NxActor.isSleeping() NxBodyDesc.sleepEnergyThreshold  
  64. */  
  65. NX_BF_ENERGY_SLEEP_TEST = (1<<11),  
NxU32 flags;
小于该速度进行Sleep状态
NxReal sleepLinearVelocity;
小于该速度进行Sleep状态
NxReal sleepAngularVelocity;

/**
\brief Number of solver iterations performed when processing joint/contacts connected to this body.

<b>Range:</b> [1,255]<br>
<b>Default:</b> 4


<b>Platform:</b>
\li PC SW: Yes
\li PPU  : No (Supported in FW, but will only influence per scene maxIterations)
\li PS3  : Yes
\li XB360: Yes


@see NxActor.setSolverIterationCount() NxActor.getSolverIterationCount()
*/
NxU32 solverIterationCount;

睡眠Energy门限
NxReal  sleepEnergyThreshold;
睡眠阻尼门限
NxReal  sleepDamping;
睡眠碰撞Force门限
NxReal  contactReportThreshold;

NxActorDescBase参数说明

Actor Frame中心位置。也就是Actor的全局坐标
NxMat34  globalPose; 

对应NxBodyDesc说明。如果是static Actor则该指针为NULL。也可以反推。
const NxBodyDesc*body;
Actor密度。可以和mass互算。一个Body必须拥有Inertia tensor.惯性的计算使用density*size或者mass。所以这2者必须有1个不为0。否则IsValid函数会返回false
NxReal  density;
 ::NxActorFlag flags
NxU32 flags;
Actor所属的Group。则碰撞检测时可以进行性能优化。会先判定两个Actor所属的Group是否需要碰撞检测。具体参考碰撞部分
NxActorGroup  group;
类似NxActorGroup。但是比group更好用。具体参考碰撞部分
NxDominanceGroup dominanceGroup;
::NxContactPairFlag flags
NxU32 contactReportFlags;

/**
\brief Force Field Material Index, index != 0 has to be created.


<b>Default:</b> 0
*/
NxU16 forceFieldMaterial;
附加用户数据。用来放额外数据。
void* userData; 

debug使用。对象名
const char*  name;


/**
\brief The compartment to place the actor in. Must be either a pointer to an NxCompartment of type NX_SCT_RIGIDBODY, or NULL.
A NULL compartment means creating the actor in the scene proper.


<b>Platform:</b>
\li PC SW: Yes
\li PPU  : Yes
\li PS3  : Yes
\li XB360: Yes


<b>Default:</b> NULL
*/
NxCompartment *compartment;

0 0