MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / simulate

Method simulate

physx/snippets/snippetnestedscene/NestedScene.h:116–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114 }
115
116 void simulate(PxScene * , PxF32 timeStep)
117 {
118 //1) mirror reference actor accelerations into scene
119
120 if (!mContainingActor->isSleeping())
121 {
122 PxVec3 lvel = mContainingActor->getLinearVelocity();
123 PxVec3 avel = mContainingActor->getAngularVelocity();
124
125 //note that this is actually -acc.
126 PxVec3 lacc = lastLVel - lvel;
127 //PxVec3 aacc = lastAVel - avel;
128
129 lastLVel = lvel;
130 lastAVel = avel;
131
132
133 //special sauce:
134 //filter out vertical movement due to suspension travel, otherwise the ride is too bumpy
135 lacc.y = 0.0f;
136 //decrease the rest of the acceleration by a bit
137 lacc *= 0.7f;
138
139
140 if (lacc.magnitudeSquared() > 0.01f) //let things sleep if the accel is too small
141 {
142 PxU32 nbActors = mScene->getNbActors(PxActorTypeFlag::eRIGID_DYNAMIC);
143 if(nbActors)
144 {
145 std::vector<PxActor*> actors(nbActors);
146 mScene->getActors(PxActorTypeFlag::eRIGID_DYNAMIC, &actors[0], nbActors);
147
148 for(PxU32 i=0;i<nbActors;i++)
149 {
150 actors[i]->is<PxRigidBody>()->addForce(lacc, PxForceMode::eVELOCITY_CHANGE);
151 }
152 }
153 }
154
155
156
157 }
158 else
159 {
160 lastLVel = PxVec3(PxZero);
161 lastAVel = PxVec3(PxZero);
162 }
163
164 //2) simulate scene
165 mScene->simulate(timeStep);
166 mScene->fetchResults(true);
167
168 //move actors that have dropped off the truck out into the main scene
169
170 for(PxU32 i=0;i<removalQueue.size();i++)
171 {
172 mScene->removeActor(*removalQueue[i]);
173

Callers 15

stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
snippetMainFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45
stepPhysicsFunction · 0.45

Calls 15

fetchResultsMethod · 0.80
PxVec3Class · 0.50
isSleepingMethod · 0.45
getLinearVelocityMethod · 0.45
getAngularVelocityMethod · 0.45
magnitudeSquaredMethod · 0.45
getNbActorsMethod · 0.45
getActorsMethod · 0.45
addForceMethod · 0.45
sizeMethod · 0.45
removeActorMethod · 0.45
getGlobalPoseMethod · 0.45

Tested by

no test coverage detected