| 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 |
no test coverage detected