mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 15:35:23 +00:00
More fixes for scaled particle systems
This commit is contained in:
parent
c4738b11b1
commit
74c56556cc
@ -974,7 +974,7 @@ namespace NifOsg
|
||||
}
|
||||
else if (affectors->recType == Nif::RC_NiParticleRotation)
|
||||
{
|
||||
// unused?
|
||||
// unused
|
||||
}
|
||||
else
|
||||
std::cerr << "Unhandled particle modifier " << affectors->recName << std::endl;
|
||||
@ -1064,8 +1064,6 @@ namespace NifOsg
|
||||
{
|
||||
osg::ref_ptr<ParticleSystem> partsys (new ParticleSystem);
|
||||
partsys->setSortMode(osgParticle::ParticleSystem::SORT_BACK_TO_FRONT);
|
||||
// Scaling the particle node should also scale particles, even when the worldspace flag is enabled
|
||||
partsys->setParticleScaleReferenceFrame(osgParticle::ParticleSystem::LOCAL_COORDINATES);
|
||||
|
||||
const Nif::NiParticleSystemController* partctrl = NULL;
|
||||
for (Nif::ControllerPtr ctrl = nifNode->controller; !ctrl.empty(); ctrl = ctrl->next)
|
||||
|
@ -50,8 +50,8 @@ void InverseWorldMatrix::operator()(osg::Node *node, osg::NodeVisitor *nv)
|
||||
osg::MatrixTransform* trans = dynamic_cast<osg::MatrixTransform*>(node);
|
||||
|
||||
osg::Matrix mat = osg::computeLocalToWorld( path );
|
||||
mat = osg::Matrix::inverse(mat);
|
||||
mat.orthoNormalize(mat); // don't undo the scale
|
||||
mat = osg::Matrix::inverse(mat);
|
||||
trans->setMatrix(mat);
|
||||
}
|
||||
traverse(node,nv);
|
||||
@ -239,6 +239,7 @@ void Emitter::setCounter(osgParticle::Counter *counter)
|
||||
void Emitter::emitParticles(double dt)
|
||||
{
|
||||
osg::Matrix worldToPs;
|
||||
// maybe this could be optimized by halting at the lowest common ancestor of the particle and emitter nodes
|
||||
osg::MatrixList worldMats = getParticleSystem()->getWorldMatrices();
|
||||
if (!worldMats.empty())
|
||||
{
|
||||
@ -246,14 +247,9 @@ void Emitter::emitParticles(double dt)
|
||||
worldToPs = osg::Matrix::inverse(psToWorld);
|
||||
}
|
||||
|
||||
worldToPs.orthoNormalize(worldToPs);
|
||||
|
||||
const osg::Matrix& ltw = getLocalToWorldMatrix();
|
||||
const osg::Matrix emitterToPs = ltw * worldToPs;
|
||||
osg::Matrix emitterToPs = ltw * worldToPs;
|
||||
|
||||
int n = mCounter->numParticlesToCreate(dt);
|
||||
|
||||
osg::Matrix transform;
|
||||
if (!mTargets.empty())
|
||||
{
|
||||
int randomRecIndex = mTargets[(std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * mTargets.size()];
|
||||
@ -270,9 +266,13 @@ void Emitter::emitParticles(double dt)
|
||||
|
||||
osg::NodePath path = visitor.mFoundPath;
|
||||
path.erase(path.begin());
|
||||
transform = osg::computeLocalToWorld(path);
|
||||
emitterToPs = osg::computeLocalToWorld(path) * emitterToPs;
|
||||
}
|
||||
|
||||
emitterToPs.orthoNormalize(emitterToPs);
|
||||
|
||||
int n = mCounter->numParticlesToCreate(dt);
|
||||
|
||||
for (int i=0; i<n; ++i)
|
||||
{
|
||||
osgParticle::Particle* P = getParticleSystem()->createParticle(0);
|
||||
@ -282,8 +282,6 @@ void Emitter::emitParticles(double dt)
|
||||
|
||||
mShooter->shoot(P);
|
||||
|
||||
P->transformPositionVelocity(transform);
|
||||
|
||||
P->transformPositionVelocity(emitterToPs);
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ namespace
|
||||
void transformInitialParticles(osgParticle::ParticleSystem* partsys, osg::Node* node)
|
||||
{
|
||||
osg::Matrix worldMat = node->getWorldMatrices()[0];
|
||||
worldMat.orthoNormalize(worldMat); // scale is already applied on the particle node
|
||||
for (int i=0; i<partsys->numParticles(); ++i)
|
||||
{
|
||||
partsys->getParticle(i)->transformPositionVelocity(worldMat);
|
||||
|
Loading…
x
Reference in New Issue
Block a user