+
+ if (particleFrame.valid()) {
+ MatrixList mlist = node->getWorldMatrices();
+ if (!mlist.empty()) {
+ const Matrix& particleMat = particleFrame->getMatrix();
+ Vec3d emitOrigin(mlist[0](3, 0), mlist[0](3, 1), mlist[0](3, 2));
+ Vec3d displace
+ = emitOrigin - Vec3d(particleMat(3, 0), particleMat(3, 1),
+ particleMat(3, 2));
+ if (displace * displace > 10000.0 * 10000.0) {
+ // Make new frame for particle system, coincident with
+ // the emitter frame, but oriented with local Z.
+ SGGeod geod = SGGeod::fromCart(toSG(emitOrigin));
+ Matrix newParticleMat = makeZUpFrame(geod);
+ Matrix changeParticleFrame
+ = particleMat * Matrix::inverse(newParticleMat);
+ particleFrame->setMatrix(newParticleMat);
+ transformParticles(particleSys.get(), changeParticleFrame);
+ }
+ }