1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 19:19:56 +00:00

Merge branch 'uvcontroller' into 'master'

Fix NiUVController UV offset calculations (bug #5995)

Closes #5995

See merge request OpenMW/openmw!795
This commit is contained in:
psi29a 2021-04-30 21:27:01 +00:00
commit 0e50349192
2 changed files with 11 additions and 11 deletions

View file

@ -118,6 +118,7 @@
Bug #5923: Clicking on empty spaces between journal entries might show random topics
Bug #5934: AddItem command doesn't accept negative values
Bug #5975: NIF controllers from sheath meshes are used
Bug #5995: NiUVController doesn't calculate the UV offset properly
Feature #390: 3rd person look "over the shoulder"
Feature #832: OpenMW-CS: Handle deleted references
Feature #1536: Show more information about level on menu

View file

@ -277,19 +277,18 @@ void UVController::apply(osg::StateSet* stateset, osg::NodeVisitor* nv)
if (hasInput())
{
float value = getInputValue(nv);
float uTrans = mUTrans.interpKey(value);
float vTrans = mVTrans.interpKey(value);
float uScale = mUScale.interpKey(value);
float vScale = mVScale.interpKey(value);
osg::Matrix flipMat;
flipMat.preMultTranslate(osg::Vec3f(0,1,0));
flipMat.preMultScale(osg::Vec3f(1,-1,1));
// First scale the UV relative to its center, then apply the offset.
// U offset is flipped regardless of the graphics library,
// while V offset is flipped to account for OpenGL Y axis convention.
osg::Vec3f uvOrigin(0.5f, 0.5f, 0.f);
osg::Vec3f uvScale(mUScale.interpKey(value), mVScale.interpKey(value), 1.f);
osg::Vec3f uvTrans(-mUTrans.interpKey(value), -mVTrans.interpKey(value), 0.f);
osg::Matrixf mat = osg::Matrixf::scale(uScale, vScale, 1);
mat.setTrans(uTrans, vTrans, 0);
mat = flipMat * mat * flipMat;
osg::Matrixf mat = osg::Matrixf::translate(uvOrigin);
mat.preMultScale(uvScale);
mat.preMultTranslate(-uvOrigin);
mat.setTrans(mat.getTrans() + uvTrans);
// setting once is enough because all other texture units share the same TexMat (see setDefaults).
if (!mTextureUnits.empty())