Nvidia PhysX 学习文档8: Rigid Body Overview

 


official site: https://gameworksdocs.nvidia.com/PhysX/4.1/documentation/physxguide/Manual/RigidBodyOverview.html

红色代表需要弄懂的。


Introduction

This chapter will introduce the fundamentals of simulating rigid body dynamics using the NVIDIA PhysX engine.

Rigid Body Object Model

PhysX uses a hierarchical rigid body object/actor model, which looks like this:

层级关系:

 

ClassExtendsFunctionality
PxBaseN/AReflection/querying object types.
PxActorPxBaseActor name, actor flags, dominance, clients, aggregates, query world bounds.
PxRigidActorPxActorShapes and transforms.
PxRigidBodyPxRigidActorMass, inertia, velocities, body flags.
PxRigidStaticPxRigidActorInterface for static body in the scene. This kind of body has implicit infinite mass/inertia.
PxRigidDynamicPxRigidBodyInterface for dynamic rigid body in the scene. Introduces support for kinematic targets and object sleeping.
PxArticulationLinkPxRigidBodyInterface for a dynamic rigid body link in a PxArticulation. Introduces support for querying the articulation and adjacent links.
PxArticulationPxBaseDefines interface for a PxArticulation. Effectively a contained referencing multiple PxArticualtionLink rigid bodies.

The following diagram shows the relationship between the main types involved in the rigid body pipeline:

../_images/RigidBodyOverview.PNG

不得不说上图总结的很好。当前已经有体会的是: 每个Actor都需要有一个shape。 PxPhysics类创建PxShape,每个PxShape对象包含两个重要的方面: PxMaterial和Geometry.  某些较为复杂的Geometry类必须依赖其他的类,例如PxConvexMeshGeometry必须依赖于PxConvexMesh类。

 

The Simulation Loop

Simulation这部分在前面有过详细的讲解。

Now use the method PxScene::simulate() to advance the world forward in time. Here is simplified code from the samples' fixed stepper class:

mAccumulator = 0.0f;
mStepSize = 1.0f / 60.0f;

virtual bool advance(PxReal dt)
{
    mAccumulator  += dt;
    if(mAccumulator < mStepSize)
        return false;

    mAccumulator -= mStepSize; //???

    mScene->simulate(mStepSize);
    return true;
}

This is called from the sample framework whenever the app is done with processing events and is starting to idle. It accumulates elapsed real time until it is greater than a sixtieth of a second, and then calls simulate(), which moves all objects in the scene forward by that interval. This is probably the simplest of very many different ways to deal with time when stepping the simulation forward.

To allow the simulation to finish and return the results, simply call:

mScene->fetchResults(true);

True indicates that the simulation should block until it is finished, so that on return the results are guaranteed to be available. When fetchResults completes, any simulation event callback functions that you defined will also be called. See the chapter Callback Sequence.

当fetchResults函数完成后,任何你定义的simulatioin event callback函数也会被调用(如果满足触发条件的话)。

It is possible to read and write from the scene during simulation. The samples take advantage of this to perform rendering work in parallel with physics. Until fetchResults() returns, the results of the current simulation step are not available. So running rendering in parallel with simulation renders the actors as they were when simulate() was called. After fetchResults() returns, all these functions will return the new, post-simulate state. See the chapter Threading for more details about reading and writing while the simulation is running.

For the human eye to perceive animated motion as smooth, use at least twenty discrete frames per second, with each frame corresponding to a physics time step. To have smooth, realistic simulation of more complex physical scenes, use at least fifty frames per second.

达到流畅的效果需要至少每秒20帧,对更加负责的常见至少每秒50帧。

Note

If you are making a real-time interactive simulation, you may be tempted to take different sized time steps which correspond to the amount of real time that has elapsed since the last simulation frame. Be very careful if you do this, rather than taking constant-sized time steps: The simulation code is sensitive to both very small and large time steps, and also to too much variation between time steps. In these cases it will likely produce jittery simulation.

仿真引擎对于过小或过大的时间步长都特别敏感! 同时,不要每次给定的时间step是由很大变化的!  否则会卡顿。

See Simulation memory for details of how memory is used in simulation.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

First Snowflakes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值