Doc of API "Immediate mode"

Where can I find the explanation or documentation of API “immediate mode”?

If the docs still not available, Can you please explain me in short how it works and where are located these functions into the engine?

Thanks in advance!!

The best place to start is with the doxygen and with SnippetImmediatMode in the snippets, which is supposed to serve as a form of API documentation. It makes use of most of the features of immediate mode.

We’ll be improving documentation for this feature and refining the API based on feedback. Its quite low level so its more or less a thin wrapper around the low level physx contact gen and rigid body solver.

If you have specific queries about it, I’ll try my best to answer here.

Best of luck


Thanks for your response, I have a box. I need simulate physics over the network for this box.

So I need to create a function that accept the box and a custom delta time to control the simulation of this object.

To do this how can I use immediate Mode?

Thanks again for the support, currently I’m checking the snippets as you suggested.

I’m studying immediate API using snippets. more or less I understand how it works.

What I’ve noticed is that the only actor that participates to simulation is PxRigidDynamic. (The others are used only for the collisions)

Each tick I execute the simulate function that perform the simulation for all actors.

How can I exclude a particular actor (PxRigidDynamic) from simulation process? So I can execute the ImmediateMode function that I’ve created, only on this actor to simulate its movement.

Take a look at the snippet. It simulates a stack of boxes and some spheres connected via joints that are thrown at the stack. It shows you how to simulate collisions and joints. It also has defines to enable/disable contact persistency and cached friction patches, which can be used to improve performance and behavioural quality respectively. It sounds like it’s probably a bit more complex than you might need but it’s a relatively compact bit of code. The snippet uses PhysX rigid body types to extract data from but you can get the rigid body data from any format you like, or even internally store the immediate mode structures.

The API for contact gen is just a single functions so it’s quite straightforward to use. The rigid body solver is split into multiple functions that you have to call in a strict order to initialize states, construct constraints, batch them, solve constraints and finally integrate your rigid bodies. You should be able to more-or-less copy the snippet into your function to simulate your set of bodies and just extract the body information from whatever data formats you’re using.

However, you may find it difficult to get identical results with simulations over a network. PhysX is deterministic, as is immediate mode. However, for it to produce deterministic results run after run, you need to provide the exact same inputs. Any variations like time-steps, which frame forces are applied or an object moves, the order in which objects are defined etc. will cause divergence. Even imperceptible epsilon differences in the impulses applied by the solver in frame I can cause the simulation to eventually diverge noticeably because these differences compound over time. This is something you should be aware of if, for example, you are simulating the body on the client(s) and server and expecting them all to produce identical results. It’s possible to achieve but it can be challenging.

You may get some interesting ideas about potential approaches for networked physics here, if you haven’t read this yet:

Little explanation about snippet edit
I edited the function (instanmode written into the snippet) that now accept only one ball actor that I create when I press the space.

The function stepPhysicsImmediateModeOneActor is not executed directly but is wrapped by the function stepPhysicsBall that allow me to toggle kinematic and dynamic mode of RigidBodygidBody

The function stepPhysicsBall is colled by renderCallback that is:

Little explanation about what code does
As you can see I’m running costantly the simulation physics on all scene except for the ball that is created when i press [space button] (ballInstantMode)

So the function stepPhysicsBall will run for 0.5sec each 3.0 sec and this function simulates the physics only for the ball (ballInstantMode).

It’s working, but has some problem. The ball is fired with high speed with not defined direction, even if I don’t add any force and any velocity.

So what is going here is that the base idea is working but not the implementation.

Personal speculation
What i’m thinking is that is not possible execute the ImmediateMode function for only one or few actors but when the simulation occurs all world must be involved.

This speculation was born for the fact that when I create the ball as dynamic (instead of kinematic) and I run the simulation for all world the simulation is perfect.

Personal conclusion

Please correct me if I’m wronging, I think what I’m trying to do with Physx is not possible. Thanks you In advance!!

If there’s an unexpected velocity, it gets set when you extract the velocity from the PxRigidDynamic using dyn->getLinearVelocity() and apply it to the immediate mode body. If it’s not what’s expected, you’d need debug to figure out where the unexpected value is coming from.

You can think of immediate mode as your own way of dictating which bodies get simulated at any given time, which shapes collide against each other etc. You have complete control.

If you want to simulate just 1 body by itself, you can. Just run through the immediate mode pipeline with just that body. If you’re doing this, you can probably skip a lot of logic because you don’t need contact gen (or maybe only need it against the static environment). If you know you don’t have joints - skip the code that sets them up etc.

If you want body X to collide with body Y, then you need to do contact generation between them, create the contact constraints that represent that collision and then run the solver with both bodies so that it can solve for those constraints and update the bodies’ respective velocities.

If you want to simulate just body X and have it interact with everything else, which you simulate the motion of the other bodies in a separate immediate mode instance, that’s not possible unless those interactions are 1-way (body X bounces off everything else like they’re static/kinematic). If that’s what you need, then you can do it. If you want 2-way interactions, you need to simulate all bodies together.

You can think of each run of immediate mode as being something similar to just creating a PxScene and pushing the subset of your actors that you want to simulate into that scene. However, you have more direct control over what’s being done because you’re calling the low-level contact gen and solve functions.

It also has much less overhead compared to running lots of scenes, which makes it suitable for use-cases like secondary physics animation on characters with an embedded solver in the game’s animation system.

Ok perfect, Now I’ve understood how it works. Thanks