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:

層級關係:

 

Class Extends Functionality
PxBase N/A Reflection/querying object types.
PxActor PxBase Actor name, actor flags, dominance, clients, aggregates, query world bounds.
PxRigidActor PxActor Shapes and transforms.
PxRigidBody PxRigidActor Mass, inertia, velocities, body flags.
PxRigidStatic PxRigidActor Interface for static body in the scene. This kind of body has implicit infinite mass/inertia.
PxRigidDynamic PxRigidBody Interface for dynamic rigid body in the scene. Introduces support for kinematic targets and object sleeping.
PxArticulationLink PxRigidBody Interface for a dynamic rigid body link in a PxArticulation. Introduces support for querying the articulation and adjacent links.
PxArticulation PxBase Defines 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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章