forked from teamnwah/openmw-tes3coop
More fixes for scaled particle systems
This commit is contained in:
parent
c4738b11b1
commit
74c56556cc
3 changed files with 10 additions and 13 deletions
|
@ -974,7 +974,7 @@ namespace NifOsg
|
||||||
}
|
}
|
||||||
else if (affectors->recType == Nif::RC_NiParticleRotation)
|
else if (affectors->recType == Nif::RC_NiParticleRotation)
|
||||||
{
|
{
|
||||||
// unused?
|
// unused
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cerr << "Unhandled particle modifier " << affectors->recName << std::endl;
|
std::cerr << "Unhandled particle modifier " << affectors->recName << std::endl;
|
||||||
|
@ -1064,8 +1064,6 @@ namespace NifOsg
|
||||||
{
|
{
|
||||||
osg::ref_ptr<ParticleSystem> partsys (new ParticleSystem);
|
osg::ref_ptr<ParticleSystem> partsys (new ParticleSystem);
|
||||||
partsys->setSortMode(osgParticle::ParticleSystem::SORT_BACK_TO_FRONT);
|
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;
|
const Nif::NiParticleSystemController* partctrl = NULL;
|
||||||
for (Nif::ControllerPtr ctrl = nifNode->controller; !ctrl.empty(); ctrl = ctrl->next)
|
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::MatrixTransform* trans = dynamic_cast<osg::MatrixTransform*>(node);
|
||||||
|
|
||||||
osg::Matrix mat = osg::computeLocalToWorld( path );
|
osg::Matrix mat = osg::computeLocalToWorld( path );
|
||||||
mat = osg::Matrix::inverse(mat);
|
|
||||||
mat.orthoNormalize(mat); // don't undo the scale
|
mat.orthoNormalize(mat); // don't undo the scale
|
||||||
|
mat = osg::Matrix::inverse(mat);
|
||||||
trans->setMatrix(mat);
|
trans->setMatrix(mat);
|
||||||
}
|
}
|
||||||
traverse(node,nv);
|
traverse(node,nv);
|
||||||
|
@ -239,6 +239,7 @@ void Emitter::setCounter(osgParticle::Counter *counter)
|
||||||
void Emitter::emitParticles(double dt)
|
void Emitter::emitParticles(double dt)
|
||||||
{
|
{
|
||||||
osg::Matrix worldToPs;
|
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();
|
osg::MatrixList worldMats = getParticleSystem()->getWorldMatrices();
|
||||||
if (!worldMats.empty())
|
if (!worldMats.empty())
|
||||||
{
|
{
|
||||||
|
@ -246,14 +247,9 @@ void Emitter::emitParticles(double dt)
|
||||||
worldToPs = osg::Matrix::inverse(psToWorld);
|
worldToPs = osg::Matrix::inverse(psToWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
worldToPs.orthoNormalize(worldToPs);
|
|
||||||
|
|
||||||
const osg::Matrix& ltw = getLocalToWorldMatrix();
|
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())
|
if (!mTargets.empty())
|
||||||
{
|
{
|
||||||
int randomRecIndex = mTargets[(std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * mTargets.size()];
|
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;
|
osg::NodePath path = visitor.mFoundPath;
|
||||||
path.erase(path.begin());
|
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)
|
for (int i=0; i<n; ++i)
|
||||||
{
|
{
|
||||||
osgParticle::Particle* P = getParticleSystem()->createParticle(0);
|
osgParticle::Particle* P = getParticleSystem()->createParticle(0);
|
||||||
|
@ -282,8 +282,6 @@ void Emitter::emitParticles(double dt)
|
||||||
|
|
||||||
mShooter->shoot(P);
|
mShooter->shoot(P);
|
||||||
|
|
||||||
P->transformPositionVelocity(transform);
|
|
||||||
|
|
||||||
P->transformPositionVelocity(emitterToPs);
|
P->transformPositionVelocity(emitterToPs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ namespace
|
||||||
void transformInitialParticles(osgParticle::ParticleSystem* partsys, osg::Node* node)
|
void transformInitialParticles(osgParticle::ParticleSystem* partsys, osg::Node* node)
|
||||||
{
|
{
|
||||||
osg::Matrix worldMat = node->getWorldMatrices()[0];
|
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)
|
for (int i=0; i<partsys->numParticles(); ++i)
|
||||||
{
|
{
|
||||||
partsys->getParticle(i)->transformPositionVelocity(worldMat);
|
partsys->getParticle(i)->transformPositionVelocity(worldMat);
|
||||||
|
|
Loading…
Reference in a new issue